-
Notifications
You must be signed in to change notification settings - Fork 2
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
Can sell more coins than what you have... without warning or raising an exception #2
Comments
Maybe adding something like def diff(trades):
return trades[trades["trade_side"] == "BUY"].groupby("cryptocurrency")["quantity"].sum().reindex(trades["cryptocurrency"].unique()).fillna(0) - trades[trades["trade_side"] == "SELL"].groupby("cryptocurrency")["quantity"].sum().reindex(trades["cryptocurrency"].unique()).fillna(0)
def verify(trades):
trades_diff = diff(trades)
neg = trades_diff[trades_diff < 0]
assert (trades_diff >= 0).all(), f"You can't sell more coins than what you have. See\n{neg}" should be considered |
Thank you for detecting this bug and opening an issue. It looks like you are right, this is a missing check. Selling more coins than you own can happen on exchanges that support short sells, but coin2086 explicitly does not support this use case, and I have no idea of the tax treatment of such events. I will have a look at it and add a check to prevent negative balances at any point in time, not just on average. |
Hi @fandre90 , You are right ! this check shouldn't be made "on average" but at "any point in time"... display(trades)
portfolio = trades[["cryptocurrency", "quantity", "trade_side"]].copy()
display(portfolio)
portfolio["sign"] = portfolio["trade_side"].map({"BUY": 1, "SELL": -1})
portfolio["signed_quantity"] = portfolio["quantity"] * portfolio["sign"]
pivoted_trades = pd.pivot_table(portfolio.reset_index(), values="signed_quantity", columns="cryptocurrency", index="index").fillna(0)
display(pivoted_trades)
display(pivoted_trades.cumsum())
display(pivoted_trades.cumsum() >= 0)
display((pivoted_trades.cumsum() >= 0).all())
display((pivoted_trades.cumsum() >= 0).all().all())
assert (pivoted_trades.cumsum() >= 0).all().all(), f"You can't sell more coins than what you have. See\n{pivoted_trades.cumsum()}" |
Hi,
I think the following code should raises an error or at least display a warning...
Kind regards
The text was updated successfully, but these errors were encountered: