878 lines
43 KiB
Python
878 lines
43 KiB
Python
import requests
|
|
import sys
|
|
import json
|
|
import credentials
|
|
|
|
try:
|
|
earn_api_key = credentials.get_credentials("earn_api_key")["key"]
|
|
if sys.argv[1]=="--testnet":
|
|
is_testnet = True
|
|
string_to_add = "TESTNET "
|
|
api_key = credentials.get_credentials("testnet_api_key")["key"]
|
|
base_url = credentials.get_url("testnet") #type: ignore
|
|
exchanges = {"Binance":"/binance"}
|
|
elif sys.argv[1]=="--mainnet":
|
|
is_testnet = False
|
|
string_to_add = "MAINNET "
|
|
api_key = credentials.get_credentials("mainnet_api_key")["key"]
|
|
base_url = credentials.get_url("mainnet") #type: ignore
|
|
exchanges = {"binance":"/binance", "gate.io":"/gateio", "kucoin":"/kucoin", "okx":"/okex"}
|
|
else:
|
|
print(f"Unrecognized parameter {sys.argv[1]}")
|
|
sys.exit()
|
|
except Exception as e:
|
|
print(e)
|
|
sys.exit()
|
|
|
|
headers = {'X-API-KEY': api_key}
|
|
|
|
earn_headers = {'X-API-KEY': earn_api_key}
|
|
|
|
command_list = f'''{string_to_add}COMMANDS:
|
|
|
|
INSTANCE
|
|
1) global_status 2) missing_pairs 3) server_time
|
|
4) trader_time 5) toggle_restart 6) toggle_telegram
|
|
7) mod_global_tp_level 8) global_last_call 9) edit_loop_wait_time
|
|
10) edit_call_wait_time 11) reload_markets 12) fetch_full_log
|
|
13) paused_traders 14) fetch_log 15) edit_cooldown_multiplier
|
|
16) get_balance 17) cancel_global_last_call
|
|
18) mod_default_order_size
|
|
|
|
EARN
|
|
31) toggle_pause 32) get_step_size 33) set_step_size
|
|
34) get_percentage 35) set_percentage 36) get_time_between_subscriptions
|
|
37) set_time_between_subscriptions 38) get_time_between_redemptions
|
|
39) set_time_between_redemptions 40) get_minimum_amount_in_trading_account
|
|
41) set_minimum_amount_in_trading_account 42) get_last_subscription
|
|
43) get_last_redemption 44) get_total_balance
|
|
45) get_global_status 46) subscribe 47) redeem
|
|
|
|
TRADERS
|
|
51) worker_status 52) get_all_worker_status
|
|
53) add_pair 54) remove_pair 55) restart_pair
|
|
56) import_pair 57) switch_to_short 58) switch_to_long
|
|
59) load_old_long 60) add_so 61) add_quote
|
|
62) mod_tp_level 63) last_call 64) deferred_last_call
|
|
65) toggle_pause 66) toggle_cleanup 67) toggle_autoswitch
|
|
68) toggle_check_old_long_price 69) switch_quote_currency
|
|
70) reload_safety_order 71) view_old_long 72) switch_price
|
|
73) reload_trader_config 74) toggle_liquidate_after_switch
|
|
75) base_add_calculation
|
|
|
|
98) Change broker 99) Exit
|
|
'''
|
|
|
|
def validate_pair(trading_pair):
|
|
return "/" in trading_pair and len(trading_pair)>3
|
|
|
|
def validate_float_or_int(number):
|
|
'''
|
|
Validates if the number can be interpreted as a float or an int
|
|
'''
|
|
try:
|
|
number = str(float(number))
|
|
return True
|
|
except Exception:
|
|
return False
|
|
|
|
def validate_int(number):
|
|
'''
|
|
Validates if the number can be interpreted as an integer
|
|
'''
|
|
try:
|
|
new_number = int(number)
|
|
if str(new_number) == str(number):
|
|
return True
|
|
return False
|
|
except Exception:
|
|
return False
|
|
|
|
def select_exchange(exchanges):
|
|
'''
|
|
Selects the exchange to use
|
|
'''
|
|
|
|
while True:
|
|
selection = input("Enter exchange: (Binance, Gate.io, KuCoin, OKX) ").lower()
|
|
for item in exchanges:
|
|
if selection in item.lower():
|
|
return item
|
|
print("Invalid input")
|
|
|
|
|
|
if __name__=="__main__":
|
|
|
|
if len(exchanges)==1:
|
|
selection = list(exchanges.keys())[0]
|
|
else:
|
|
selection = select_exchange(exchanges)
|
|
#selection = input("Enter exchange: (Binance, Gate.io, KuCoin, OKX) ").lower()
|
|
#for item in exchanges:
|
|
# if selection in item.lower():
|
|
# selection = item
|
|
# break
|
|
#print("Invalid input")
|
|
#sys.exit()
|
|
port = exchanges[selection]
|
|
earn_broker = port[1:]
|
|
if earn_broker=="okex":
|
|
earn_broker="okx"
|
|
|
|
|
|
|
|
print("DCAv2 COMMANDER")
|
|
if not is_testnet:
|
|
print("WARNING: RUNNING ON MAINNET")
|
|
|
|
while True:
|
|
print("="*80)
|
|
print(f"Exchange: {selection}")
|
|
print(command_list)
|
|
|
|
|
|
#When entering the command, it shows a brief description and requests for parameters.
|
|
command = input("Your input: ")
|
|
|
|
try:
|
|
command = int(command)
|
|
except Exception as e:
|
|
print(e)
|
|
|
|
if command==99:
|
|
print("Goodbye")
|
|
sys.exit()
|
|
|
|
elif command==98:
|
|
#while True:
|
|
# selection = input("Enter exchange: (Binance, Gate.io, KuCoin, OKX) ").lower()
|
|
# if selection not in exchanges:
|
|
# print("Invalid input")
|
|
# port = exchanges[selection]
|
|
# break
|
|
selection = select_exchange(exchanges)
|
|
port = exchanges[selection]
|
|
earn_broker = port[1:]
|
|
if earn_broker=="okex":
|
|
earn_broker="okx"
|
|
print(f"New exchange selected: {selection}")
|
|
|
|
|
|
######################
|
|
###### INSTANCE ######
|
|
######################
|
|
|
|
elif command==1:
|
|
print("global_status returns a dictionary of the global status of the instance")
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/global_status"
|
|
print(json.loads(requests.get(url,headers=headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==2:
|
|
print("missing_pairs returns a list of pairs that are in the config file of the instance")
|
|
print("but are not running.")
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/missing_pairs"
|
|
print(json.loads(requests.get(url,headers=headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==3:
|
|
print("server_time returns the linux time of the server")
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/server_time"
|
|
print(json.loads(requests.get(url,headers=headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==4:
|
|
print("trader_time return the last time of the traders was active")
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/trader_time"
|
|
print(json.loads(requests.get(url,headers=headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==5:
|
|
print("toggle_restart controls if the instance will attempt to restart failed traders or not")
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/toggle_restart"
|
|
print(json.loads(requests.post(url, headers=headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==6:
|
|
print("toggle_telegram turns on or off the Telegram notifications")
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/toggle_telegram"
|
|
print(json.loads(requests.post(url, headers=headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==7:
|
|
print("mod_global_tp_level modifies the percentage of profit of all the traders")
|
|
print("Example: 1.02 is equal to 2% profit")
|
|
new_profit_level = input("Desired profit level: ")
|
|
if not validate_float_or_int(new_profit_level):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/mod_global_tp_level"
|
|
parameters = {"amount": new_profit_level}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==8:
|
|
print("global_last_call signals all traders to cease operation when profit is reached")
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/global_last_call"
|
|
print(json.loads(requests.post(url, headers=headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==9:
|
|
print("edit_loop_wait_time modifies the pause the instance takes after processing the open orders")
|
|
print("instance fetch the orders -> instance sends the orders to the traders ->")
|
|
print("instance waits for the traders to complete their tasks -> instance waits <loop_wait_time> seconds")
|
|
print(f"Current value is {None}")
|
|
print("The input value can be an integer or a float")
|
|
new_wait_time = input("Desired wait time: ")
|
|
if not validate_float_or_int(new_wait_time):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/edit_loop_wait_time"
|
|
parameters = {"wait_time": new_wait_time}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==10:
|
|
print("edit_call_wait_time modifies the pause that the traders take between some API calls")
|
|
print("This aims to reduce the load on the API endpoints of the broker.")
|
|
print("The input value can be an integer or a float")
|
|
print(f"Current value is {None}")
|
|
new_wait_time = input("Desired call wait time: ")
|
|
if not validate_float_or_int(new_wait_time):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/edit_call_wait_time"
|
|
parameters = {"wait_time": new_wait_time}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==11:
|
|
print("reload_markets forces CCXT to renew all the market information")
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/reload_markets"
|
|
print(json.loads(requests.post(url, headers=headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==12:
|
|
print("fetch_full_log displays the log of an instance.")
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}/statistics_server/fetch_full_log?exchange_name={port[1:]}&width={100}"
|
|
for item in json.loads(requests.get(url, headers=headers).content)["line"]:
|
|
print(item)
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==13:
|
|
print("paused_traders returns a list of paused traders.")
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/paused_traders"
|
|
print(json.loads(requests.get(url,headers=headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==14:
|
|
print("fetch_log displays the last n log entries of an instance.")
|
|
amount = input("Amount of lines? ")
|
|
if not validate_float_or_int(amount):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}/statistics_server/fetch_log?exchange_name={port[1:]}&width={100}&amount={amount}"
|
|
for item in json.loads(requests.get(url, headers=headers).content)["line"]:
|
|
print(item)
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==15:
|
|
print("edit_cooldown_multiplier modifies the pause's multiplier after it hits profit.")
|
|
print("This aims to reduce the volatility effect on the trader when there are big orderbook movements.")
|
|
print(f"Current value is {None}")
|
|
print("The input value can be an integer or a float")
|
|
new_multiplier = input("Desired multiplier: ")
|
|
if not validate_float_or_int(new_multiplier):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/edit_cooldown_multiplier"
|
|
parameters = {"cooldown_multiplier": new_multiplier}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==16:
|
|
print("Returns the free balance of a given coin")
|
|
coin = input("Input currency: ").upper()
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/get_balance?coin={coin}"
|
|
print(json.loads(requests.get(url,headers=headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==17:
|
|
print("cancel_global_last_call reverts global_last_call")
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/cancel_global_last_call"
|
|
print(json.loads(requests.post(url, headers=headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==18:
|
|
print("mod_default_order_size modifies the default order size that is used when creating a trader")
|
|
print(f"Current value is {None}")
|
|
print("The input value can be an integer or a float")
|
|
new_default_order_size = input("New default order size: ")
|
|
if not validate_float_or_int(new_default_order_size):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/mod_default_order_size"
|
|
parameters = {"amount": new_default_order_size}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
|
|
######################
|
|
######## EARN ########
|
|
######################
|
|
|
|
elif command==31:
|
|
print("toggle_pause interrupts or resume the subcription and redemption of funds")
|
|
if input(f"This will toggle the subscription and redemption of funds on {port}. Are you sure? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}/earn/toggle_pause"
|
|
parameters = {"broker": earn_broker}
|
|
print(json.loads(requests.post(url,headers=earn_headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==32:
|
|
print("get_step_size returns the step size")
|
|
url = f"{base_url}/earn/get_step_size?broker={earn_broker}"
|
|
print(json.loads(requests.get(url,headers=earn_headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==33:
|
|
print("set_step_size sets the step size")
|
|
new_step_size = input("New step size? ")
|
|
if not validate_float_or_int(new_step_size):
|
|
print("Invalid step size")
|
|
break
|
|
if input(f"This will set the step size to {new_step_size}. Are you sure? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}/earn/set_step_size"
|
|
parameters = {"broker": earn_broker, "new_step_size": new_step_size}
|
|
print(json.loads(requests.post(url,headers=earn_headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==34:
|
|
print("get_percentage displays the percentage of funds to be allocated to earn")
|
|
url = f"{base_url}/earn/get_percentage?broker={earn_broker}"
|
|
print(json.loads(requests.get(url,headers=earn_headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==35:
|
|
print("set_percentage sets the percentage of funds to be allocated to earn")
|
|
new_percentage = input("New percentage? ")
|
|
if not validate_float_or_int(new_percentage):
|
|
print("Invalid percentage")
|
|
break
|
|
if input(f"This will set the percentage to {new_percentage}. Are you sure? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}/earn/set_percentage"
|
|
parameters = {"broker": earn_broker, "new_percentage": new_percentage}
|
|
print(json.loads(requests.post(url,headers=earn_headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==36:
|
|
print("get_time_between_subscriptions displays the time to wait between subscriptions")
|
|
url = f"{base_url}/earn/get_time_between_subscriptions?broker={earn_broker}"
|
|
print(json.loads(requests.get(url,headers=earn_headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==37:
|
|
print("set_time_between_subscriptions sets the time to wait between subscriptions")
|
|
new_time_between_subscriptions = input("New time between subscriptions? ")
|
|
if not validate_int(new_time_between_subscriptions):
|
|
print("Invalid time")
|
|
break
|
|
if input(f"This will set the time to wait between subscriptions to {new_time_between_subscriptions}. Are you sure? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}/earn/set_time_between_subscriptions"
|
|
parameters = {"broker": earn_broker, "new_time_between_subscriptions": new_time_between_subscriptions}
|
|
print(json.loads(requests.post(url,headers=earn_headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==38:
|
|
print("get_time_between_redemptions displays the time to wait between redemptions")
|
|
url = f"{base_url}/earn/get_time_between_redemptions?broker={earn_broker}"
|
|
print(json.loads(requests.get(url,headers=earn_headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==39:
|
|
print("set_time_between_redemptions sets the time to wait between redemptions")
|
|
new_time_between_redemptions = input("New time between redemptions? ")
|
|
if not validate_int(new_time_between_redemptions):
|
|
print("Invalid time")
|
|
break
|
|
if input(f"This will set the time to wait between redemptions to {new_time_between_redemptions}. Are you sure? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}/earn/set_time_between_redemptions"
|
|
parameters = {"broker": earn_broker, "new_time_between_redemptions": new_time_between_redemptions}
|
|
print(json.loads(requests.post(url,headers=earn_headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==40:
|
|
print("get_minimum_amount_in_trading_account displays the minimum amount of funds that always have to exist in the trading account")
|
|
url = f"{base_url}/earn/get_minimum_amount_in_trading_account?broker={earn_broker}"
|
|
print(json.loads(requests.get(url,headers=earn_headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==41:
|
|
print("set_minimum_amount_in_trading_account sets the minimum amount of funds that always have to exist in the trading account")
|
|
new_minimum_amount_in_trading_account = input("New minimum amount in trading account? ")
|
|
if not validate_int(new_minimum_amount_in_trading_account):
|
|
print("Invalid amount")
|
|
break
|
|
if input(f"This will set the minimum amount of funds that always have to exist in the trading account to {new_minimum_amount_in_trading_account}. Are you sure? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}/earn/set_minimum_amount_in_trading_account"
|
|
parameters = {"broker": earn_broker, "new_minimum_amount_in_trading_account": new_minimum_amount_in_trading_account}
|
|
print(json.loads(requests.post(url,headers=earn_headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==42:
|
|
print("get_last_subscription display the last subscription")
|
|
url = f"{base_url}/earn/get_last_subscription?broker={earn_broker}"
|
|
print(json.loads(requests.get(url,headers=earn_headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==43:
|
|
print("get_last_redemptions displays the last redemption")
|
|
url = f"{base_url}/earn/get_last_redemption?broker={earn_broker}"
|
|
print(json.loads(requests.get(url,headers=earn_headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==44:
|
|
print("get_total_balance displays the trading account balance and the earning account balance")
|
|
url = f"{base_url}/earn/get_total_balance?broker={earn_broker}"
|
|
print(json.loads(requests.get(url,headers=earn_headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==45:
|
|
print("get_global_status returns the status of all the earners.")
|
|
url = f"{base_url}/earn/get_global_status"
|
|
print(json.loads(requests.get(url,headers=earn_headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==46:
|
|
print("subscribe forces funds subscription")
|
|
amount_to_subscribe = input("Enter the amount to subscribe: ")
|
|
if not validate_float_or_int(amount_to_subscribe):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}/earn/subscribe"
|
|
parameters = {
|
|
"broker": earn_broker,
|
|
"amount": amount_to_subscribe}
|
|
print(json.loads(requests.post(url,headers=earn_headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==47:
|
|
print("redeem forces funds redemption")
|
|
amount_to_redeem = input("Enter the amount to redeem: ")
|
|
if not validate_float_or_int(amount_to_redeem):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}/earn/redeem"
|
|
parameters = {
|
|
"broker": earn_broker,
|
|
"amount": amount_to_redeem}
|
|
print(json.loads(requests.post(url,headers=earn_headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
|
|
|
|
######################
|
|
####### TRADER #######
|
|
######################
|
|
|
|
elif command==51:
|
|
print("worker_status return the status dictionary of the trader")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
base,quote = trading_pair.split("/")
|
|
url = f"{base_url}{port}/worker_status?base={base}"e={quote}"
|
|
print(json.loads(requests.get(url,headers=headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==52:
|
|
print("get_all_worker_status returns a dictionary of all the status dictionaries of all active trader")
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/get_all_worker_status"
|
|
print(json.loads(requests.get(url,headers=headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==53:
|
|
print("add_pair add a trader to the instance.")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/add_pair"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==54:
|
|
print("remove_pair terminates a running trader from the instance.")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/remove_pair"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==55:
|
|
print("restart_pair terminates and restarts a trader from the instance.")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/restart_pair"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==56:
|
|
print("import_pair imports a trader to the instance.")
|
|
print("In order for the importing to be successful, a status file must exist in the status directory ")
|
|
print("and the take profit order must be open.")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
tp_id_input = input("Input take profit order id to use (if any)")
|
|
forced_tp_id = None if tp_id_input=="" else tp_id_input
|
|
so_id_input = input("Input safety order id to use (if any)")
|
|
forced_so_id = None if so_id_input=="" else so_id_input
|
|
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/import_pair"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote,
|
|
"forced_tp_id": forced_tp_id,
|
|
"forced_so_id": forced_so_id}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==57:
|
|
print("switch_to_short changes the mode of operation of a trader from long mode (the default one) to short mode.")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/switch_to_short"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==58:
|
|
print("switch_to_long changes the mode of operation of a trader from short mode to the default long mode")
|
|
print("It takes an extra parameter flag: 0 to ignore the profit calculation from the switch and 1 to do that calculation")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
calculation = input("Profit calculation? 0: ignore, 1: calculate ")
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if int(calculation) not in [0,1]:
|
|
print("The input for the calculation flag is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/switch_to_long"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote,
|
|
"calculate_profits": calculation}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==59:
|
|
print("load_old_long load to the status dictionary the contents of an old_long file")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/load_old_long"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==60:
|
|
print("add_so extends the safety order limit of a trader")
|
|
print("You can also use negative numbers to substract to that limit")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
amount = input("Amount of safety orders to add/remove: ")
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if not validate_int(amount):
|
|
print("The amount entered is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/add_so"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote,
|
|
"amount": amount}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==61:
|
|
print("add_quote adds a lump sum of quote currency to the deal.")
|
|
print("This is not possible to do on a short trader")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
amount = input("Amount of quote to add: ")
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if not validate_float_or_int(amount):
|
|
print("The amount entered is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/add_quote"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote,
|
|
"amount": amount}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==62:
|
|
print("mod_tp_level modifies the profit percentage of a trader")
|
|
print("Example: 1.02 is equal to 2% profit")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
new_profit_level = input("Desired profit level: ")
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if not validate_float_or_int(new_profit_level):
|
|
print("The amount entered is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/mod_tp_level"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote,
|
|
"amount": new_profit_level}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==63:
|
|
print("last_call signals a trader to cease operation when profit is reached")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/last_call"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==64:
|
|
print("deferred_last_call signals a trader to cease operation when profit is reached after certain date")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
yyyymmdd = input("Input date (YYYYMMDD) ")
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if len(yyyymmdd)!=8:
|
|
print("Date format is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/deferred_last_call"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote,
|
|
"yyyymmdd": yyyymmdd}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==65:
|
|
print("toggle_pause pauses or unpauses a trader")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/toggle_pause"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==66:
|
|
print("toggle_cleanup enables or disables the cleanup routine of a trader")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/toggle_cleanup"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==67:
|
|
print("toggle_autoswitch enables or disables the automatic switch to long of a short trader once certain conditions are met.")
|
|
print("This is only valid in a short trader, of course.")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/toggle_autoswitch"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==68:
|
|
print("toggle_check_old_long_price enables or disables the verification of the current price exceeding the old long price.")
|
|
print("This is only valid in a short trader, of course.")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/toggle_check_old_long_price"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==69:
|
|
print("switch_quote_currency changes the quote currency of a running trader.")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
new_quote = input("Input new quote currency: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if len(new_quote)==0:
|
|
print("The quote currency is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/switch_quote_currency"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote,
|
|
"new_quote": new_quote}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==70:
|
|
print("reload_safety_order reloads the safety order to the reader using the order id present in the status dictionary")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/reload_safety_order"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==71:
|
|
print("Views the old_long information")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
from_file = 0 if input("From file? (y/N) ") in ["N","n",""] else 1
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
base,quote = trading_pair.split("/")
|
|
url = f"{base_url}{port}/view_old_long?base={base}"e={quote}&from_file={from_file}"
|
|
print(json.loads(requests.get(url,headers=headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==72:
|
|
print("Returns the price target to reach to switch to long mode")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
base,quote = trading_pair.split("/")
|
|
url = f"{base_url}{port}/switch_to_long_price?base={base}"e={quote}"
|
|
print(json.loads(requests.get(url,headers=headers).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==73:
|
|
print("Reloads from disk the configuration file of a trader")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/reload_trader_config"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==74:
|
|
print("toggle_liquidate_after_switch enables or disables the liquidation after an automatic switch to long of a short trader")
|
|
print("This is only valid in a short trader, of course.")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
url = f"{base_url}{port}/toggle_liquidate_after_switch"
|
|
base,quote = trading_pair.split("/")
|
|
parameters = {"base": base,
|
|
"quote": quote}
|
|
print(json.loads(requests.post(url, headers=headers, json=parameters).content))
|
|
input("Press ENTER to continue ")
|
|
|
|
elif command==75:
|
|
print("Returns the amount of safety orders that can be added to a short trader with the available funds")
|
|
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
|
if not validate_pair(trading_pair):
|
|
print("The input is invalid")
|
|
break
|
|
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
|
base,quote = trading_pair.split("/")
|
|
url = f"{base_url}{port}/base_add_so_calculation?base={base}"e={quote}"
|
|
print(json.loads(requests.get(url,headers=headers).content))
|
|
input("Press ENTER to continue ") |