// Get and print margin requirements void printMargins(IO2GSession *session, IO2GAccountRow *account, IO2GOfferRow *offer) { O2G2Ptr<IO2GLoginRules> loginRules = session->getLoginRules(); if (!loginRules) { std::cout << "Cannot create request" << std::endl; return; } O2G2Ptr<IO2GTradingSettingsProvider> tradingSettings = loginRules->getTradingSettingsProvider(); double dMmr = 0; double dEmr = 0; double dLmr = 0; tradingSettings->getMargins(offer->getInstrument(), account, dMmr, dEmr, dLmr); std::cout << "Margin requirements: MMR=" << std::fixed << dMmr << "; EMR=" << std::fixed << dEmr << "; LMR=" << std::fixed << dLmr << std::endl; }
// 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; }