-
Notifications
You must be signed in to change notification settings - Fork 2
/
RunBOT.py
57 lines (46 loc) · 2.32 KB
/
RunBOT.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
import Config
import json
import websocket
from binance.client import Client
from MainStrategy import AlgorithmTrading
# ---------------------------------------- Set Your Trading Parameters -----------------------------------------------
# Declare your Binance API connection keys:
API_Keys = Config.api_keys('test')
# Please set the algorithm Status: Live or Test
Live = False
# Please select your trading style: 'Day_Trading' or 'Swing_Trading' or 'Position_Trading'
Trading_Style = 'Day_Trading'
# Please choose your trading symbol, order size (proportion of you balance) and set the period of RSI indicator
Trade_Symbol = "ALGOUSDT"
Order_Size = 1
RSI_PERIOD = 7
# Socket Functions ----------------------------------------------------------------------------------------------------
class RunBot:
def __init__(self, mainkey, secretkey, live, trading_style, trade_symbol, order_size, rsi_period):
self.Live = live
self.Trading_Style = trading_style
self.Trade_Symbol = trade_symbol
self.Order_Size = order_size
self.Rsi_Period = rsi_period
self.Binance_Client = Client(mainkey, secretkey)
print("logged In")
self.AT = AlgorithmTrading(mainkey, secretkey, self.Live, self.Trade_Symbol, self.Order_Size)
self.SOCKET_miniTicker = "wss://stream.binance.com:9443/ws/{}@miniTicker".format(self.Trade_Symbol.lower())
WS = websocket.WebSocketApp(self.SOCKET_miniTicker, on_open=self.on_open,
on_close=self.on_close, on_message=self.on_message)
WS.run_forever()
def on_open(self, ws):
print('Opened connection')
def on_close(self, ws):
print('Closed connection')
WS = websocket.WebSocketApp(self.SOCKET_miniTicker, on_open=self.on_open,
on_close=self.on_close, on_message=self.on_message)
WS.run_forever()
def on_message(self, ws, message):
Listen_Key = self.Binance_Client.stream_get_listen_key()
self.Binance_Client.stream_keepalive(Listen_Key)
json_message = json.loads(message)
Mark_Price = float(json_message['c'])
self.AT.rsi_strategy(self.Trading_Style, self.Rsi_Period, Mark_Price)
if __name__ == "__main__":
RunBot(API_Keys['key'], API_Keys['secret'], Live, Trading_Style, Trade_Symbol, Order_Size, RSI_PERIOD)