-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcli.py
90 lines (81 loc) · 3.58 KB
/
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
import terra_sdk
import sys
from src.trading_core import get_bluna_for_luna_price, get_luna_for_bluna_price, buy, sell
from src.helpers import create_params, info, create_terra, create_wallet, warn, from_u_unit, get_arg_safe
from src import bot, const
def main():
with open("files/greeting.txt") as f:
content = f.read()
print(content)
params, terra, wallet = setup()
while True:
inp = input(' 👽 >>> ').strip()
split = inp.split()
if not len(split):
continue
command = split[0]
args = split[1:]
if command == 'quit':
terra.session.close()
break
try:
if command == 'price':
return_amount, price = get_bluna_for_luna_price(terra, params)
info("returned for {} Luna: {} bLuna, price: {}".format(params.amount_luna, from_u_unit(return_amount), price))
return_amount, price = get_luna_for_bluna_price(terra, params)
info("returned for {} bLuna: {} Luna, inv price: {}, price: {}".format(params.amount_bluna, from_u_unit(return_amount), 1 / price, price))
elif command == 'amount-luna':
amount_luna = get_arg_safe(args)
if amount_luna:
params.amount_luna = float(amount_luna)
info("amount for selling Luna set to {}".format(params.amount_luna))
elif command == 'amount-bluna':
amount_luna = get_arg_safe(args)
if amount_luna:
params.amount_bluna = float(amount_luna)
info("amount for selling bLuna set to {}".format(params.amount_bluna))
elif command == 'inv-sell-price':
inv_sell_price = get_arg_safe(args)
if inv_sell_price:
params.inv_sell_price = float(inv_sell_price)
info("price for selling bLuna set to {}".format(params.inv_sell_price))
elif command == 'buy-price':
buy_price = get_arg_safe(args)
if buy_price:
params.buy_price = float(buy_price)
info("price for buying bLuna set to {}".format(params.buy_price))
elif command == 'spread':
spread = get_arg_safe(args)
if spread:
params.spread = float(spread)
info("max spread set to {}".format(params.spread))
elif command == 'bot':
bot.run(params, terra, wallet)
elif command == 'mode-buy':
params.mode = const.buy
info("set mode to buy ({})".format(params.mode))
elif command == 'mode-sell':
params.mode = const.sell
info("set mode to sell ({})".format(params.mode))
elif command == 'buy':
_, price = get_bluna_for_luna_price(terra, params)
buy(params, terra, price, wallet)
elif command == 'sell':
_, price = get_luna_for_bluna_price(terra, params)
sell(params, terra, price, wallet)
else:
info('Invalid Command.')
except terra_sdk.exceptions.LCDResponseError as e:
warn(str(e))
def setup(is_bot=False):
params = create_params(is_bot)
terra = create_terra()
wallet = create_wallet(terra)
return params, terra, wallet
if __name__ == "__main__":
args = sys.argv
if len(args) > 1 and args[1] == 'bot':
params, terra, wallet = setup(True)
bot.run(params, terra, wallet)
else:
main()