For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Disconnect behavior when live trading



  • I have a question regarding backtrader's behavior when encountering a connection loss while live trading:

    As shown in the blog (https://www.backtrader.com/blog/posts/2016-06-21-livedata-feed/live-data-feed.html) when the connection gets lost when in live mode then the current bar (which got interrupted) will still be yielded when the bar ends.

    This can be seen here (bar 1443):

    Output (skipping the initial known part):
    
    
    ...
    1440, 2016-06-20T18:16:20.000000, 16.05, 16.05, 16.04, 16.04, 0.0, 0, 16.048
    1441, 2016-06-20T18:16:25.000000, 16.05, 16.05, 16.05, 16.05, 0.0, 0, 16.05
    ***** DATA NOTIF: LIVE
    1442, 2016-06-20T18:16:30.000000, 15.9, 15.9, 15.89, 15.9, 11.0, 0, 16.02
    ***** STORE NOTIF: <error id=-1, errorCode=1100, errorMsg=Connectivity between IB and TWS has been lost.>
    ***** STORE NOTIF: <error id=-1, errorCode=2105, errorMsg=HMDS data farm connection is broken:demohmds>
    ***** STORE NOTIF: <error id=-1, errorCode=2103, errorMsg=Market data farm connection is broken:ibdemo>
    1443, 2016-06-20T18:16:35.000000, 15.9, 15.9, 15.89, 15.9, 28.0, 0, 15.988
    ***** STORE NOTIF: <error id=-1, errorCode=1102, errorMsg=Connectivity between IB and TWS has been restored - data maintained.>
    ***** STORE NOTIF: <error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:demohmds>
    ***** STORE NOTIF: <error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:ibdemo>
    ***** DATA NOTIF: DELAYED
    1444, 2016-06-20T18:16:40.000000, 16.04, 16.04, 16.03, 16.04, 0.0, 0, 15.986
    1445, 2016-06-20T18:16:45.000000, 16.03, 16.04, 16.03, 16.04, 0.0, 0, 15.986
    1446, 2016-06-20T18:16:50.000000, 16.04, 16.04, 16.03, 16.03, 0.0, 0, 15.982
    1447, 2016-06-20T18:16:55.000000, 16.04, 16.04, 16.03, 16.04, 0.0, 0, 16.01
    1448, 2016-06-20T18:17:00.000000, 16.03, 16.04, 16.03, 16.04, 0.0, 0, 16.038
    1449, 2016-06-20T18:17:05.000000, 16.03, 16.04, 16.02, 16.03, 0.0, 0, 16.036
    1450, 2016-06-20T18:17:10.000000, 15.9, 15.91, 15.9, 15.91, 3.0, 0, 16.01
    ***** DATA NOTIF: LIVE
    1451, 2016-06-20T18:17:15.000000, 15.92, 15.92, 15.9, 15.92, 9.0, 0, 15.988
    1452, 2016-06-20T18:17:20.000000, 15.91, 15.91, 15.89, 15.89, 18.0, 0, 15.958
    1453, 2016-06-20T18:17:25.000000, 15.89, 15.92, 15.89, 15.89, 24.0, 0, 15.928
    ...
    The narrative:
    
    After bar 1442, the WLAN interface has been disabled
    
    TWS notifications arrive indicating the situation
    
    Bar 1443 is delivered from the resampler, because the platform had some ticks in between 18:16:30.000000 and 18:16:35.000000
    

    I am referring to the last sentence which describes the behavior I am seeing. So I guess this behavior is intended.

    I was surprised about this behavior and thought if it wouldn't be better if backtrader would not yield the bar (which is based on incomplete data) and rather backfill it later upon reconnection like the other missing bars?

    I mean in worst case you could be trading D1 bars and only had a single tick from that day but still a whole bar would be yielded based on a single tick?


 

});