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

Binance API or updating backtrader every 5 min



  • Hi there,

    I've backtested a variety of cryptocurrency strategies with backtrader and am now at the point where I'd like to start papertrading. I'm struggling to come up with the best way to go about implementing it. I'd prefer to be able to connect backtrader directly to Binance through its API, but I'm having a hard time finding how to directly do this. I found a thread on implementing a CCXT extension, but there still seems to be some issues with that. My other option would be to set a timer on a python script to the Binance API, store the data as a CSV, and then have backtrader take in the new data. My main question about this method is whether or not backtrader has the ability to (once initially run) call on the new data every few minutes so that I'm trading on a 5 minute lag or less.

    Hopefully I described my situation well enough, if not please let me know. If anybody has additional ideas that what I'd come up with, I'm all ears! Thanks y'all


  • administrators

    Your best bet is to create a data feed which reports to be a live data feed.

    This data feed waits for something like:

    • A csv file which grows
    • A binary file which grows
    • Communication over a socket or pipe
    • ...
    • It can even call the Binance API every 5 minutes and use the result

    Of course you want to pay attention to these events in a background thread.

    And you return the data to the system.

    Check for example the sources for OandaData: https://github.com/backtrader/backtrader/blob/master/backtrader/feeds/oanda.py



  • I am also trying to use the CCXT lib from https://github.com/Dave-Vallance/bt-ccxt-store. The feed works very fine with 1 minute time frame. But with other compressions, does not work.

    I also tried to add to cerebro with:

    cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes, compression=5)
    

    But does not work too.
    @guwop do you have some progress with it?


Log in to reply
 

});