neka-nat / python-forexconnect

Python binding of forexconnect api
39 stars 24 forks source link

Added some changes #19

Closed JamesKBowler closed 6 years ago

JamesKBowler commented 6 years ago

Hi Neka,

I've added some modifications to split up the classes so different sessions can be created with FXCM, i.e. one with and without the live offers table in memory. Also no point in having multiple copies of the same offers table, as this is VERY CPU intensive causing timeouts when many sessions are created.

Also, I think some of the raised exceptions need modifying, so they pass a value back. For example:

std::string ForexConnectOffersClient::getOfferTradingStatus(const std::string& instrument) 
{
    TableHandler<Offers, IO2GOffersTable, IO2GOfferTableRow> handler(mpSession);
    while (handler.getNextRow())
    {
        IO2GOfferTableRow* offerRow = handler.getRow();
        if (offerRow->getInstrument() == instrument)
        {
            return offerRow->getTradingStatus();
        }
    }
    return "U";
}

double ForexConnectOffersClient::getOfferTime(const std::string& instrument) 
{
    TableHandler<Offers, IO2GOffersTable, IO2GOfferTableRow> handler(mpSession);
    while (handler.getNextRow())
    {
        IO2GOfferTableRow* offerRow = handler.getRow();
        if (offerRow->getInstrument() == instrument)
        {
            return offerRow->getTime();
        }
    }
    return 0.0;
}

double ForexConnectOffersClient::getBid(const std::string& instrument) {
    TableHandler<Offers, IO2GOffersTable, IO2GOfferTableRow> handler(mpSession);
    while (handler.getNextRow())
    {
        IO2GOfferTableRow* offerRow = handler.getRow();
        if (offerRow->getInstrument() == instrument)
        {
            return offerRow->getBid();
        }
    }
    return 0.0;
}

I have removed the while loop from getHistoricalPrice too because this allows a lot more control in python and is much more efficient in terms of RAM usage when collecting large price data ranges.

On the python side, it would look like this... https://github.com/JamesKBowler/fxcollect/blob/master/fx_collect/broker/fxcm.py

Summary ~ split up the clients
~ removed time zone date time and made UTC
~ removed while loop
~ changed runtimeerror exceptions to return a default value
~ added more "get
" options for each offer

Please review the changes and add to master once you are happy with the code, my C++ is not the best : )

Thanks again for creating this C++ FXCM API, I would be lost without it.

Cheers

James

neka-nat commented 6 years ago

Thank you pull request. Although I looked at it, since many parts that are not related to the main modification such as indent space and variable name have been changed, it is hard to see the modification.

Please restore indent space and variable name. Or please separate pull requests.

JamesKBowler commented 6 years ago

ok thanks will come back to you.