Skip to content

Instantly share code, notes, and snippets.

@ranaroussi
Last active March 14, 2020 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ranaroussi/d886145bde5545e63d7a9eacbd150a1f to your computer and use it in GitHub Desktop.
Save ranaroussi/d886145bde5545e63d7a9eacbd150a1f to your computer and use it in GitHub Desktop.
Tradologics - example algo
# mycode.py
import tradologics
def tradehook(payload):
payload = tradologics.parse(payload)
# is this a "data" payload?
if payload.event == "data":
for asset in payload.data:
sma10 = asset.close.rolling(10).mean()
sma50 = asset.close.rolling(50).mean()
# buy signal ?
if sma10 > sma50 and # algo rule
asset.last > asset.prev_close and # gap up
data.positions[asset.id] <= 0: # not in short position already
tradologics.submit_order(
asset=asset.id,
qty=100,
kind="market",
side="buy",
time_in_force="opg",
accountId="my-ib-account",
strategy="my amazing strategy"
)
# sell signal ?
if sma10 < sma50 and # algo rule
asset.last < asset.prev_close and # gap down
data.positions[asset.id] >= 0: # not in short position already
tradologics.submit_order(
asset=asset.id,
qty=100,
kind="market",
side="buy",
time_in_force="opg",
accountId="my-ib-account",
strategy="my amazing strategy"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment