-
Notifications
You must be signed in to change notification settings - Fork 1
/
live_trader.py
96 lines (74 loc) · 2.34 KB
/
live_trader.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/python3.5
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 26 20:54:30 2017
@author: Avanti Financial Services
"""
from core.strategies_gdax import Strategy
from core.libraries.websocket_thread import ConnectThread
from core.GDAX_data_feeder import GDAXWebSocketClient
from core.libraries.gdax_auth import Authentication
from core.trader import GDAXTrader
class CustomStrategy(Strategy):
def on_tick(self):
pass
def on_minute_bar(self):
"""
self.get_timeframe(5)
could be 5, 10, 15... N minutes
returns a dataframe with the timeframe specified
self.trader.list_accounts()
returns the account balance dict
"""
print('{}: o={}, h={}, l={}, c={}, v={}'.format(
self.main_df.index[-1],
self.main_df['open'][-1],
self.main_df['high'][-1],
self.main_df['low'][-1],
self.main_df['close'][-1],
self.main_df['volume'][-1]))
print('\nNew minute bar')
def on_bar(self):
"""
Main methods you can use.
self.vstop
self.get_timeframe()
self.trader.place_order()
self.trader.close_last_order()
"""
if __name__ == "__main__":
# User Variables.
API_KEY = ''
API_PASS = ''
API_SECRET = ''
product = "BTC-USD"
ATR_period = 14
timeframe = 5
VStop_multiplier = 3
data_days = 1
# Authentication
auth = Authentication(API_KEY, API_SECRET, API_PASS)
request = {"type": "subscribe",
"channels": [{"name": "full", "product_ids": [product]}]}
request.update(auth.get_dict()) # comment this for no auth
# Setting data feeder.
ws = GDAXWebSocketClient(request, [product])
connectThread = ConnectThread(ws)
connectThread.setDaemon(False)
# Setting strategy and subscribing to data channels.
parameters = {
'pairs': product,
'ATR-Period': ATR_period,
'vstop timeframe': timeframe,
'vstop multiplier': VStop_multiplier,
'data days': data_days}
strategy = CustomStrategy(**parameters)
for c in [product]:
ws.pub.register(c, strategy)
# Setting trader.
trader = GDAXTrader(auth=auth)
strategy.trader = trader
# Shows data of every wallet
# print(trader.list_accounts())
# Start connection.
connectThread.start()