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

Futures Live Trading



  • Hello everyone,
    I am trying to use backtrader with Interactive Brokers in order to live trade Futures. I am running into two problems.

    1. Is there a way to get all the contracts related to a symbol ( for example CL ) , in order to add them as feeds to backtrader, get their expiration dates, their multipliers etc?
    2. Can I get historical data from ib for a continuous future? Or I need to request the separate contracts and then use the Rollover class to create the continuous feed?

    Thanks in advance.



  • What contract are you looking for for historical data?



  • Well let's say I want to trade Crude Oil Jul 2020 and I want to get an indicator going back 1 year.



  • I understand that my question seemed rather vague but I am new both at backtrader and algorithmic trading altogether, so I am struggling with the actual implementation details as well as trading concepts at the same time.
    I will try to rephrase my question in hopes that it will be more clear what I am trying to do.

    I want to use backtrader with IB for live trading futures contracts. What I cannot wrap my mind around, is how can I rollover the contract to the next. I understand how I can do this in backtesting using the Rollover class and its functionality but in live trading I can only have the current contract as a live feed.

    My thought at this point is to get the feed for both the front month future as well as the next few months and recreate the rollover logic to decide when I will start trading with the next month's feed. The problem with this logic is that if I want to trade with a large universe of futures the number of feeds will grow. If this is the only way could I possibly add the feeds dynamically so that I only have a small number of contracts per future and load the next one after I rollover?

    Has anyone out there have any sample code I could study for futures live trading?

    Once again thank you for your patience.



  • Intraday or daily bars?



  • @ab_trader Daily bars



  • @giakoumis said in Futures Live Trading:

    I want to use backtrader with IB for live trading futures contracts. What I cannot wrap my mind around, is how can I rollover the contract to the next. I understand how I can do this in backtesting using the Rollover class and its functionality but in live trading I can only have the current contract as a live feed.

    You may want to have live data feed for the active contract from ib and than use backfill_from parameter to backfill the data from previously stored continuous contracts. On the first look every time you switch to next contract the bt needs to be restarted with new live data feed and new backfill_from data.

    @giakoumis said in Futures Live Trading:

    If this is the only way could I possibly add the feeds dynamically so that I only have a small number of contracts per future and load the next one after I rollover?

    Data feeds should be added before the cerebro run started, not on the fly. But restarting bt every time you start trading new contract can help.

    But honestly if you are trading on the daily bars having live trading setup is more hassle than worse.



  • @ab_trader Thank you very much for your suggestions. I will look into them in more detail.


Log in to reply
 

});