Skip to content

Commit

Permalink
Added portfolio check
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanAkkerman committed Nov 12, 2023
1 parent c21202d commit bb468c5
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/cogs/commands/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ async def add(
elif exchange.lower() == "binance":
ccxt_exchange = ccxt.binance({"apiKey": key, "secret": secret})

# Check if the API keys are valid
status = ccxt_exchange.fetch_status()
if status["status"] != "ok":
await ctx.respond(
f"Your API keys are not valid! Please check your API keys and try again."
)
return

new_data = pd.DataFrame(
{
"id": ctx.author.id,
Expand All @@ -98,14 +106,20 @@ async def add(
index=[0],
)

# TODO: Before adding the portfolio, check if it already exists

# Check if the API keys are valid
status = ccxt_exchange.fetch_status()
if status["status"] != "ok":
await ctx.respond(
f"Your API keys are not valid! Please check your API keys and try again."
)
# Check if new_data already exists in portfolio_db
if not util.vars.portfolio_db.empty: # ensure the DB isn't empty
# Check for duplicates based on a subset of columns that should be unique together
# Adjust the subset columns as per your data's unique constraints
duplicate_entries = util.vars.portfolio_db[
(util.vars.portfolio_db["user"] == new_data["user"].iloc[0])
& (util.vars.portfolio_db["exchange"] == new_data["exchange"].iloc[0])
& (util.vars.portfolio_db["key"] == new_data["key"].iloc[0])
& (util.vars.portfolio_db["secret"] == new_data["secret"].iloc[0])
]

if not duplicate_entries.empty:
# Handle the case where a duplicate is found
await ctx.respond("This portfolio already exists in the database.")
return

# Update the databse
Expand Down

0 comments on commit bb468c5

Please sign in to comment.