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;
}
std::vector<TradeInfo> ForexConnectClient::getTrades()
{
    std::vector<TradeInfo> trades;
    TableHandler<Trades, IO2GTradesTable, IO2GTradeTableRow> handler(mpSession);
    std::map<std::string, std::string> offers = getOffers();
    while (handler.getNextRow())
    {
	IO2GTradeTableRow* tradeRow = handler.getRow();
	TradeInfo trade;
	const std::map<std::string, std::string>::const_iterator it = std::find_if(offers.begin(),
										   offers.end(),
										   boost::bind(&std::map<std::string, std::string>::value_type::second, _1) == tradeRow->getOfferID());
	if (it == offers.end())
	{
	    throw std::runtime_error("Could not get offer table row.");
	}
        trade.mInstrument = it->first;
	trade.mTradeID = tradeRow->getTradeID();
        trade.mBuySell = tradeRow->getBuySell();
        trade.mOpenRate = tradeRow->getOpenRate();
        trade.mAmount = tradeRow->getAmount();
        trade.mOpenDate = toPtime(tradeRow->getOpenTime());
        trade.mGrossPL = tradeRow->getGrossPL();
	trades.push_back(trade);
    }
    return trades;
}