Last active
March 14, 2020 22:47
-
-
Save ranaroussi/d886145bde5545e63d7a9eacbd150a1f to your computer and use it in GitHub Desktop.
Tradologics - example algo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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