std::string ForexConnectWrapper::getTradesAsYAML() { std::string rv; IO2GTableManager *tableManager = getLoadedTableManager(); IO2GTradesTable *tradesTable = (IO2GTradesTable *)tableManager->getTable(Trades); IO2GTradeTableRow *tradeRow = NULL; IO2GTableIterator tableIterator; while (tradesTable->getNextRow(tableIterator, tradeRow)) { bool isLong = (strncmp(tradeRow->getBuySell(), "B", 1) == 0); double d = tradeRow->getOpenTime(); std::string openDateTime; formatDate(d, openDateTime); IO2GOfferRow *offer = getTableRow<IO2GOfferRow, IO2GOffersTableResponseReader>(Offers, tradeRow->getOfferID(), &findOfferRowByOfferId, &getOffersReader); rv.append("- symbol: ").append(offer->getInstrument()).append("\n"); offer->release(); rv.append(" id: ").append(tradeRow->getTradeID()).append("\n"); rv.append(" direction: ").append(isLong ? "long" : "short").append("\n"); rv.append(" openPrice: ").append(double2str(tradeRow->getOpenRate())).append("\n"); rv.append(" size: ").append(int2str(tradeRow->getAmount())).append("\n"); rv.append(" openDate: ").append(openDateTime).append("\n"); rv.append(" pl: ").append(double2str(tradeRow->getGrossPL())).append("\n"); tradeRow->release(); } tradesTable->release(); tableManager->release(); return rv; }
void ForexConnectWrapper::closeMarket(const std::string tradeID, int amount) { IO2GTradeTableRow *trade = getTradeTableRow(tradeID); if (!trade) { std::stringstream ss; ss << "Could not find trade with ID = " << tradeID; log(ss.str()); throw ss.str().c_str(); } IO2GValueMap *valuemap = mRequestFactory->createValueMap(); valuemap->setString(Command, O2G2::Commands::CreateOrder); valuemap->setString(OrderType, O2G2::Orders::TrueMarketClose); valuemap->setString(AccountID, sAccountID.c_str()); valuemap->setString(OfferID, trade->getOfferID()); valuemap->setString(TradeID, tradeID.c_str()); valuemap->setString(BuySell, ( strncmp(trade->getBuySell(), "B", 1) == 0 ? O2G2::Sell : O2G2::Buy ) ); trade->release(); valuemap->setInt(Amount, amount); //valuemap->setString(CustomID, "Custom"); IO2GRequest *request = mRequestFactory->createOrderRequest(valuemap); valuemap->release(); TableListener *tableListener = new TableListener(); tableListener->setRequestID(request->getRequestID()); IO2GTableManager *tableManager = getLoadedTableManager(); subscribeTableListener(tableManager, tableListener); Listener *ll = new Listener(session); IO2GResponse *response = ll->sendRequest(request); request->release(); ll->release(); if (!response) { std::stringstream ss; ss << "Failed to get response to closeMarket request " << tradeID << " " << amount; log(ss.str()); throw ss.str().c_str(); } tableListener->waitForTableUpdate(); response->release(); unsubscribeTableListener(tableManager, tableListener); tableListener->release(); tableManager->release(); }