Commit 629c26a
Fix: Auto-cancel trigger orders when position is closed
Resolves issue #923 where stop-loss (trigger) orders were not being
automatically cancelled when a user closed their position.
Changes:
- Added new function `cancel_trigger_orders_for_closed_position()` that
cancels all trigger orders (TriggerMarket and TriggerLimit) for a
specific market when called
- Modified `fulfill_perp_order()` to check if a position is completely
closed after fulfillment (base_asset_amount == 0)
- If position is closed, automatically cancel all trigger orders for
that market to prevent unintended order execution
This prevents the following risk scenario:
1. User opens a short position with a stop-loss order
2. User manually closes the short position
3. Previously: SL order remained active and could execute unexpectedly
4. Now: SL order is automatically cancelled when position closes1 parent c74d5e9 commit 629c26a
1 file changed
+69
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
584 | 584 | | |
585 | 585 | | |
586 | 586 | | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
587 | 638 | | |
588 | 639 | | |
589 | 640 | | |
| |||
2042 | 2093 | | |
2043 | 2094 | | |
2044 | 2095 | | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
2045 | 2114 | | |
2046 | 2115 | | |
2047 | 2116 | | |
| |||
0 commit comments