From 3021767fa547d1466becb5f0d150e156b9cc03bf Mon Sep 17 00:00:00 2001 From: grandted Date: Fri, 27 Aug 2021 23:30:24 +0200 Subject: [PATCH] Made it possible to use other stable coins than USDT --- PieBot.py | 24 ++++++++++++------------ _config-example.py | 25 ++++++++++++++----------- functions.py | 32 ++++++++++++++++---------------- 3 files changed, 42 insertions(+), 39 deletions(-) diff --git a/PieBot.py b/PieBot.py index efce6ad..0d4369a 100644 --- a/PieBot.py +++ b/PieBot.py @@ -16,13 +16,13 @@ def buy(pairs): print(colored("Placing orders...", "cyan")) total_portfolio_value = get_portfolio_value(pairs, True) - total_usdt_reserve = (total_portfolio_value / 100) * (usdt_reserve * 100) + total_stable_coin_reserve = (total_portfolio_value / 100) * (stable_coin_reserve * 100) - total_usdt_value = get_coin_balance("USDT") - total_usdt_available = total_usdt_value - total_usdt_reserve - required_usdt = buy_order_value * len(pairs) + total_stable_coin_value = get_coin_balance(stable_coin) + total_stable_coin_available = total_stable_coin_value - total_stable_coin_reserve + required_stable_coin = buy_order_value * len(pairs) - if required_usdt <= total_usdt_available: + if required_stable_coin <= total_stable_coin_available: for pair in pairs: order_value = buy_order_value @@ -35,7 +35,7 @@ def buy(pairs): print_value = round(order_value, 2) current_time(True) - print(str(print_value) + " USDT - " + pair[0], end=" ") + print(str(print_value) + stable_coin + " - " + pair[0], end=" ") print(colored("[BUY]", "green")) if not order_confirmed: @@ -45,11 +45,11 @@ def buy(pairs): else: print_value = round(order_value, 2) current_time(True) - print(str(print_value) + " USDT - " + pair[0], end=" ") + print(str(print_value) + stable_coin + " - " + pair[0], end=" ") print(colored("[BUY]", "green")) else: - print(colored("Not enough USDT available", "yellow")) + print(colored("Not enough "+ stable_coin +" available", "yellow")) print(colored("Waiting to be called...", "cyan")) @@ -111,7 +111,7 @@ def rebalance(pairs): print_value = round(order[3], 2) current_time(True) - print(str(print_value) + " USDT - " + order[0], end=" ") + print(str(print_value) + stable_coin + " - " + order[0], end=" ") print(colored("[SELL]", "magenta")) if not order_confirmed: @@ -121,7 +121,7 @@ def rebalance(pairs): else: print_value = round(order[3], 2) current_time(True) - print(str(print_value) + " USDT - " + order[0], end=" ") + print(str(print_value) + stable_coin + " - " + order[0], end=" ") print(colored("[SELL]", "magenta")) if len(buy_orders) >= 1: @@ -135,7 +135,7 @@ def rebalance(pairs): print_value = round(order[3], 2) current_time(True) - print(str(print_value) + " USDT - " + order[0], end=" ") + print(str(print_value) + stable_coin + " - " + order[0], end=" ") print(colored("[BUY]", "green")) if not order_confirmed: @@ -145,7 +145,7 @@ def rebalance(pairs): else: print_value = round(order[3], 2) current_time(True) - print(str(print_value) + " USDT - " + order[0], end=" ") + print(str(print_value) + stable_coin + " - " + order[0], end=" ") print(colored("[BUY]", "green")) total_orders = len(sell_orders) + len(buy_orders) diff --git a/_config-example.py b/_config-example.py index 404533d..97fc695 100644 --- a/_config-example.py +++ b/_config-example.py @@ -2,18 +2,21 @@ api_key = "xxx" api_secret = "xxx" +# Set the type of stable coin your will trade with (USDC, USDT, TUSD etc.) +stable_coin = "USDC" + # The list of coin pairs you want to trade with pair_list = [ - ("ADA", "ADA_USDT"), - ("ALGO", "ALGO_USDT"), - ("ATOM", "ATOM_USDT"), - ("BTC", "BTC_USDT"), - ("CRO", "CRO_USDT"), - ("DOT", "DOT_USDT"), - ("ETH", "ETH_USDT"), - ("LTC", "LTC_USDT"), - ("XLM", "XLM_USDT"), - ("XRP", "XRP_USDT") + ("ADA", "ADA_" + stable_coin), + ("ALGO", "ALGO_" + stable_coin), + ("ATOM", "ATOM_" + stable_coin), + ("BTC", "BTC_" + stable_coin), + ("CRO", "CRO_" + stable_coin), + ("DOT", "DOT_" + stable_coin), + ("ETH", "ETH_" + stable_coin), + ("LTC", "LTC_" + stable_coin), + ("XLM", "XLM_" + stable_coin), + ("XRP", "XRP_" + stable_coin) ] # Sets after how many hours each task should repeat @@ -26,4 +29,4 @@ # How much USDT do you want to keep as a reserve. This is a percentage of the total portfolio balance # 0.05 = 5% # 0.15 = 15% -usdt_reserve = 0.02 +stable_coin_reserve = 0.02 diff --git a/functions.py b/functions.py index 5f3319a..58b4649 100644 --- a/functions.py +++ b/functions.py @@ -38,10 +38,10 @@ def current_time(new_line): # Gets the total available value of the portfolio def get_available_portfolio_value(value): - # Keeps aside the defined USDT reserves - usdt_reserve_value = (value / 100) * (usdt_reserve * 100) + # Keeps aside the defined stable coin reserves + stable_coin_reserve_value = (value / 100) * (stable_coin_reserve * 100) - total_available_balance = value - usdt_reserve_value + total_available_balance = value - stable_coin_reserve_value return total_available_balance @@ -93,7 +93,7 @@ def get_instrument(instruments, name): # Gets the total value of the portfolio -def get_portfolio_value(pairs, include_usdt): +def get_portfolio_value(pairs, include_stable_coin): total_balance = 0 for pair in pairs: @@ -105,11 +105,11 @@ def get_portfolio_value(pairs, include_usdt): total_balance = total_balance + (coin_balance * coin_price) - if include_usdt: - # Get the total balance of USDT and add it to the current collected balance - usdt_total_balance = get_coin_balance("USDT") + if include_stable_coin: + # Get the total balance of stable coin and add it to the current collected balance + stable_coin_total_balance = get_coin_balance(stable_coin) - total_balance = total_balance + usdt_total_balance + total_balance = total_balance + stable_coin_total_balance return total_balance @@ -234,18 +234,18 @@ def pre_flight_checks(): print(colored("Your Buy order value cannot be smaller than the minimum order value", "red")) sys.exit() - # Checks whether the USDT reserve amount has been defined + # Checks whether the stable coin reserve amount has been defined try: - usdt_reserve + stable_coin_reserve except NameError: - print(colored("Your USDT reserve amount is missing from the config file", "red")) + print(colored("Your "+ stable_coin +" reserve amount is missing from the config file", "red")) sys.exit() else: - if usdt_reserve < 0: - print(colored("You need to define a valid USDT reserve. If you don't want to use a reserve, set the value as 0", "red")) + if stable_coin_reserve < 0: + print(colored("You need to define a valid "+ stable_coin +" reserve. If you don't want to use a reserve, set the value as 0", "red")) sys.exit() - elif usdt_reserve > 80: - print(colored("Your USDT reserve must be 80% or lower", "red")) + elif stable_coin_reserve > 80: + print(colored("Your "+ stable_coin +" reserve must be 80% or lower", "red")) sys.exit() # Send a private request to test if the API key and API secret are correct @@ -254,7 +254,7 @@ def pre_flight_checks(): "method": "private/get-account-summary", "api_key": api_key, "params": { - "currency": "USDT" + "currency": stable_coin }, "nonce": int(time.time() * 1000) }