-
Notifications
You must be signed in to change notification settings - Fork 52
/
trader.py
30 lines (25 loc) · 955 Bytes
/
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
class Trader():
def __init__(self, client, strategy, money_to_trade=100, leverage=5):
self.client = client
self.strategy = strategy
self.money_to_trade = money_to_trade
self.leverage = leverage
def execute_trade(self):
prediction = self.strategy.predict()
print(f"Last prediction: {prediction}")
try:
if prediction == -1:
response = self.client.Order.Order_new(
symbol="XBTUSD",
side="Sell",
orderQty=self.money_to_trade * self.leverage,
).result()
if prediction == 1:
response = self.client.Order.Order_new(
symbol="XBTUSD",
side="Buy",
orderQty=self.money_to_trade * self.leverage,
).result()
except Exception:
print("Something goes wrong!")
return