Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Made it possible to use other stable coins than USDT #42

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions PieBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,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

Expand All @@ -52,7 +52,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:
Expand All @@ -62,11 +62,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"))

gc.collect()

Expand Down Expand Up @@ -144,7 +144,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:
Expand All @@ -154,7 +154,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_data) >= 1:
Expand All @@ -168,7 +168,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:
Expand All @@ -178,7 +178,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_data) + len(buy_orders_data)
Expand Down
25 changes: 14 additions & 11 deletions _config-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,4 +34,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
32 changes: 16 additions & 16 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down