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

Stablecoin selection #40

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
10 changes: 5 additions & 5 deletions PieBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,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_stablecoin_reserve = (total_portfolio_value / 100) * (stablecoin_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_stablecoin_value = get_coin_balance("USDT")
total_stablecoin_available = total_stablecoin_value - total_stablecoin_reserve
required_stablecoin = buy_order_value * len(pairs)

if required_usdt <= total_usdt_available:
if required_stablecoin <= total_stablecoin_available:
for pair in pairs:
order_value = buy_order_value

Expand Down
9 changes: 6 additions & 3 deletions _config-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
api_key = "xxx"
api_secret = "xxx"

# Set the stablecoin you want to trade with
stablecoin = "USDT"

# The list of coin pairs you want to trade with
pair_list = [
("ADA", "ADA_USDT"),
Expand All @@ -20,10 +23,10 @@
buy_frequency = 6
rebalance_frequency = 1

# The USDT value that PieBot will buy for each enabled coin pair in the "Buy" task
# The value in your chosen stablecoin that PieBot will buy for each enabled coin pair in the "Buy" task
buy_order_value = 0.50

# How much USDT do you want to keep as a reserve. This is a percentage of the total portfolio balance
# How much of your chosen stablecoin 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
stablecoin_reserve = 0.02
20 changes: 10 additions & 10 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 stablecoin reserves
stablecoin_reserve_value = (value / 100) * (stablecoin_reserve * 100)

total_available_balance = value - usdt_reserve_value
total_available_balance = value - stablecoin_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_stablecoin):
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:
if include_stablecoin:
# Get the total balance of USDT and add it to the current collected balance
usdt_total_balance = get_coin_balance("USDT")
stablecoin_total_balance = get_coin_balance("USDT")

total_balance = total_balance + usdt_total_balance
total_balance = total_balance + stablecoin_total_balance

return total_balance

Expand Down Expand Up @@ -236,15 +236,15 @@ def pre_flight_checks():

# Checks whether the USDT reserve amount has been defined
try:
usdt_reserve
stablecoin_reserve
except NameError:
print(colored("Your USDT reserve amount is missing from the config file", "red"))
sys.exit()
else:
if usdt_reserve < 0:
if stablecoin_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"))
sys.exit()
elif usdt_reserve > 80:
elif stablecoin_reserve > 80:
print(colored("Your USDT reserve must be 80% or lower", "red"))
sys.exit()

Expand Down