feat: implement Self-Trade Prevention (STP) - #596
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #596 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 10 10
Lines 2369 2538 +169
Branches 303 350 +47
==========================================
+ Hits 2369 2538 +169 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Jun 29, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
User can trade against themself
Related Issues: #537, #226 and #149
What is the new behavior?
Implements Self-Trade Prevention (STP) as described in Binance's STP documentation. Orders from the same account (
accountId) can now be prevented from matching each other based on the taker'sstpMode.What's included
New API (
SelfTradePreventionModeenum):NONE— no prevention (default, backward compatible)EXPIRE_MAKER— resting maker order(s) expire, taker continuesEXPIRE_TAKER— taker expires immediately, maker stays on bookEXPIRE_BOTH— both maker and taker expireNew fields on all order types:
accountId?: string— identifies the account/trade group for STP matchingstpMode?: SelfTradePreventionMode— STP mode for the orderNew response field (
IProcessOrder):stpExpired?: IOrder[]— orders removed from the book due to STPNew error:
ERROR.STP_TRIGGERED(code1202) — returned whenEXPIRE_TAKERorEXPIRE_BOTHreject the takerScenarios covered (16 test cases):
accountIdis setFixes
Closes #537
Does this PR introduce a breaking change?
Other information