[Kraken] Scoped reads compare the wrong pair spelling, and one asset carries up to three currency codes
Confirmation
- I've re-read the relevant sections of the documentation.
- I've searched existing issues and discussions to avoid duplicates.
- I've reviewed or skimmed the source code (or examples) to confirm the behavior is not by design.
- I've tested this issue using a recent pre-release or development wheel.
Found by source review against develop at 3adf5a8dc0. Paths below are under
crates/adapters/kraken/src/. Related: #5033 / #5034 fixed the unscoped lookup; the scoped filters
below were not covered. Separate from #5064.
Expected behavior
A scoped read returns that instrument's rows and no others, whichever way Kraken spells the pair. One asset has one Nautilus currency code across instruments, balances and fees.
Actual behavior
1. Scoped reads compare the wrong pair spelling
http/spot/client.rs:2210 (open orders) and :2258 (closed orders) pre-filter each row with:
if let Some(inst) = self.get_cached_instrument(&target_id.symbol.inner())
&& inst.raw_symbol().as_str() != order.descr.pair
{
continue;
}raw_symbol is the AssetPairs key (XXBTZEUR, set at common/parse.rs:192), while
descr.pair is the altname (XBTEUR). The adapter documents this exact split at
http/spot/client.rs:1407-1410. For a pair whose key and altname differ, a scoped read skips that
pair's own orders. The alias-aware get_instrument_by_raw_symbol from #5034 runs on the next
statement, so it never reaches this comparison.
:2340 applies the same filter to TradesHistory rows. Kraken's docs and kraken-cli suggest
TradesHistory returns the key, which would match; the adapter's own comment says altname. We have
no live capture that settles which is right, so we flag it as unverified rather than asserting it.
Only two callers reach these filters with a scope: execution/spot.rs:1295
(generate_order_status_reports) and :1312 (generate_fill_reports) forward cmd.instrument_id.
Startup mass status (:1362, :1366) and the order queries pass None, so reconciliation at
startup is unaffected.
2. The scope filter switches itself off
In all seven filters — spot :2207-2213, :2255-2261, :2337-2343, and futures
http/futures/client.rs:1781, :1843, :1996, :2043 — a cache miss makes the whole if let
false, so the filter is skipped and the scoped read returns every instrument's rows. Spot and
futures ids share the KRAKEN venue, so a futures id passed to the spot client is enough to
trigger it. (The spelling problem in 1 is spot-only; this one is not.)
3. One asset carries up to three currency codes
common/parse.rs:194-195: instrument currencies are Kraken's legacy codes verbatim viaCurrency::get_or_create_crypto—XXBT,ZEUR,ZUSD.http/spot/client.rs:2057-2060(BalanceEx) strips one leadingXorZ, as doesnormalize_currency_codeatcommon/parse.rs:75-79. So the account holdsXBTandEUR. The same strip turnsXTZ(Tezos) intoTZandXBT.F(auto-earn) intoBT.F.common/parse.rs:796: REST fill commissions useinstrument.quote_currency()→ZEUR/ZUSD.websocket/spot_v2/parse.rs:585uses the venue'sfee.assetverbatim instead, a different source and spelling for the same fee.- Both futures fill parsers ignore
fee_currencyand book the fee ininstrument.quote_currency():common/parse.rs:1161(REST,parse_futures_fill_report) andwebsocket/futures/parse.rs:355(WebSocket). Both message types carry the field (http/futures/models.rs:391-392,websocket/futures/messages.rs:494) and the venue populates it — the existing test athttp/futures/models.rs:1015assertsfee_currency == Some("BTC"). So a BTC fee on an inverse contract is recorded as USD.
Net effect: Bitcoin appears as XXBT on instruments, XBT in the account and BTC on WebSocket
fees; euro as ZEUR and EUR. Currencies compare by code, so these never match.
Two consequences follow:
http/spot/client.rs:2597matchesspot_positions_quote_currencyagainst the instrument's quote code exactly. Instruments are quotedZEUR/ZUSD, so configuring"EUR"or"USD"matches no instrument and produces no reports. The"USDT"default works only because USDT has no legacy prefix..Fbalances are excluded too, since:2553keys them asBT.Fwhile:2606looks upXBT.crates/risk/src/engine/mod.rs:2433-2436looks up free balance byrequired.currency, which comes from the instrument (ZEUR), and falls back toMoney::zeroon a miss while the account holdsEUR. This is a latent order denial, measured in a backtest: a MARGIN account with no base currency holding 1000 EUR, the adapter's ownXXBTZEURinstrument, and one post-only limit BUY of 0.001.Instrument margin_init2.0.0rc6.dev20260918dev20260923ZEUR-quoted, as the adapter builds it0 accepted accepted ZEUR-quoted0.5 accepted denied EUR-quoted control0.5 accepted accepted The denial reads
INITIAL_MARGIN_EXCEEDS_FREE_BALANCE: free=0.00000000 ZEUR, margin=5.00000000 ZEUR. It is masked today only becauseparse_spot_instrument(common/parse.rs:218-231) never setsmargin_initormargin_maint, so both default to zero and the required margin is zero. Populating those rates turns this into a denial of every margin order. The change in behaviour between the two builds appears to come from ba95d4e72a (2026-09-22).
WebSocket v2 symbols were checked and are not affected: all 1450 AssetPairs entries carry a
wsname, and after KRAKEN_SYMBOL_RENAMES every one matches the public WS v2 instrument
snapshot, so common/parse.rs:189-191 and the subscribe and add_order symbol paths have no
broken case today.
Not examined: the shape of tokenized .T balance keys and the .P / .HOLD suffixes, the futures
/accounts keys, and any risk or portfolio consequence beyond the denial measured above.
Steps to reproduce
- Load spot instruments for a pair whose
AssetPairskey and altname differ, e.g.BTC/EUR(XXBTZEUR/XBTEUR). - Place an order on it, then call
generate_order_status_reportsscoped toBTC/EUR.KRAKEN. - The order is missing. Calling it unscoped returns it.
For 2: call any scoped read with an instrument id the client does not hold and observe that every instrument's rows come back.
Specifications
- OS platform: Linux
- Adapter/venue: Kraken (spot and futures)
- Installed from: built from source,
developat3adf5a8dc0
Question for maintainers
@cjdsellers these share one root cause but the fixes differ in blast radius, so we would rather agree the shape before writing code. Which would you accept?
- A. One PR. A pair resolver covering key, altname and wsname used by every read and filter;
scoped reads compare resolved instrument ids and return nothing for an instrument the client does
not hold; one table-driven asset-code normaliser (
XXBT/XBT→BTC,XDG→DOGE,ZEUR→EUR, suffixes handled) used for instruments, balances, fees and the two config values; fixtures with key≠altname pairs and prefixed or suffixed assets. One detail:record_pair_aliasesis only reachable from theAssetPairsfetch (http/spot/client.rs:1677,:1715), so a client fed throughcache_instrument/cache_instrumentsalone has no altname index and the resolver would need to fetchAssetPairsonce in that case. This moves currency codes toBTC/EUR/USD, which every Kraken user sees. - B. The same work split in two. Pair resolution first, with no user-visible change, then the asset-code normalisation.
- C. Pair resolution, plus consistency without renaming. Balances and fees keep the instruments' legacy codes rather than stripping them, so nothing a user has stored changes.
We lean towards A, since one root cause explains every symptom, or B if you would rather isolate the currency-code change. Also: should the currency-code change be treated as breaking?
Source: nautechsystems/nautilus_trader