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

Anyone use backtrader to do live trading on Bitcoin exchange?



  • @thatblokedave
    Definitively coming to the same conclusion and probably the same solution or a solution using a smart ratelimiter.
    But If we don't need those broker values intensively, we can cheat.

    You can check my thought here : https://github.com/bartosh/backtrader/issues/22

    Even for getposition(). A strategy can store and update his own size with orders notifications.



  • Hi everyone,

    First of all thanks @Ed-Bartosh for implementing the CCXT broker.

    I was wandering what is the official repo for this and if there is any plan to contribute this back to backtrader or to develop as a standalone module that people could use.

    I'm starting to use it, and I'd be happy to contribute to it but so far the only thing I have found is this fork: https://github.com/bartosh/backtrader/tree/ccxt

    Thanks
    Simone



  • I think the most up to date repo is this one:
    https://github.com/Dave-Vallance/bt-ccxt-store



  • Thanks @sandro-böhme , the repo that you mention seems to be the latest one and is working fine with Binance as per my testings. I have a question in regards to the order status. I do place orders correctly and can see the order status in the dashboard. However, in the notify_order() when it comes to printing exections details like :
    self.log (order.executed.price,order.executed.value,order.executed.comm)

    It always prints 0 for all 3 values, I am not sure why I cant see the order execution details. Does it work for you? Also, is there anyone actively looking at fixing the reported issues?

    Thanks



  • Hey, Im having a problem when trying to run the following code.
    I get the error: AttributeError: module 'backtrader.feeds' has no attribute 'CCXT'
    I'm running the latest version of python on the latest version of ubuntu and when I check pip3 freeze, I have backtrader and ccxt installed.

    import backtrader as bt
    import ccxt
    import pandas as pd

    class Strategy():
    def init(self, client, timeframe='5m'):
    self.client = client
    self.timeframe = timeframe

    def getSignal(self):
    	cerebro = bt.Cerebro()
    	data = bt.feeds.CCXT(exchange='bitmex', symbol='BTC/USD', timeframe=bt.TimeFrame.Minutes, compression=1)
    	cerebro.addstrategy(bt.Strategy)
    	cerebro.adddata(data)
    	print(data)
    	cerebro.run()
    	cerebro.plot(style="candlesticks")
    

    any help would be appreciated



  • @noh I did have a similar issue which resolved it. You need to make sure to create a new environment with correct version of the BT fork for CCXT. See below the steps I followed to fix my issue:

    conda create --name New-env
    source activate New-env
    conda install -c anaconda git
    pip install ccxt
    pip install git+https://github.com/Dave-Vallance/bt-ccxt-store.git

    This should resolve your issue.



  • I published a simple example with Binance integration: https://github.com/rodrigo-brito/backtrader-binance-bot



  • @rodrigo-brito This looks great thanks for sharing!



  • @rodrigo-brito
    how do you achieve data persistence between restarts?



  • @coolernax I don't persist the feed or strategies positions. The feed loads a delayed history when started. About the trade position, I'm start always with no funds in crypto, the first operation should be a buy. Maybe it can be improved with a simple flag in the script.



  • @rodrigo-brito -

    1. When running your script in live mode does the notify_order() return correct order details? when i place order I am unable to get filled price back from order.executed.price,order.executed.value,order.executed.comm all the fileds returning 0. Is this something that anyone looking at fixing?
    2. How stable do you think the CCXT Live broker for BT is at the moment? Do you have high confidence in it's stability? Are you running it live?
    3. Also, the Dave-wallace fork seems to have a new function self.getposition() whch does not seem to work for Binance as i receive empty object where I should get a list of my open positions.


  • Hi, @pfederra

    1. I have the same issue in notify_order(), it works only in simulations to me.
    2. I think the fork has a lot of issues, but work very well for the main features, like order and feed.
    3. The get positions does not work for me very well, it has a precision issue. I'm using a function to get my wallet ballance and settting a custom sizer. I'm also defining a global variable with the last operation (BUY/SELL) to control the next operation. It is a working arrond, but working in live.


  • @rodrigo-brito
    How do we proceed to test with another dataset ? (ex: from 01/01/2019 to 05/05/2019)
    It seems that your scripts do not incorporate params to generate a csv file with from some date to another.

    Best regards,
    Diamond



  • Hi there. In each loop (calling _load()), maybe more than one trade is appended in the "for trade in trades" block, but only one trade is popped, ie. trade = self.trades.popleft(). Will this cause delay? Will this datafeed be much slower than the real world?



  • Hi guys. I am using this CCXTbt library, and to be honnest, it's kinda hard getting it to work properly. I have a simple question: How ot have a fetch_ohlcv function work on an optimised time frame ? The thing is, I see this function running all the time, spamming the exchange with no reason. I think that instead, it should be called at a fixed time, like every minute, or every granularity, more generally speaking.

    I am perfectly aware of the rateLimit parameter on the exchange, but I don't want to set a timeout between my API calls: I don't want any timeout between the time I fetch a ticker, and place an order, because a small wait can result in losing a bid or a sell.



  • @theroque said in Anyone use backtrader to do live trading on Bitcoin exchange?:

    Hi guys. I am using this CCXTbt library, and to be honnest, it's kinda hard getting it to work properly. I have a simple question: How ot have a fetch_ohlcv function work on an optimised time frame ? The thing is, I see this function running all the time, spamming the exchange with no reason. I think that instead, it should be called at a fixed time, like every minute, or every granularity, more generally speaking.

    I am perfectly aware of the rateLimit parameter on the exchange, but I don't want to set a timeout between my API calls: I don't want any timeout between the time I fetch a ticker, and place an order, because a small wait can result in losing a bid or a sell.

    Try this thread:
    https://community.backtrader.com/topic/401/optimizing-with-ibstore-causes-redundant-connections-downloads/5

    A similar thing happens with IB on optimization. BT has the best answer at the end.



  • Hey guys awesome work you are doing here.
    Is this the best fork to start with? https://github.com/bartosh/backtrader/tree/ccxt
    I'm looking to trade bitmex, polonix, btcmarkets.


  • administrators

    You probably want to use a Store, rather than a fork (which had no good reason to be). Someone took the right approach extracting the code from the fork.


 

});