forked from javifalces/tradingFramework
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dumbAlgo.py
45 lines (33 loc) · 1.13 KB
/
dumbAlgo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# strategy.py
from qtpylib.algo import Algo
class DumbAlgo(Algo):
def on_start(self):
# optional method that gets called once upon start
pass
def on_fill(self, instrument, order):
# optional method that gets called on every order fill
pass
def on_orderbook(self, instrument):
# optional method that gets called on every orderbook change
pass
def on_quote(self, instrument):
# optional method that gets called on every quote change
pass
def on_tick(self, instrument):
# optional method that gets called on every tick received
pass
def on_bar(self, instrument):
# optional method that gets called on every bar received
# buy if position = 0, sell if in position > 0
if instrument.positions['position'] == 0:
instrument.buy(100)
else:
instrument.exit()
if __name__ == "__main__":
# initialize the algo
strategy = DumbAlgo(
instruments=["AAPL"],
resolution="1T" # 1Min bar resolution (Pandas "resample" resolutions)
)
# run the algo
strategy.run()