Skip to content

Stoploss with wrong qty after a partial takeprofit #510

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

Open
dpanelli opened this issue Apr 1, 2025 · 0 comments
Open

Stoploss with wrong qty after a partial takeprofit #510

dpanelli opened this issue Apr 1, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@dpanelli
Copy link

dpanelli commented Apr 1, 2025

🐞 Bug Report: Stoploss Order Reflects Incorrect Quantity After Partial Take-Profit

Summary:
After executing a partial take-profit order, the corresponding stop-loss order displays an incorrect quantity that does not match the remaining position.

Steps to Reproduce:
1. Open a long position with a total quantity of 0.17 at market price (e.g., at 66223.8).
2. Set a limit take-profit order for a partial quantity (e.g., 0.09 at 67548.28).
3. Set a stop-loss order for the remaining position.
4. Allow the take-profit order to partially execute.

Expected Result:
After the partial take-profit is filled, the stop-loss quantity should reflect the remaining position (0.08 in this case).

Actual Result:
The stop-loss quantity remains -0.17, which is the original full position size, even though 0.09 has already been sold.

Screenshot Reference:
• Initial BUY: 0.17 @ 66223.8 (MARKET)
• Partial TAKE-PROFIT: -0.09 @ 67548.28 (LIMIT SELL)
• STOP-LOSS: -0.17 @ 59601.42 (STOP SELL) ❌ Incorrect — should be -0.08

To Reproduce
Orders set up code.

   def go_long(self):
      entry_price = self.price
      qty = utils.size_to_qty(self.balance, entry_price)

      stop_loss_price = entry_price * 0.9
      take_profit_1_price = entry_price * 1.02
      take_profit_2_price = entry_price * 1.1

      self.buy = qty, entry_price
      self.stop_loss = qty, stop_loss_price
      self.take_profit = [
          (qty * 0.5, take_profit_1_price),  
          (qty * 0.5, take_profit_2_price),  
    ]
Image
@dpanelli dpanelli added the bug Something isn't working label Apr 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants
@dpanelli and others