Skip to content

Fix replay mode symbol resolution to use fully-qualified symbol (EXCHANGE:SYMBOL) - #230

Open
randomshinichi wants to merge 2 commits into
bitbytelabio:mainfrom
randomshinichi:fix/gaps-due-to-unqualified-symbol
Open

Fix replay mode symbol resolution to use fully-qualified symbol (EXCHANGE:SYMBOL)#230
randomshinichi wants to merge 2 commits into
bitbytelabio:mainfrom
randomshinichi:fix/gaps-due-to-unqualified-symbol

Conversation

@randomshinichi

Copy link
Copy Markdown

Reproduce the problem

TV_AUTH_TOKEN="$TV_AUTH_TOKEN" cargo run --example export_index_btcusd_1m_backfill -- --symbol BTCUSD --exchange INDEX --tf 1m --from 2026-02-01 --to 2026-02-19       
 --out-dir /tmp/tv-repro

If you want a single command that also prints detected minute gaps right after export:

TV_AUTH_TOKEN="$TV_AUTH_TOKEN" cargo run --example export_index_btcusd_1m_backfill -- --symbol BTCUSD --exchange INDEX --tf 1m --from 2026-02-01 --to 2026-02-19       
 --out-dir /tmp/tv-repro && f=$(ls /tmp/tv-repro/*2026-02*.csv | head -n1) && awk -F, 'NR==2{p=$1;next}{d=$1-p;if(d>60)printf("gap: %s -> %s (%ss)\n",p,$1,d);p=$1}' "$f"

Summary

This fixes an issue in replay mode where symbol resolution used the bare symbol (e.g. BTCUSD) instead of the fully-qualified symbol (e.g. INDEX:BTCUSD).

In my backfill runs, this caused subtle data quality problems:

  • missing 1m bars (small gaps),

  • and mismatched OHLCV vs TradingView/tvdatafeed for the same timestamps.

    Root cause

    In set_replay(...), resolve_symbol(...) was called with &options.symbol (bare symbol), while non-replay path uses symbol ({exchange}:{symbol}).

    So replay requests were not consistently scoped to the intended market/exchange.

    Fix

    In src/live/websocket.rs (set_replay), changed:

    resolve_symbol(..., &options.symbol, ...)

    to:

    resolve_symbol(..., symbol, ...)

    where symbol is already built as "{exchange}:{symbol}".

    Why this is correct

    set_market builds the fully-qualified symbol once and passes it to set_replay.

    resolve_symbol should receive the same symbol format in replay and non-replay paths for consistent behavior.

    Validation

    I validated this with repeated BTCUSD INDEX backfills:

  • Before fix: reproducible 1m gaps in exported CSV (e.g. missing minute bars around specific timestamps).

  • After fix: same export flow produced gap-free 1m output for the previously failing range; bar counts and continuity aligned with expected cadence.

    Scope

  • Minimal change (single-line behavior fix in replay path)

  • No API changes

  • No behavior change for non-replay mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant