-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
executable file
·164 lines (138 loc) · 5.09 KB
/
bot.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import time
import argparse
from orders.mirror_orders import *
from technical_analysis.moving_averages import *
from utils.log_utils import *
class TradingBot:
def __init__(
self,
coin="BTC",
stable_coin="USDT",
budget=2000.0,
gain_percentage=0.2,
loss_percentage=0.05,
):
self.coin = coin
self.stable_coin = stable_coin
self.budget = budget
self.gain_percentage = gain_percentage
self.loss_percentage = loss_percentage
def run(self):
coin = self.coin
stable_coin = self.stable_coin
market_pair = "{}/{}".format(coin, stable_coin)
stable_coin_balance = self.budget
coin_balance = 0.0
sell_order = None
incrementor = 0
fixed_balance = stable_coin_balance / get_price_by_coin_pair(pair=market_pair)
while True:
if incrementor == 18:
incrementor = 0
current_price = get_price_by_coin_pair(pair=market_pair)
if sell_order is not None:
diff = " | SELL LIMIT ORDER DIFF: ({}%)".format(
str(round((current_price - sell_order['initial_buy_price'])/sell_order['initial_buy_price']*100, 2))
)
else:
diff = ""
log_entry(
coin=coin,
stable_coin=stable_coin,
current_price=current_price,
diff=diff,
coin_balance=coin_balance,
stable_coin_balance=stable_coin_balance
)
print("HODL BALANCE = {} USDT".format(fixed_balance*current_price))
if sell_order is not None:
print("CHECKING SELL LIMIT ORDER")
sell_order, sell_output = sell_limit_order(
sell_order,
stable_coin_balance,
coin_balance,
pair=market_pair
)
if sell_order is None:
time.sleep(30)
sell_price, stable_coin_balance, coin_balance = sell_output
if incrementor % 18 == 0:
candle_sticks = fetch_olhcv_candles_dataframe(
symol="BNB/USDT",
timeframe="3m",
limit=50,
emas=[7, 20, 50]
)
uptrend = is_indicator_on_uptrend(
candle_sticks,
emas=[7, 20, 50],
steps=5,
plot=False
)
momentum_up = is_ema_picking_momentum(
candle_sticks,
emas=[7, 20, 50]
)
momentum_down = is_ema_losing_momentum(
candle_sticks,
emas=[7, 20, 50]
)
if uptrend and momentum_up:
buy_price, stable_coin_balance, coin_balance = buy_market(
stable_coin_amount=stable_coin_balance,
stable_coin_balance=stable_coin_balance,
coin_balance=coin_balance,
pair=market_pair
)
if sell_order is None and buy_price is not None:
sell_order = open_sell_limit_order(
buy_price,
gain_percentage=self.gain_percentage,
loss_percentage=self.loss_percentage
)
if not uptrend and momentum_down:
_, stable_coin_balance, coin_balance = sell_market(
coin_amount=coin_balance,
stable_coin_balance=stable_coin_balance,
coin_balance=coin_balance,
pair=market_pair
)
time.sleep(3)
incrementor += 1
if __name__ == '__main__':
log_bot_version(version="Alpha 1.0.0")
parser = argparse.ArgumentParser(description='Signarly TradingBot Command Line.')
parser.add_argument(
'--coin',
default='BTC',
help='Select the cryptocurrency you want to trade.'
)
parser.add_argument(
'--stable-coin',
default='USDT',
help='Select the stable coin you want to trade against.'
)
parser.add_argument(
'--budget',
default=2000.0,
help='Select the budget you want to start with.'
)
parser.add_argument(
'--gain_percentage',
default=0.2,
help='Select the price percentage increase above which you want the bot to cash out.'
)
parser.add_argument(
'--loss_percentage',
default=0.05,
help='Select the price percentage decrease below which you want the bot to cut losses.'
)
args = parser.parse_args()
bot = TradingBot(
coin=args.coin,
stable_coin=args.stable_coin,
budget=float(args.budget),
gain_percentage=float(args.gain_percentage),
loss_percentage=float(args.loss_percentage)
)
bot.run()