-
Notifications
You must be signed in to change notification settings - Fork 6
/
mm2_tui.py
executable file
·140 lines (132 loc) · 5.95 KB
/
mm2_tui.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
#!/usr/bin/env python3
import os
import sys
import json
import time
import requests
import subprocess
from os.path import expanduser
from lib import rpclib, tuilib, coinslib, binance_api
# Get and set config
cwd = os.getcwd()
script_path = sys.path[0]
home = expanduser("~")
header = "\
_ _ _____ ________ __ \n\
/\ | | (_) | __ \| ____\ \ / / \n\
/ \ | |_ ___ _ __ ___ _ ___| | | | |__ \ V / \n\
/ /\ \| __/ _ \| '_ ` _ \| |/ __| | | | __| > < \n\
/ ____ \ || (_) | | | | | | | (__| |__| | |____ / . \ \n\
/_/ \_\__\___/|_| |_| |_|_|\___|_____/|______/_/ \_\ \n\
\n"
author = '{:^65}'.format('Welcome to the AtomicDEX TUI v0.2 by Thorn Mennet')
no_params_list = ["Start MarketMaker 2"]
def main():
try:
with open(script_path+"/MM2.json") as j:
mm2json = json.load(j)
gui = mm2json['gui']
netid = mm2json['netid']
passphrase = mm2json['passphrase']
userpass = mm2json['rpc_password']
rpc_password = mm2json['rpc_password']
local_ip = "http://127.0.0.1:7783"
MM2_json_exists = True
except:
MM2_json_exists = False
pass
while True:
os.system('clear')
print(tuilib.colorize(header, 'lightgreen'))
print(tuilib.colorize(author, 'cyan'))
menuItems = []
if not MM2_json_exists:
print(tuilib.colorize("No MM2.json file!", 'red'))
menuItems.append({"Setup MM2.json file": tuilib.create_MM2_json})
else:
status = rpclib.get_status(local_ip, userpass)
print('{:^84}'.format(status[0]))
num_orders = status[4]
if status[1]:
swaps_info = tuilib.swaps_info(local_ip, userpass)
num_swaps = swaps_info[1]
num_finished = swaps_info[2]
num_failed = swaps_info[3]
num_in_progress = swaps_info[4]
print(tuilib.colorize('{:^68}'.format("[Total swaps: "+str(num_swaps)+"] [Failed swaps: "+str(num_failed)+"] [In Progress: "+str(num_in_progress)+"] "), 'orange'))
print(tuilib.colorize('{:^68}'.format("[You have "+str(num_orders)+" orders active in the orderbook]"), 'orange'))
if len(sys.argv) > 1:
if sys.argv[1] == 'runbot':
tuilib.run_tradebot(local_ip, userpass)
# Build Menu
if status[1] is False:
menuItems.append({"Start MarketMaker 2": tuilib.start_mm2})
else:
menuItems.append({"Stop MarketMaker 2": tuilib.stop_mm2})
if status[2] is False:
menuItems.append({"Activate coins": tuilib.activate_all})
if len(status[3]) > 0:
menuItems.append({"View/withdraw balances": tuilib.show_balances_table})
menuItems.append({"View/buy from orderbook": tuilib.show_orderbook_pair})
menuItems.append({"View/cancel my orders": tuilib.show_orders_table})
menuItems.append({"View swaps in progress": tuilib.show_pending_swaps})
menuItems.append({"Review recent swaps": tuilib.show_recent_swaps})
menuItems.append({"Review failed swaps": tuilib.show_failed_swaps})
menuItems.append({"Recover stuck swap": tuilib.recover_swap})
if binance_api.api_key != '':
menuItems.append({"Run Tradebot": tuilib.run_tradebot})
if binance_api.api_key != '':
menuItems.append({"View Binance Account Info (needs valid API keys)": tuilib.binance_account_info})
menuItems.append({"Exit TUI": tuilib.exit})
print("\n")
for item in menuItems:
print(tuilib.colorize("[" + str(menuItems.index(item)) + "] ", 'blue') + tuilib.colorize(list(item.keys())[0],'blue'))
choice = input(tuilib.colorize("Select menu option: ", 'orange'))
try:
if int(choice) < 0:
raise ValueError
# Call the matching function
if list(menuItems[int(choice)].keys())[0] == "Setup MM2.json file":
list(menuItems[int(choice)].values())[0]()
try:
with open(script_path+"/MM2.json") as j:
mm2json = json.load(j)
gui = mm2json['gui']
netid = mm2json['netid']
passphrase = mm2json['passphrase']
userpass = mm2json['rpc_password']
rpc_password = mm2json['rpc_password']
local_ip = "http://127.0.0.1:7783"
MM2_json_exists = True
except:
input(colorize("Error in MM2.json file! See MM2_example.json for a valid example..."))
MM2_json_exists = False
pass
elif list(menuItems[int(choice)].keys())[0] in no_params_list:
list(menuItems[int(choice)].values())[0]()
elif list(menuItems[int(choice)].keys())[0].find('Menu') != -1:
submenu(list(menuItems[int(choice)].values())[0])
else:
list(menuItems[int(choice)].values())[0](local_ip, userpass)
except (ValueError, IndexError):
pass
if __name__ == "__main__":
while True:
os.system('clear')
print("\n\n")
with (open("lib/logo.txt", "r")) as logo:
for line in logo:
parts = line.split(' ')
row = ''
for part in parts:
if part.find('.') == -1:
row += tuilib.colorize(part, 'blue')
else:
row += tuilib.colorize(part, 'black')
print(row, end='')
#print(line, end='')
time.sleep(0.04)
time.sleep(0.4)
print("\n")
break
main()