Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate min/max usd btc values with btb database #230

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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: 14 additions & 10 deletions btb_manager_telegram/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,6 @@ def bot_stats():
end_date = datetime.strptime(bot_end_date[2:], "%y-%m-%d %H:%M:%S.%f")
numDays = (end_date - start_date).days

reports = [
r for r in get_previous_reports() if r["time"] >= start_date.timestamp()
]

# get first trade and its bridge - all stats must be in this bridge
cur.execute(
f"""SELECT alt_coin_id, crypto_coin_id, alt_trade_amount, crypto_trade_amount
Expand Down Expand Up @@ -580,6 +576,20 @@ def bot_stats():
return message
currentCoinID, currentCoinAmount = query

cur.execute(
"""
SELECT min(usd_values), max(usd_values), min(btc_values), max(btc_values) FROM (
SELECT (balance * usd_price) usd_values, (balance * btc_price) btc_values FROM coin_value WHERE usd_values > 5
)
"""
)
query = cur.fetchone()
if query is None:
max_usd = min_usd = max_btc = min_btc = 0
logger.error("Exception : Unable to calculate min/max USD, BTC values.")
else:
min_usd, max_usd, min_btc, max_btc = query

displayCurrency = (
"$" if initialCoinbridgeID in stableCoins else initialCoinbridgeID
)
Expand Down Expand Up @@ -616,12 +626,6 @@ def bot_stats():
(convertibleStartCoinAmount - initialCoinAmount) / initialCoinAmount * 100
)

max_usd = max(reports, key=lambda a: a["total_usdt"])["total_usdt"]
min_usd = min(reports, key=lambda a: a["total_usdt"])["total_usdt"]
btc_vals = [a["total_usdt"] / a["tickers"]["BTC"] for a in reports]
max_btc = max(btc_vals)
min_btc = min(btc_vals)

message += (
"`"
f"{i18n.t('bot_stats.bot_started', date=start_date.strftime('%d/%m/%y'), no_days=numDays)}"
Expand Down