feat(scrypt): tighten price deviation cap to 0.3% + notify on overshoot#3736
Draft
TaprootFreak wants to merge 1 commit into
Draft
feat(scrypt): tighten price deviation cap to 0.3% + notify on overshoot#3736TaprootFreak wants to merge 1 commit into
TaprootFreak wants to merge 1 commit into
Conversation
Scrypt embeds its commission into the quoted price ("price you see is
what you get"), so the spread between Scrypt's executable price and our
pricing reference is the only pre-trade signal that the implicit cost
is too high.
The default maxPriceDeviation of 5% in ScryptAdapter.getAndCheckTradePrice
was too loose: on 2026-05-21 a 570'000 EUR BTC/EUR buy on Scrypt cleared
at a 0.65% spread vs. our pricing reference, costing ~2'870 EUR more
than Kraken would have. The check passed silently because 0.65% << 5%.
Changes:
- Add Config.scrypt.maxPriceDeviation = 0.003 (0.3%)
- ScryptAdapter.getAndCheckTradePrice defaults to that cap
- On overshoot: send ErrorMonitoring mail (isLiqMail) before throwing
OrderFailedException, debounced 1h per asset pair to avoid spam
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.
Why
On 2026-05-21 a 570'000 EUR BTC/EUR buy on Scrypt cleared at a 0.65 % spread vs. our pricing reference, costing ~2'870 EUR more than the equivalent Kraken trade would have (Kraken BTC/EUR fee is a constant 0.14 % over 5'685 historical trades). The trade went through silently because the existing pre-trade check
ScryptAdapter.getAndCheckTradePricehas a defaultmaxPriceDeviationof 5 %, far above any reasonable threshold.Scrypt embeds its commission into the quoted price ("price you see is what you get", per their FAQ), so it does not return a separate fee via its WebSocket API. The spread between Scrypt's executable price and our internal pricing reference is therefore the only pre-trade signal that the implicit cost is too high.
What
Config.scrypt.maxPriceDeviation = 0.003(0.3 %)ScryptAdapter.getAndCheckTradePricedefaults to that cap (was hardcoded 0.05)maxPriceDeviationoverride inparamMapstill wins, so emergency loosening stays possible without code changeErrorMonitoringmail (withisLiqMail: true, so monitoring + liq team both get it) before throwingOrderFailedExceptioncorrelationId+suppressRecurringto avoid alert spamEffect on the 2026-05-21 incident
With this change, the BTC/EUR buy at 0.65 % spread would have:
Test plan
OrderFailedExceptionand a mail lands in monitoring inbox