IB example - connection "delayed" on forex data #222


  • administrators

    From Issue #222


    Hi, I've been trying to run the IBtest example, however can't see to access live feed, just shows me that the data feed is delayed and disconnects. I currently have a live account with IB but did not subscribe to any market data, though I understand FX data is free. Hope for your help, thanks!

    
    e:\PythonWork\BackTrader>python ibtest.py --data0 EUR.USD-CASH-IDEALPRO
    
    Server Version: 76
    TWS Time at connection:20161212 17:23:42 SGT
    --------------------------------------------------
    Strategy Created
    --------------------------------------------------
    Timezone from ContractDetails: EST
    Datetime, Open, High, Low, Close, Volume, OpenInterest, SMA
    ***** STORE NOTIF: <error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:usfuture>
    ***** STORE NOTIF: <error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:cashfarm>
    ***** STORE NOTIF: <error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:usfarm>
    ***** STORE NOTIF: <error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:ushmds>
    ***** DATA NOTIF: DELAYED
    ***** DATA NOTIF: DISCONNECTED
    
    

  • administrators

    Try telling the sample to what you actually want the data resampled to. For example

    ./ibtest.py --data0 EUR.USD-CASH-IDEALPRO --resample --timeframe Seconds --compression 1
    


  • Thanks for such a quick reply! And yes, issue solved too.


  • administrators

    The reason being that IB provides no historical data for Ticks which is the default timeframe.

    An alternative to get the ticks in realtime without resampling

    ./ibtest.py --data0 EUR.USD-CASH-IDEALPRO --no-backfill_start --no-backfill
    

    The first disables the initial backfill and the second any backfill in case a disconnection would take place.



  • I´ve tried to run the example with the first arguments you mentioned

    ./ibtest.py --data0 EUR.USD-CASH-IDEALPRO --resample --timeframe Seconds --compression 1
    

    but it seems I´m getting real time data, not every second, instead every random number of seconds... not quite sure if it´s something wrongly configured on my tws or something else.. has someone experience this?
    This is the output I'm getting:

    Data0, 1798, 736337.9405092592, 2017-01-08T17:34:20.000000, 1.05305, 1.05305, 1.05305, 1.05305, -1.0, 0, 1.05305
    Data0, 1799, 736337.9405208334, 2017-01-08T17:34:21.000000, 1.05305, 1.05305, 1.05305, 1.05305, -1.0, 0, 1.05305
    Data0, 1800, 736337.9405324074, 2017-01-08T17:34:22.000000, 1.05305, 1.05305, 1.05305, 1.05305, -1.0, 0, 1.05305
    ***** DATA NOTIF: LIVE
    Data0, 1801, 736337.9405555555, 2017-01-08T17:34:24.000000, 1.05305, 1.05305, 1.05305, 1.05305, 0.0, 0, 1.05305
    Data0, 1802, 736337.9411226852, 2017-01-08T17:35:13.000000, 1.05295, 1.05295, 1.05295, 1.05295, 0.0, 0, 1.0530300000000001
    Data0, 1803, 736337.9416319445, 2017-01-08T17:35:57.000000, 1.0529, 1.0529, 1.0529, 1.0529, 0.0, 0, 1.0530000000000002
    Data0, 1804, 736337.9417592592, 2017-01-08T17:36:08.000000, 1.05295, 1.05295, 1.05295, 1.05295, 0.0, 0, 1.05298
    Data0, 1805, 736337.9417824075, 2017-01-08T17:36:10.000000, 1.053, 1.053, 1.053, 1.053, 0.0, 0, 1.05297
    Data0, 1806, 736337.9417939815, 2017-01-08T17:36:11.000000, 1.05305, 1.05305, 1.05305, 1.05305, 0.0, 0, 1.05297
    Data0, 1807, 736337.9420833334, 2017-01-08T17:36:36.000000, 1.053, 1.053, 1.053, 1.053, 0.0, 0, 1.05298
    Data0, 1808, 736337.9423148148, 2017-01-08T17:36:56.000000, 1.05305, 1.05305, 1.05305, 1.05305, 0.0, 0, 1.05301
    

  • administrators

    That would mean that there are actually no transactions happening during those seconds. With 2 possibilities in mind:

    • You have joined the data feed during a not so active market phase

    or

    • You are testing against the demo account setup of TWS

    Take into account that the data feed provided by IB for Forex is not like the data feed for equities, for example. Appearances of the BID price will be recorded as the indication for price oscillation. This is what also others do.

    In any case you may also run the sample with --debug and you will have the chance to see all messages delivered by TWS to your client (literally all), which may help you follow the details of the price formation in Forex

    You may change BID to ASK or MID (check the IB documentation for possible values) by manipulating the what parameter during the creation of an IBData data feed in backtrader.

    Read here: Data feeds reference


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.