-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathoanda_order_data.py
63 lines (53 loc) · 1.51 KB
/
oanda_order_data.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import backtrader as bt
import btoandav20 as bto
import json
''' Order info '''
class St(bt.Strategy):
def __init__(self):
self.order = None
self.mybuysignals = {
"buysignal1": False,
"buysignal2": False,
"buysignal3": False,
"buysignal4": True,
"buysignal5": False,
}
def notify_store(self, msg, *args, **kwargs):
if "clientExtensions" in msg:
o_info = json.loads(msg["clientExtensions"]["comment"])
buytrigger = o_info["buytrigger"]
def next(self):
if self.order:
return
for k, v in self.mybuysignals.items():
if v:
self.order = self.buy(
size=1,
buytrigger=k
)
with open("config.json", "r") as file:
config = json.load(file)
storekwargs = dict(
token=config["oanda"]["token"],
account=config["oanda"]["account"],
practice=config["oanda"]["practice"],
notif_transactions=True,
stream_timeout=10,
)
store = bto.stores.OandaV20Store(**storekwargs)
datakwargs = dict(
timeframe=bt.TimeFrame.Minutes,
compression=1,
tz='Europe/Berlin',
backfill=False,
backfill_start=False,
)
data = store.getdata(dataname="EUR_USD", **datakwargs)
data.resample(
timeframe=bt.TimeFrame.Minutes,
compression=1) # rightedge=True, boundoff=1)
cerebro = bt.Cerebro()
cerebro.adddata(data)
cerebro.setbroker(store.getbroker())
cerebro.addstrategy(St)
cerebro.run()