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

Prevent "Not enough shares to sell" error #19

Open
siropkin opened this issue Nov 1, 2024 · 1 comment
Open

Prevent "Not enough shares to sell" error #19

siropkin opened this issue Nov 1, 2024 · 1 comment

Comments

@siropkin
Copy link
Owner

siropkin commented Nov 1, 2024

Sometimes you can see that bot can't sell stocks because of this error: Not enough shares to sell.

Log example:

[2024-11-01 11:28:53] [INFO]    WD > Decision: sell with amount $1.0
[2024-11-01 11:28:53] [DEBUG]   Function: order_sell_fractional_by_price, Parameters: ('WD', 1.0), Attempt: 1/3, Result: {'detail': 'Not enough shares to sell.'}
[2024-11-01 11:28:53] [ERROR]   WD > Error selling: Not enough shares to sell.

It will be great if bot will prevent it before sell attempt.

Info about this error from Robinhood: https://robinhood.com/us/en/support/articles/not-enough-shares-error/

@siropkin siropkin changed the title Prevent "Not enough shares to sell" errors Prevent "Not enough shares to sell" error Nov 1, 2024
@siropkin
Copy link
Owner Author

siropkin commented Nov 4, 2024

One of the possible solutions will be filter decisions in adjust_decisions():

# Adjust decisions based on trading parameters
def adjust_decisions(decisions):
    sell_decisions = [
        decision for decision in decisions
        if decision['decision'] == "sell" and MIN_SELLING_AMOUNT_USD <= decision['amount'] <= MAX_SELLING_AMOUNT_USD
    ]
    buy_decisions = [
        decision for decision in decisions
        if decision['decision'] == "buy" and MIN_BUYING_AMOUNT_USD <= decision['amount'] <= MAX_BUYING_AMOUNT_USD
    ]
    hold_decisions = [decision for decision in decisions if decision['decision'] == "hold"]
    return sell_decisions + buy_decisions + hold_decisions

But it's not a garanty way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant