Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

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

    General Code/Help
    3
    6
    2710
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      backtrader administrators last edited by

      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
      
      
      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        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
        
        1 Reply Last reply Reply Quote 0
        • K
          kicking_potato88 last edited by

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

          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • ealvarpe
              ealvarpe last edited by

              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
              
              1 Reply Last reply Reply Quote 0
              • B
                backtrader administrators last edited by

                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

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors