-
Notifications
You must be signed in to change notification settings - Fork 3
/
trading.py
60 lines (44 loc) · 1.52 KB
/
trading.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
import queue
import threading
import time
from settings import ACCESS_TOKEN, ACCOUNT_ID, DOMAIN
from execution import OANDAExecutionHandler
from streaming import StreamingForexPrices
from portfolio import PortfolioRemote
from timeseries import TimeSeries
from manager import Manager
from strategy.ols_time import OLSTIME
from strategy.sma2 import SMA2
from strategy.sma_pip import SMAPIP
from strategy.sma_bol_pip_rsi import SMABOLPIPRSI
from strategy.martin2_rsi import MARTIN2RSI
heartbeat = 0.5
def on_tick(events, manager):
while True:
try:
event = events.get(False)
except queue.Empty:
pass
else:
manager.perform_trade(event)
manager.portfolio.show_current_status(event)
time.sleep(heartbeat)
if __name__ == "__main__":
events = queue.Queue()
price_src = StreamingForexPrices(environment=DOMAIN,
access_token=ACCESS_TOKEN)
status = dict()
status["is_sim"] = False
portfolio = PortfolioRemote(status)
execution = OANDAExecutionHandler(status)
strategy = OLSTIME(status)
timeseries = TimeSeries(status)
manager = Manager(status, events, execution,
portfolio, strategy, timeseries)
trade_thread = threading.Thread(target=on_tick,
args=[events, manager])
price_thread = threading.Thread(target=price_src.begin, args=[
ACCOUNT_ID, "EUR_USD", events
])
trade_thread.start()
price_thread.start()