Maybe this will help someone... I had the same issue and solved it by using a percentage of my portfolio
params = (('prop', 0.1),)
def _getsizing(self, comminfo, cash, data, isbuy):
"""Returns the proper sizing"""
if isbuy: # Buying
target = self.broker.getvalue() * self.params.prop # Ideal total value of the position
price = data.close
size_net = target / price # How many shares are needed to get target
size = size_net * 0.99
if size * price > cash:
return 0 # Not enough money for this trade
else: # Selling
return self.broker.getposition(data).size # Clear the position
I've succesfully implemented ccxtbt to backtrader and can trade live on Binance. However there are some things unclear to me:
Looking at de debug output I can see ccxtbt is continously fetching the newest ohlcv ticks, multiple times per second.
Using bt.Timeframe.Minutes my next() is only called once per minute. However I want my next() to be called every new tick. When I apply the bt.Timeframe.Ticks as supported by Backtrader, I get the following error:
ValueError: backtrader CCXT module doesn't support fetching OHLCV data for time frame Tick, comression 1
Is this correct? Is there no way for me to get the individual tick price live, and feed it to my next() ?