[Kraken] Scoped reads compare the wrong pair spelling, and one asset carries up to three currency codes

Author: zhaow-deCreated Sep 23, 2026Updated Sep 30, 2026

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:

rust
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 via Currency::get_or_create_crypto — XXBT, ZEUR, ZUSD.
  • http/spot/client.rs:2057-2060 (BalanceEx) strips one leading X or Z, as does normalize_currency_code at common/parse.rs:75-79. So the account holds XBT and EUR. The same strip turns XTZ (Tezos) into TZ and XBT.F (auto-earn) into BT.F.
  • common/parse.rs:796: REST fill commissions use instrument.quote_currency() → ZEUR / ZUSD. websocket/spot_v2/parse.rs:585 uses the venue's fee.asset verbatim instead, a different source and spelling for the same fee.
  • Both futures fill parsers ignore fee_currency and book the fee in instrument.quote_currency(): common/parse.rs:1161 (REST, parse_futures_fill_report) and websocket/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 at http/futures/models.rs:1015 asserts fee_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:2597 matches spot_positions_quote_currency against the instrument's quote code exactly. Instruments are quoted ZEUR / ZUSD, so configuring "EUR" or "USD" matches no instrument and produces no reports. The "USDT" default works only because USDT has no legacy prefix. .F balances are excluded too, since :2553 keys them as BT.F while :2606 looks up XBT.

  • crates/risk/src/engine/mod.rs:2433-2436 looks up free balance by required.currency, which comes from the instrument (ZEUR), and falls back to Money::zero on a miss while the account holds EUR. This is a latent order denial, measured in a backtest: a MARGIN account with no base currency holding 1000 EUR, the adapter's own XXBTZEUR instrument, and one post-only limit BUY of 0.001.

    Instrument margin_init 2.0.0rc6.dev20260918 dev20260923
    ZEUR-quoted, as the adapter builds it 0 accepted accepted
    ZEUR-quoted 0.5 accepted denied
    EUR-quoted control 0.5 accepted accepted

    The denial reads INITIAL_MARGIN_EXCEEDS_FREE_BALANCE: free=0.00000000 ZEUR, margin=5.00000000 ZEUR. It is masked today only because parse_spot_instrument (common/parse.rs:218-231) never sets margin_init or margin_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

  1. Load spot instruments for a pair whose AssetPairs key and altname differ, e.g. BTC/EUR (XXBTZEUR / XBTEUR).
  2. Place an order on it, then call generate_order_status_reports scoped to BTC/EUR.KRAKEN.
  3. 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, develop at 3adf5a8dc0

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_aliases is only reachable from the AssetPairs fetch (http/spot/client.rs:1677, :1715), so a client fed through cache_instrument/cache_instruments alone has no altname index and the resolver would need to fetch AssetPairs once in that case. This moves currency codes to BTC/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