Skip to content

Instantly share code, notes, and snippets.

@elja
Created October 17, 2022 09:43
Show Gist options
  • Save elja/a89b7de609dd562aa9fbc950d93e77b4 to your computer and use it in GitHub Desktop.
Save elja/a89b7de609dd562aa9fbc950d93e77b4 to your computer and use it in GitHub Desktop.
def initialize(state):
pass
@schedule(interval="6h", symbol="BTCUSDT")
def handler(state, data):
'''
1) Compute indicators from data and add parameters into strategy
'''
ema_short = data.ema(20).last
ema_long = data.ema(50).last
'''
2) Fetch position for symbol
'''
position = query_open_position_by_symbol(data.symbol,include_dust=False)
has_position = position is not None
'''
4) Resolve buy or sell signals
'''
if ema_short > ema_long and not has_position:
order_market_target(symbol=data.symbol, target_percent=0.8)
elif ema_short < ema_long and has_position:
close_position(data.symbol)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment