-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinance_cli.py
248 lines (215 loc) · 8.25 KB
/
binance_cli.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import binance_spot
import binance_usdt_futures
import threading
import binance_order_overview
import colorama
from colorama import Fore
colorama.init(autoreset=True)
def get_all_running_threads():
if len(threading.enumerate()) == 1:
print(Fore.LIGHTYELLOW_EX + "No running proceses")
else:
print(Fore.LIGHTYELLOW_EX + "Current running processes:")
for thread in threading.enumerate():
if thread.name != "MainThread":
print(thread.name)
def binance_spot_cli(account, color):
client = binance_spot.auth(account=account)
exit = False
while not exit:
print("\n")
print(Fore.LIGHTYELLOW_EX + "What do you want to do:"
"\n 1 >> display positions"
"\n 2 >> market orders"
"\n 3 >> limit orders"
"\n 4 >> limits at bid/ask"
"\n 5 >> TWAPS"
"\n 0 >> exit - Binance SPOT"
"\n 99 >> restart client"
"\n 999 >> check current running processes")
try:
mode = int(input(color + "input number >>> "))
except:
print(color +"input must be number")
mode = 0
if mode == 0:
exit = True
print(color + f"Binance SPOT - closing")
elif mode == 1:
binance_spot.get_spot_balances(client, display=True)
elif mode == 2:
print("\n")
print(color +"Market order mode selected >> options:"
"\n 1 >> market order by $ amount"
"\n 2 >> market order by acc %")
try:
order_mode = int(input(color + "input number >>> "))
except:
print(color + "input must be number")
order_mode = 0
if order_mode == 1:
binance_spot.set_market_order_usd(client)
elif order_mode == 2:
binance_spot.set_market_order_pct(client)
print("\n")
elif mode == 3:
print("\n")
print(color + "Limit order mode selected >> options:"
"\n 1 >> limit orders between 2 prices by $ amount"
"\n 2 >> limit orders between 2 prices by account %"
)
try:
order_mode = int(input(color + "input number >>> "))
except:
print(color + "input must be number")
order_mode = 0
if order_mode == 1:
binance_spot.set_limit_orders_usd(client)
elif order_mode == 2:
binance_spot.set_limit_orders_pct(client)
print("\n")
elif mode == 4:
print("\n")
print(color + "Limit order mode selected >> options:"
"\n 1 >> limit orders by $ amount"
"\n 2 >> limit orders by account %"
)
try:
order_mode = int(input(color + "input number >>> "))
except:
print(color + "input must be number")
order_mode = 0
if order_mode == 1:
binance_spot.set_limit_orders_usd_bidask(client)
elif order_mode == 2:
binance_spot.set_limit_orders_pct_bid_ask(client)
elif mode == 5:
print("\n")
print(color + "TWAP mode selected >> options:"
"\n 1 >> linear twap by $ amount"
"\n 2 >> linear twap by account %")
try:
order_mode = int(input(color +"input number >>> "))
except:
print(color + "input must be number")
order_mode = 0
if order_mode == 1:
binance_spot.set_linear_twap_usd(client)
elif order_mode == 2:
binance_spot.set_linear_twap_pct(client)
elif mode == 999:
print("\n")
get_all_running_threads()
print("\n")
elif mode == 99:
print(color + "Reconnecting client")
client = binance_spot.auth(account=account)
print("\n")
def binance_futures_cli(account, color):
client = binance_usdt_futures.auth(account=account)
exit = False
while not exit:
print("\n")
print(color + "What do you want to do:"
"\n 1 >> display positions"
"\n 2 >> open position"
"\n 3 >> close/reduce position"
"\n 4 >> modify tp/sl"
"\n 0 >> exit - Binance Futures"
"\n 99 >> restart client"
"\n 999 >> check current running processes")
try:
mode = int(input(color + "input number >>> "))
except:
print(color +"input must be number")
mode = 0
if mode == 0:
exit = True
print(color + f"Binance Futures - closing")
elif mode == 1:
binance_usdt_futures.get_open_positions(client, display=True)
elif mode == 2:
print("\n")
print(color +"Open position mode selected >> options:"
"\n 1 >> market orders"
"\n 2 >> limit orders"
"\n 3 >> limits at bid/ask"
"\n 4 >> TWAPS")
try:
order_mode = int(input(color +"input number >>> "))
except:
print(color +"input must be number")
order_mode = 0
if order_mode == 1:
binance_usdt_futures.set_market_order_open(client)
elif order_mode == 2:
binance_usdt_futures.set_limits_open(client)
elif order_mode == 3:
binance_usdt_futures.set_limits_at_bidask_open(client)
elif order_mode == 4:
binance_usdt_futures.set_linear_twap_open(client)
elif mode == 3:
print("\n")
print(color +"Close / reduce position mode selected >> options:"
"\n 1 >> market orders"
"\n 2 >> limit orders"
"\n 3 >> limits at bid/ask"
"\n 4 >> TWAPS"
"\n 5 >> close all positions")
try:
order_mode = int(input(color +"input number >>> "))
except:
print(color +"input must be number")
order_mode = 0
if order_mode == 1:
binance_usdt_futures.set_market_order_close(client)
elif order_mode == 2:
binance_usdt_futures.set_limits_close(client)
elif order_mode == 3:
binance_usdt_futures.set_limits_at_bidask_close(client)
elif order_mode == 4:
binance_usdt_futures.set_linear_twap_close(client)
elif order_mode == 5:
binance_usdt_futures.close_all_positions(client)
elif mode == 4:
binance_usdt_futures.set_position_sl_tp(client)
elif mode == 999:
print("\n")
get_all_running_threads()
print("\n")
elif mode == 99:
print(color + "Reconnecting client")
client = binance_spot.auth(account=account)
print("\n")
def main():
exit = False
while not exit:
print("\n")
print(Fore.LIGHTYELLOW_EX + "Select account:"
"\n 1 >> Binance SPOT - personal"
"\n 2 >> Binance USDT perps - personal"
"\n 3 >> Order Overview"
"\n 999 >> check current running processes"
"\n 0 >> exit terminal")
mode = int(input(Fore.LIGHTYELLOW_EX + "input number >>> "))
if mode == 0:
exit = True
print("\n")
print(Fore.LIGHTYELLOW_EX + "Terminal closing")
elif mode == 999:
print("\n")
get_all_running_threads()
print("\n")
elif mode == 1:
print("\n")
color = Fore.LIGHTYELLOW_EX
binance_spot_cli(account="personal", color=color)
elif mode == 2:
print("\n")
color = Fore.LIGHTYELLOW_EX
binance_futures_cli(account="personal", color=color)
elif mode == 3:
print("\n")
binance_order_overview.Order_overview()
if __name__ == "__main__":
main()