-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'StrategyLogger' object has no attribute 'get_position' #220
Comments
Did you make any modifications to the file? Make sure to run code like below: import blankly
from blankly import futures, Side
from blankly.futures import FuturesStrategyState
from blankly.futures.utils import close_position
def price_event(price, symbol, state: FuturesStrategyState):
prev_price = state.variables['prev_price']
position = state.interface.get_position(symbol)
# if the price rose more than 1,000 and we don't already have a short position, then short sell
if not position and price - prev_price >= 1000:
order_size = (state.interface.cash / price) * 0.99
state.interface.market_order(symbol, Side.SELL, order_size)
# if the price stablized and we *do* have a short position, close our position.
elif position and abs(price - prev_price) <= 100:
# we use abs(position['size']) here because position['size'] can (and will) be negative, since we have taken a short position.
state.interface.market_order(symbol, Side.BUY, abs(position['size']), reduce_only=True)
state.variables['prev_price'] = price
# This function will be run before our algorithm starts
def init(symbol, state: FuturesStrategyState):
# Close any open positions
close_position(symbol, state)
# Give the algo the previous price as context
last_price = state.interface.history(symbol, to=1, return_as='deque', resolution=state.resolution)['close'][-1]
state.variables['prev_price'] = last_price
if __name__ == "__main__":
exchange = futures.BinanceFutures()
strategy = futures.FuturesStrategy(exchange)
strategy.add_price_event(price_event, init=init, teardown=close_position, symbol='BTC-USDT', resolution='1d')
if blankly.is_deployed:
strategy.start()
else:
strategy.backtest(to='1y', initial_values={'USDT': 10000}) |
just strategy.start() |
Looks like it could be some futures bug, I'll have to check into this |
Hi guys! Is there any way to fix this? Backtests for FuturesStrategy class with futures exchange work fine. But cant get start() method to work
adding these lines before calling |
Description
I run the file 'futures_tutorial.py' , then got this error:
'StrategyLogger' object has no attribute 'get_position'
settings.json
settings.json here
backtest.json (if applicable)
backtest.json here
Error (if applicable)
Platform Info
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: