Closed rohsat closed 2 years ago
Hey @rohsat, this is indeed correct and we highlight this a little bit in here. The issue is because when you store the asset, the asset is stored as BTC
and not stored as BTC-USDT
, as a result, we do have to store it and utilize the interface.account[state.base_asset].available
. You can also take a look at this sample RSI that's found here
def price_event(price, symbol, state: blankly.StrategyState):
""" This function will give an updated price every 15 seconds from our definition below """
state.variables['history'].append(price)
rsi = blankly.indicators.rsi(state.variables['history'])
if rsi[-1] < 40 and not state.variables['owns_position']:
# Dollar cost average buy
buy = blankly.trunc(state.interface.cash/price, 2)
state.interface.market_order(symbol, side='buy', size=buy)
state.variables['owns_position'] = True
elif rsi[-1] > 60 and state.variables['owns_position']:
# Dollar cost average sell
curr_value = blankly.trunc(state.interface.account[state.base_asset].available, 2)
state.interface.market_order(symbol, side='sell', size=curr_value)
state.variables['owns_position'] = False
def init(symbol, state: blankly.StrategyState):
# Download price data to give context to the algo
state.variables['history'] = state.interface.history(symbol, to=150, return_as='deque',
resolution=state.resolution)['close']
state.variables['owns_position'] = False
Description
While backtesting golden_cross.py example in BInance with asset = BTC-USTD, the code was able buy but not sell.
The code only worked when I modified the below line (as given in rsi.py).
to
Could you please check why this is happening?
settings.json
backtest.json
Error (got the error multiple times - showing two)
Platform Info