Пример #1
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;
}
Пример #2
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;
}