/** Request update data received data handler. */
void ResponseListener::onTablesUpdates(IO2GResponse *data)
{
	if (data)
	{
		O2G2Ptr<IO2GResponseReaderFactory> factory = mSession->getResponseReaderFactory();
		if (factory)
		{
			O2G2Ptr<IO2GTablesUpdatesReader> reader = factory->createTablesUpdatesReader(data);
			if (reader)
			{
				for (int i = 0; i < reader->size(); ++i)
				{
					if (reader->getUpdateTable(i) == Orders)
					{
						O2G2Ptr<IO2GOrderRow> order = reader->getOrderRow(i);
						if (reader->getUpdateType(i) == Insert)
						{
							if (mRequestID == order->getRequestID())
							{
								std::cout << "The order has been added. OrderID='" << order->getOrderID() << "', "
									<< "Type='" << order->getType() << "', "
									<< "BuySell='" << order->getBuySell() << "', "
									<< "Rate='" << order->getRate() << "', "
									<< "TimeInForce='" << order->getTimeInForce() << "'"
									<< std::endl;
								SetEvent(mResponseEvent);
							}
						}
					}
				}
			}
		}
	}
}
Beispiel #2
0
void printPrices(IO2GSession *session, IO2GResponse *response)
{
    if (response != 0)
    {
        if (response->getType() == MarketDataSnapshot)
        {
            std::cout << "Request with RequestID='" << response->getRequestID() << "' is completed:" << std::endl;
            O2G2Ptr<IO2GResponseReaderFactory> factory = session->getResponseReaderFactory();
            if (factory)
            {
                O2G2Ptr<IO2GMarketDataSnapshotResponseReader> reader = factory->createMarketDataSnapshotReader(response);
                if (reader)
                {
                    char sTime[20];
                    for (int ii = reader->size() - 1; ii >= 0; ii--)
                    {
                        DATE dt = reader->getDate(ii);
                        formatDate(dt, sTime);
                        if (reader->isBar())
                        {
                            printf("DateTime=%s, BidOpen=%f, BidHigh=%f, BidLow=%f, BidClose=%f, AskOpen=%f, AskHigh=%f, AskLow=%f, AskClose=%f, Volume=%i\n",
                                    sTime, reader->getBidOpen(ii), reader->getBidHigh(ii), reader->getBidLow(ii), reader->getBidClose(ii),
                                    reader->getAskOpen(ii), reader->getAskHigh(ii), reader->getAskLow(ii), reader->getAskClose(ii), reader->getVolume(ii));
                        }
                        else
                        {
                            printf("DateTime=%s, Bid=%f, Ask=%f\n", sTime, reader->getBid(ii), reader->getAsk(ii));
                        }
                    }
                }
            }
        }
    }
}
std::vector<Prices> ForexConnectClient::getPricesFromResponse(IO2GResponse* response)
{
    std::vector<Prices> prices;
    if (!response || response->getType() != MarketDataSnapshot)
    {
	return prices;
    }
    BOOST_LOG_TRIVIAL(debug) << "Request with RequestID='" << response->getRequestID() << "' is completed:";
    O2G2Ptr<IO2GMarketDataSnapshotResponseReader> reader = mpResponseReaderFactory->createMarketDataSnapshotReader(response);
    if (!reader)
    {
	return prices;
    }
    for (int ii = reader->size() - 1; ii >= 0; ii--)
    {
	DATE dt = reader->getDate(ii);
	if (reader->isBar())
	{
	    prices.push_back(Prices(toPtime(dt),
				    reader->getAskOpen(ii),
				    reader->getAskHigh(ii),
				    reader->getAskLow(ii),
				    reader->getAskClose(ii)));
	}
	else
	{
	    prices.push_back(Prices(toPtime(dt),
				    reader->getAsk(ii)));
	}
    }
    return prices;
}
Beispiel #4
0
bool getHistoryPrices(IO2GSession *session, const char *sInstrument, const char *sTimeframe, DATE dtFrom, DATE dtTo, ResponseListener *responseListener)
{
    O2G2Ptr<IO2GRequestFactory> factory = session->getRequestFactory();
    if (!factory)
    {
        std::cout << "Cannot create request factory" << std::endl;
        return false;
    }
    //find timeframe by identifier
    O2G2Ptr<IO2GTimeframeCollection> timeframeCollection = factory->getTimeFrameCollection();
    O2G2Ptr<IO2GTimeframe> timeframe = timeframeCollection->get(sTimeframe);
    if (!timeframe)
    {
        std::cout << "Timeframe '" << sTimeframe << "' is incorrect!" << std::endl;
        return false;
    }
    O2G2Ptr<IO2GRequest> request = factory->createMarketDataSnapshotRequestInstrument(sInstrument, timeframe, timeframe->getQueryDepth());
    DATE dtFirst = dtTo;
     // there is limit for returned candles amount
    do
    {
        factory->fillMarketDataSnapshotRequestTime(request, dtFrom, dtFirst, false);
        responseListener->setRequestID(request->getRequestID());
        session->sendRequest(request);
        if (!responseListener->waitEvents())
        {
            std::cout << "Response waiting timeout expired" << std::endl;
            return false;
        }
        // shift "to" bound to oldest datetime of returned data
        O2G2Ptr<IO2GResponse> response = responseListener->getResponse();
        if (response && response->getType() == MarketDataSnapshot)
        {
            O2G2Ptr<IO2GResponseReaderFactory> readerFactory = session->getResponseReaderFactory();
            if (readerFactory)
            {
                O2G2Ptr<IO2GMarketDataSnapshotResponseReader> reader = readerFactory->createMarketDataSnapshotReader(response);
                if (reader->size() > 0)
                {
                    if (abs(dtFirst - reader->getDate(0)) > 0.0001)
                        dtFirst = reader->getDate(0); // earliest datetime of returned data
                    else
                        break;
                }
                else
                {
                    std::cout << "0 rows received" << std::endl;
                    break;
                }
            }
            printPrices(session, response);
        }
        else
        {
            break;
        }
    } while (dtFirst - dtFrom > 0.0001);
    return true;
}
std::vector<Prices> ForexConnectClient::getHistoricalPrices(const std::string& instrument,
							    const boost::posix_time::ptime& from,
							    const boost::posix_time::ptime& to,
    							    const std::string& timeFrame)
{
    std::vector<Prices> prices;
    O2G2Ptr<IO2GTimeframeCollection> timeframeCollection = mpRequestFactory->getTimeFrameCollection();
    O2G2Ptr<IO2GTimeframe> timeframe = timeframeCollection->get(timeFrame.c_str());
    if (!timeframe)
    {
        BOOST_LOG_TRIVIAL(error) << "Timeframe '" << timeFrame << "' is incorrect!";
        return prices;
    }
    O2G2Ptr<IO2GRequest> request = mpRequestFactory->createMarketDataSnapshotRequestInstrument(instrument.c_str(),
											       timeframe,
											       timeframe->getQueryDepth());
    DATE dtFrom = toOleTime(from);
    DATE dtTo = toOleTime(to);
    DATE dtFirst = dtTo;
    do
    {
        mpRequestFactory->fillMarketDataSnapshotRequestTime(request, dtFrom, dtFirst, false);
        mpResponseListener->setRequestID(request->getRequestID());
        mpSession->sendRequest(request);
        if (!mpResponseListener->waitEvents())
        {
            BOOST_LOG_TRIVIAL(error) << "Response waiting timeout expired";
            return prices;
        }
        // shift "to" bound to oldest datetime of returned data
        O2G2Ptr<IO2GResponse> response = mpResponseListener->getResponse();
        if (response && response->getType() == MarketDataSnapshot)
        {
	    O2G2Ptr<IO2GMarketDataSnapshotResponseReader> reader = mpResponseReaderFactory->createMarketDataSnapshotReader(response);
	    if (reader->size() > 0)
	    {
		if (fabs(dtFirst - reader->getDate(0)) > 0.0001)
		    dtFirst = reader->getDate(0); // earliest datetime of returned data
		else
		    break;
	    }
	    else
	    {
		BOOST_LOG_TRIVIAL(warning) << "0 rows received";
		break;
	    }
	    std::vector<Prices> prc = getPricesFromResponse(response);
	    prices.insert(prices.end(), prc.begin(), prc.end());
	}
	else
	{
	    break;
	}
    } while (dtFirst - dtFrom > 0.0001);
    return prices;
}
Beispiel #6
0
bool getCloseOrdersData(IO2GSession *session, ResponseListener *responseListener, const char *sAccountID, const char *sOfferID, CloseOrderData &closeOrdersData)
{
    O2G2Ptr<IO2GRequestFactory> requestFactory = session->getRequestFactory();
    if (!requestFactory)
    {
        std::cout << "Cannot create request factory" << std::endl;
        return false;
    }
    O2G2Ptr<IO2GRequest> request = requestFactory->createRefreshTableRequestByAccount(Trades, sAccountID);
    if (!request)
    {
        std::cout << requestFactory->getLastError() << std::endl;
        return false;
    }
    responseListener->setRequestID(request->getRequestID());
    session->sendRequest(request);
    if (!responseListener->waitEvents())
    {
        std::cout << "Response waiting timeout expired" << std::endl;
        return false;
    }

    O2G2Ptr<IO2GResponse> response = responseListener->getResponse();

    bool bIsTradesFound = false;
    if (response)
    {
        O2G2Ptr<IO2GResponseReaderFactory> readerFactory = session->getResponseReaderFactory();
        O2G2Ptr<IO2GTradesTableResponseReader> responseReader = readerFactory->createTradesTableReader(response);
        for (int i = 0; i < responseReader->size(); ++i)
        {
            O2G2Ptr<IO2GTradeRow> trade = responseReader->getRow(i);
            if (strcmp(sOfferID, trade->getOfferID()) != 0)
                continue;

            bIsTradesFound = true;
            std::string sBuySell = trade->getBuySell();
            // Set opposite side
            OrderSide side = (sBuySell == O2G2::Buy) ? Sell : Buy;
            if (closeOrdersData.offerID != sOfferID)
            {
                closeOrdersData.offerID = sOfferID;
                closeOrdersData.account = sAccountID;
                closeOrdersData.side = side;
            }
            else
            {
                OrderSide currentSide = closeOrdersData.side;
                if (currentSide != Both && currentSide != side)
                    closeOrdersData.side = Both;
            }
        }
    }
    return bIsTradesFound;
}
Beispiel #7
0
// Print orders table using IO2GEachRowListener
void printOrders(IO2GTableManager *tableManager, const char *sAccountID)
{
    O2G2Ptr<IO2GOrdersTable> ordersTable = (IO2GOrdersTable *)tableManager->getTable(Orders);
    if (ordersTable->size() == 0)
    {
        std::cout << "Table is empty!" << std::endl;
    }
    else
    {
        ordersTable->forEachRow(new EachRowListener(sAccountID));
    }
}
Beispiel #8
0
// Find the first opened position by AccountID and OfferID
IO2GTradeRow *getTrade(IO2GTableManager *tableManager, const char *sAccountID, const char *sOfferID)
{
    O2G2Ptr<IO2GTradesTable> tradesTable = (IO2GTradesTable *)tableManager->getTable(Trades);
    for (int i = 0; i < tradesTable->size(); ++i)
    {
        O2G2Ptr<IO2GTradeRow> trade = tradesTable->getRow(i);
        if (strcmp(sAccountID, trade->getAccountID()) == 0 && 
                strcmp(sOfferID, trade->getOfferID()) == 0)
            return trade.Detach();
    }
    return NULL;
}
Beispiel #9
0
IO2GOfferRow *getOfferAndPrint(IO2GSession *session, const char *sInstrument)
{
    if (!session || !sInstrument)
        return NULL;

    IO2GOfferRow *resultOffer = NULL;
    O2G2Ptr<IO2GLoginRules> loginRules = session->getLoginRules();
    if (loginRules)
    {
        O2G2Ptr<IO2GResponse> response = loginRules->getTableRefreshResponse(Offers);
        if (response)
        {
            O2G2Ptr<IO2GResponseReaderFactory> readerFactory = session->getResponseReaderFactory();
            if (readerFactory)
            {
                O2G2Ptr<IO2GOffersTableResponseReader> reader = readerFactory->createOffersTableReader(response);
                for (int i = 0; i < reader->size(); ++i)
                {
                    O2G2Ptr<IO2GOfferRow> offer = reader->getRow(i);
                    if (offer)
                    {
                        if (strcmp(offer->getSubscriptionStatus(), O2G2::SubscriptionStatuses::ViewOnly) == 0)
                            printf("%s : [V]iew only\n", offer->getInstrument());
                        else if (strcmp(offer->getSubscriptionStatus(), O2G2::SubscriptionStatuses::Disable) == 0)
                            printf("%s : [D]isabled\n", offer->getInstrument());
                        else if (strcmp(offer->getSubscriptionStatus(), O2G2::SubscriptionStatuses::Tradable) == 0)
                            printf("%s : Available for [T]rade\n", offer->getInstrument());
                        else
                            printf("%s : %s\n", offer->getInstrument(), offer->getSubscriptionStatus());
                        if (strcmp(offer->getInstrument(), sInstrument) == 0)
                            resultOffer = offer.Detach();
                    }
                }
            }
        }
    }
    return resultOffer;
}
Beispiel #10
0
bool isOrderExists(IO2GSession *session, const char *sAccountID, const char *sOrderID, ResponseListener *responseListener)
{
    if (!session || !responseListener || !sAccountID)
        return false;

    O2G2Ptr<IO2GRequestFactory> requestFactory = session->getRequestFactory();
    if (!requestFactory)
    {
        std::cout << "Cannot create request factory" << std::endl;
        return false;
    }

    O2G2Ptr<IO2GRequest> request = requestFactory->createRefreshTableRequestByAccount(Orders, sAccountID);
    responseListener->setRequestID(request->getRequestID());
    session->sendRequest(request);
    if (!responseListener->waitEvents())
    {
        std::cout << "Response waiting timeout expired" << std::endl;
        return false;
    }
    O2G2Ptr<IO2GResponse> response = responseListener->getResponse();
    if (response)
    {
        O2G2Ptr<IO2GResponseReaderFactory> readerFactory = session->getResponseReaderFactory();
        if (readerFactory)
        {
            O2G2Ptr<IO2GOrdersTableResponseReader> ordersResponseReader = readerFactory->createOrdersTableReader(response);
            for (int i = 0; i < ordersResponseReader->size(); ++i)
            {
                O2G2Ptr<IO2GOrderRow> order = ordersResponseReader->getRow(i);
                if (sOrderID && strcmp(order->getOrderID(), sOrderID) == 0)
                    return true;
            }
        }
    }
    return false;
}
void SessionStatusListener::onSessionStatusChanged(IO2GSessionStatus::O2GSessionStatus status)
{
    BOOST_LOG_TRIVIAL(trace) << __PRETTY_FUNCTION__;
    switch (status)
    {
    case IO2GSessionStatus::Disconnected:
        BOOST_LOG_TRIVIAL(info) << "status::disconnected";
        mConnected = false;
        mDisconnected = true;
        SetEvent(mSessionEvent);
        break;
    case IO2GSessionStatus::Connecting:
        BOOST_LOG_TRIVIAL(info) << "status::connecting";
        break;
    case IO2GSessionStatus::TradingSessionRequested:
    {
        BOOST_LOG_TRIVIAL(info) << "status::trading session requested";
        O2G2Ptr<IO2GSessionDescriptorCollection> descriptors = mSession->getTradingSessionDescriptors();
        bool found = false;
        if (descriptors)
        {
            if (mPrintSubsessions)
                BOOST_LOG_TRIVIAL(info) << "descriptors available:";
            for (int i = 0; i < descriptors->size(); ++i)
            {
                O2G2Ptr<IO2GSessionDescriptor> descriptor = descriptors->get(i);
                if (mPrintSubsessions)
                    BOOST_LOG_TRIVIAL(info) << "  id:='" << descriptor->getID()
					    << "' name='" << descriptor->getName()
					    << "' description='" << descriptor->getDescription()
					    << "' " << (descriptor->requiresPin() ? "requires pin" : "");
                if (mSessionID == descriptor->getID())
                {
                    found = true;
                    break;
                }
            }
        }
        if (!found)
        {
            onLoginFailed("The specified sub session identifier is not found");
        }
        else
        {
            mSession->setTradingSession(mSessionID.c_str(), mPin.c_str());
        }
    }
    break;
    case IO2GSessionStatus::Connected:
        BOOST_LOG_TRIVIAL(info) << "status::connected";
        mConnected = true;
        mDisconnected = false;
        SetEvent(mSessionEvent);
        break;
    case IO2GSessionStatus::Reconnecting:
        BOOST_LOG_TRIVIAL(info) << "status::reconnecting";
        break;
    case IO2GSessionStatus::Disconnecting:
        BOOST_LOG_TRIVIAL(info) << "status::disconnecting";
        break;
    case IO2GSessionStatus::SessionLost:
        BOOST_LOG_TRIVIAL(info) << "status::session lost";
        break;
    }
}
Beispiel #12
0
/** Request update data received data handler. */
void ResponseListener::onTablesUpdates(IO2GResponse *data)
{
    if (data)
    {
        O2G2Ptr<IO2GResponseReaderFactory> factory = mSession->getResponseReaderFactory();
        if (factory)
        {
            O2G2Ptr<IO2GTablesUpdatesReader> reader = factory->createTablesUpdatesReader(data);
            if (reader)
            {
                for (int i = 0; i < reader->size(); ++i)
                {
                    switch (reader->getUpdateTable(i))
                    {
                    case Orders:
                    {
                        O2G2Ptr<IO2GOrderRow> order = reader->getOrderRow(i);
                        if (mRequestID != order->getRequestID())
                            break;
                        switch (reader->getUpdateType(i))
                        {
                        case Insert:
                            if ((isClosingOrder(order) || isOpeningOrder(order)) &&
                                    mOrderMonitorNetting == NULL)
                            {
                                std::cout << "The order has been added. OrderID='" << order->getOrderID() << "', "
                                          << "Rate='" << order->getRate() << "', "
                                          << "TimeInForce='" << order->getTimeInForce() << "'"
                                          << std::endl;
                                O2G2Ptr<IO2GTradeRow> trade = NULL;
                                std::string sTradeID = std::string(order->getTradeID());
                                if (mTradesTable)
                                {
                                    for (int j = 0; j < mTradesTable->size(); ++j)
                                    {
                                        if (sTradeID == mTradesTable->getRow(j)->getTradeID())
                                        {
                                            trade = mTradesTable->getRow(j);
                                            break;
                                        }
                                    }
                                }
                                if (trade)
                                    mOrderMonitorNetting = new OrderMonitorNetting(order, trade->getAmount());
                                else
                                    mOrderMonitorNetting = new OrderMonitorNetting(order, 0);
                            }
                            break;
                        case Delete:
                            if (mOrderMonitorNetting)
                            {
                                std::cout << "The order has been deleted. OrderID='" << order->getOrderID() << "'"
                                          << std::endl;
                                mOrderMonitorNetting->onOrderDeleted(order);
                                if (mOrderMonitorNetting->isOrderCompleted())
                                {
                                    printResult();
                                    SetEvent(mResponseEvent);
                                }
                            }
                            break;
                        }
                    }
                    break;
                    case Trades:
                    {
                        O2G2Ptr<IO2GTradeRow> trade = reader->getTradeRow(i);
                        switch (reader->getUpdateType(i))
                        {
                        case Insert:
                        {
                            if (mOrderMonitorNetting)
                            {
                                mOrderMonitorNetting->onTradeAdded(trade);
                                if (mOrderMonitorNetting->isOrderCompleted())
                                {
                                    printResult();
                                    SetEvent(mResponseEvent);
                                }
                            }
                        }
                        break;
                        case Update:
                        {
                            if (mOrderMonitorNetting)
                            {
                                mOrderMonitorNetting->onTradeUpdated(trade);
                                if (mOrderMonitorNetting->isOrderCompleted())
                                {
                                    printResult();
                                    SetEvent(mResponseEvent);
                                }
                            }
                        }
                        break;
                        }
                    }
                    break;
                    case ClosedTrades:
                    {
                        if (reader->getUpdateType(i) == Insert)
                        {
                            O2G2Ptr<IO2GClosedTradeRow> closedTrade = reader->getClosedTradeRow(i);
                            if (mOrderMonitorNetting)
                            {
                                mOrderMonitorNetting->onClosedTradeAdded(closedTrade);
                                if (mOrderMonitorNetting->isOrderCompleted())
                                {
                                    printResult();
                                    SetEvent(mResponseEvent);
                                }
                            }
                        }
                    }
                    break;
                    case Messages:
                    {
                        if (reader->getUpdateType(i) == Insert)
                        {
                            O2G2Ptr<IO2GMessageRow> message = reader->getMessageRow(i);
                            if (mOrderMonitorNetting)
                            {
                                mOrderMonitorNetting->onMessageAdded(message);
                                if (mOrderMonitorNetting->isOrderCompleted())
                                {
                                    printResult();
                                    SetEvent(mResponseEvent);
                                }
                            }
                        }
                    }
                    break;
                    case Accounts:
                    {
                        if (reader->getUpdateType(i) == Update && reader->getUpdateTable(i) == Accounts)
                        {
                            O2G2Ptr<IO2GAccountRow> account = reader->getAccountRow(i);
                            std::cout << "The balance has been changed. AccountID=" << account->getAccountID() << ", "
                                      << "Balance=" << std::fixed << account->getBalance() << std::endl;
                        }
                    }
                    break;
                    }
                }
            }
        }
    }
}
Beispiel #13
0
// Print trading settings of the first account
bool printTradingSettings(IO2GSession *session)
{
    O2G2Ptr<IO2GLoginRules> loginRules = session->getLoginRules();
    if (!loginRules)
    {
        std::cout << "Cannot get login rules" << std::endl;
        return false;
    }
    O2G2Ptr<IO2GResponse> accountsResponse = loginRules->getTableRefreshResponse(Accounts);
    if (!accountsResponse)
    {
        std::cout << "Cannot get response" << std::endl;
        return false;
    }
    O2G2Ptr<IO2GResponse> offersResponse = loginRules->getTableRefreshResponse(Offers);
    if (!offersResponse)
    {
        std::cout << "Cannot get response" << std::endl;
        return false;
    }
    O2G2Ptr<IO2GTradingSettingsProvider> tradingSettingsProvider = loginRules->getTradingSettingsProvider();
    O2G2Ptr<IO2GResponseReaderFactory> factory = session->getResponseReaderFactory();
    if (!factory)
    {
        std::cout << "Cannot create response reader factory" << std::endl;
        return false;
    }
    O2G2Ptr<IO2GAccountsTableResponseReader> accountsReader = factory->createAccountsTableReader(accountsResponse);
    O2G2Ptr<IO2GOffersTableResponseReader> instrumentsReader = factory->createOffersTableReader(offersResponse);
    O2G2Ptr<IO2GAccountRow> account = accountsReader->getRow(0);
    for (int i = 0; i < instrumentsReader->size(); ++i)
    {
        O2G2Ptr<IO2GOfferRow> instrumentRow = instrumentsReader->getRow(i);
        const char *sInstrument = instrumentRow->getInstrument();
        int condDistStopForTrade = tradingSettingsProvider->getCondDistStopForTrade(sInstrument);
        int condDistLimitForTrade = tradingSettingsProvider->getCondDistLimitForTrade(sInstrument);
        int condDistEntryStop = tradingSettingsProvider->getCondDistEntryStop(sInstrument);
        int condDistEntryLimit = tradingSettingsProvider->getCondDistEntryLimit(sInstrument);
        int minQuantity = tradingSettingsProvider->getMinQuantity(sInstrument, account);
        int maxQuantity = tradingSettingsProvider->getMaxQuantity(sInstrument, account);
        int baseUnitSize = tradingSettingsProvider->getBaseUnitSize(sInstrument, account);
        O2GMarketStatus marketStatus = tradingSettingsProvider->getMarketStatus(sInstrument);
        int minTrailingStep = tradingSettingsProvider->getMinTrailingStep();
        int maxTrailingStep = tradingSettingsProvider->getMaxTrailingStep();
        double mmr = tradingSettingsProvider->getMMR(sInstrument, account);
        std::string sMarketStatus = "unknown";
        switch (marketStatus)
        {
        case MarketStatusOpen:
            sMarketStatus = "Market Open";
            break;
        case MarketStatusClosed:
            sMarketStatus = "Market Close";
            break;
        }
        std::cout << "Instrument: " << sInstrument << ", Status: " << sMarketStatus << std::endl;
        std::cout << "Cond.Dist: ST=" << condDistStopForTrade << "; LT=" << condDistLimitForTrade << std::endl;
        std::cout << "Cond.Dist entry stop=" << condDistEntryStop << "; entry limit=" << condDistEntryLimit << std::endl;
        std::cout << "Quantity: Min=" << minQuantity << "; Max=" << maxQuantity
                << "; Base unit size=" << baseUnitSize << "; MMR=" << mmr << std::endl;

        double mmr2=0, emr=0, lmr=0;
        if (tradingSettingsProvider->getMargins(sInstrument, account, mmr2, emr, lmr))
        {
            std::cout << "Three level margin: MMR=" << mmr2 << "; EMR=" << emr
                    << "; LMR=" << lmr << std::endl;
        }
        else
        {
            std::cout << "Single level margin: MMR=" << mmr2 << "; EMR=" << emr
                    << "; LMR=" << lmr << std::endl;
        }
        std::cout << "Trailing step: " << minTrailingStep << "-" << maxTrailingStep << std::endl;
    }
    return true;
}
Beispiel #14
0
/** Request update data received data handler. */
void ResponseListener::onTablesUpdates(IO2GResponse *data)
{
    if (data)
    {
        O2G2Ptr<IO2GResponseReaderFactory> factory = mSession->getResponseReaderFactory();
        if (factory)
        {
            O2G2Ptr<IO2GTablesUpdatesReader> reader = factory->createTablesUpdatesReader(data);
            if (reader)
            {
                for (int i = 0; i < reader->size(); ++i)
                {
                    switch (reader->getUpdateTable(i))
                    {
                    case Orders:
                    {
                        O2G2Ptr<IO2GOrderRow> order = reader->getOrderRow(i);
                        if (reader->getUpdateType(i) == Insert)
                        {
                            if (mBatchOrderMonitor)
                            {
                                std::cout << "The order has been added. OrderID='" << order->getOrderID() << "', "
                                        << "Rate='" << order->getRate() << "', "
                                        << "TimeInForce='" << order->getTimeInForce() << "'"
                                        << std::endl;
                                mBatchOrderMonitor->onOrderAdded(order);
                            }
                        }
                        else if (reader->getUpdateType(i) == Delete)
                        {
                            if (mBatchOrderMonitor)
                            {
                                std::cout << "The order has been deleted. OrderID='" << order->getOrderID() << "'"
                                        << std::endl;
                                mBatchOrderMonitor->onOrderDeleted(order);
                                if (mBatchOrderMonitor->isBatchExecuted())
                                {
                                    printResult();
                                    SetEvent(mResponseEvent);
                                }
                            }
                        }
                    }
                    break;
                    case Trades:
                    {
                        if (reader->getUpdateType(i) == Insert)
                        {
                            O2G2Ptr<IO2GTradeRow> trade = reader->getTradeRow(i);
                            if (mBatchOrderMonitor)
                            {
                                mBatchOrderMonitor->onTradeAdded(trade);
                                if (mBatchOrderMonitor->isBatchExecuted())
                                {
                                    printResult();
                                    SetEvent(mResponseEvent);
                                }
                            }
                        }
                    }
                    break;
                    case ClosedTrades:
                    {
                        if (reader->getUpdateType(i) == Insert)
                        {
                            O2G2Ptr<IO2GClosedTradeRow> closedTrade = reader->getClosedTradeRow(i);
                            if (mBatchOrderMonitor)
                            {
                                mBatchOrderMonitor->onClosedTradeAdded(closedTrade);
                                if (mBatchOrderMonitor->isBatchExecuted())
                                {
                                    printResult();
                                    SetEvent(mResponseEvent);
                                }
                            }
                        }
                    }
                    break;
                    case Messages:
                    {
                        if (reader->getUpdateType(i) == Insert)
                        {
                            O2G2Ptr<IO2GMessageRow> message = reader->getMessageRow(i);
                            if (mBatchOrderMonitor)
                            {
                                mBatchOrderMonitor->onMessageAdded(message);
                                if (mBatchOrderMonitor->isBatchExecuted())
                                {
                                    printResult();
                                    SetEvent(mResponseEvent);
                                }
                            }
                        }
                    }
                    break;
                    case Accounts:
                    {
                        if (reader->getUpdateType(i) == Update && reader->getUpdateTable(i) == Accounts)
                        {
                            O2G2Ptr<IO2GAccountRow> account = reader->getAccountRow(i);
                            std::cout << "The balance has been changed. AccountID=" << account->getAccountID() << ", "
                                    << "Balance=" << std::fixed << account->getBalance() << std::endl;
                        }
                    }
                    break;
                    }
                }
            }
        }
    }
}