/** 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);
							}
						}
					}
				}
			}
		}
	}
}
示例#2
0
void ResponseListener::printResult()
{
    if (mOrderMonitorNetting)
    {
        OrderMonitorNetting::ExecutionResult result = mOrderMonitorNetting->getResult();
        std::vector<IO2GTradeRow*> trades;
        std::vector<IO2GTradeRow*> updatedTrades;
        std::vector<IO2GClosedTradeRow*> closedTrades;
        O2G2Ptr<IO2GOrderRow> order = mOrderMonitorNetting->getOrder();
        std::string orderID = order->getOrderID();
        mOrderMonitorNetting->getTrades(trades);
        mOrderMonitorNetting->getUpdatedTrades(updatedTrades);
        mOrderMonitorNetting->getClosedTrades(closedTrades);

        switch (result)
        {
        case OrderMonitorNetting::Canceled:
        {
            if (trades.size() > 0)
            {
                printTrades(trades, orderID);
                printUpdatedTrades(updatedTrades, orderID);
                printClosedTrades(closedTrades, orderID);
                std::cout << "A part of the order has been canceled. "
                          << "Amount = " << mOrderMonitorNetting->getRejectAmount() << std::endl;
            }
            else
            {
                std::cout << "The order: OrderID=" << orderID << " has been canceled"  << std::endl;
                std::cout << "The cancel amount = " << mOrderMonitorNetting->getRejectAmount() << std::endl;
            }
        }
        break;
        case OrderMonitorNetting::FullyRejected:
        {
            std::cout << "The order has been rejected. OrderID = " << orderID << std::endl;
            std::cout << "The rejected amount = " << mOrderMonitorNetting->getRejectAmount() << std::endl;;
            std::cout << "Rejection cause: " << mOrderMonitorNetting->getRejectMessage() << std::endl;
        }
        break;
        case OrderMonitorNetting::PartialRejected:
        {
            printTrades(trades, orderID);
            printUpdatedTrades(updatedTrades, orderID);
            printClosedTrades(closedTrades, orderID);
            std::cout << "A part of the order has been rejected. "
                      << "Amount = " << mOrderMonitorNetting->getRejectAmount() << std::endl;
            std::cout << "Rejection cause: " << mOrderMonitorNetting->getRejectMessage() << std::endl;
        }
        break;
        case OrderMonitorNetting::Executed:
        {
            printTrades(trades, orderID);
            printUpdatedTrades(updatedTrades, orderID);
            printClosedTrades(closedTrades, orderID);
        }
        break;
        }
    }
}
示例#3
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;
}
示例#4
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;
                    }
                }
            }
        }
    }
}
示例#5
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;
                    }
                }
            }
        }
    }
}