Skip to content

update getFilters method to default symbols parameter to [] - #99

Merged
marcinvalas merged 5 commits into
masterfrom
getfilters-symbols-array
Nov 20, 2026
Merged

marcinvalas merged 5 commits into
masterfrom
getfilters-symbols-array

Conversation

@marcinvalas

Copy link
Copy Markdown
Contributor

No description provided.

… empty array

- Modified the getFilters method in various mappers to set the default value of the symbols parameter to an empty array instead of undefined.
- Ensured that all relevant mappers handle empty symbol arrays correctly, improving consistency across the codebase.
- Added error handling in Delta and FTX real-time feeds to require explicitly specified symbols for certain channels.
- Updated tests to verify that empty and omitted symbols behave as expected across different mappers and real-time feeds.
@marcinvalas

Copy link
Copy Markdown
Contributor Author

Enforcing symbols: string[] in getFilters() results

Done in this PR (option A, no public API change): the generic mapper test in test/mappers.test.ts now asserts that every filter returned for an unrestricted request carries a symbols array, for every exchange and normalizer. The mappers that still omitted symbols now return []:

  • bitfinex-derivatives liquidations and bitget-futures v3 liquidations: global channels, so they return symbols: []. Both live feeds subscribe to these globally before checking symbols.
  • phemex trades, book changes and derivative tickers: they return the requested []. realtimefeeds/phemex.ts now treats an empty symbols array like an omitted one and sends the global params: [] subscription, so live behaviour is unchanged.

Not done (option B, compile-time enforcement): change the public Mapper type in src/mappers/mapper.ts:

getFilters: (symbols?: string[]) => (FilterForExchange[T] & { symbols: string[] })[]

With option A's changes in place, only two built-in mappers would still fail to compile, both because their explicit return type annotation uses the looser FilterForExchange[...]. Fix: drop the annotation or tighten it.

  • src/mappers/binance.ts:337 (BinanceFuturesDerivativeTickerMapper.getFilters)
  • src/mappers/huobi.ts:297 (HuobiDerivativeTickerMapper.getFilters)

Trade-off: Mapper is exported from the package. A user's TypeScript custom mapper whose getFilters() omits symbols would stop compiling, so B is a small breaking type change. It needs an explicit decision and, ideally, a major version bump. Runtime behaviour would not change.

Related follow-up: under the documented filter rules (getFilters lists channels and does not choose instruments), the Delta India and WhiteBIT derivative ticker mappers still narrow requested symbols to perpetuals. Before simplifying them like Backpack, check that their live APIs accept non-perpetual symbols on those channels.

@thaaddeus

Copy link
Copy Markdown
Member

Looks good, ready to merge. just one small thing Docs: the ARCHITECTURE.md paragraph isn't needed. The contract already lives in the Mapper.getFilters JSDoc, which this PR updates, and the cache note belongs in the release notes.

@thaaddeus

Copy link
Copy Markdown
Member

Looks good, ready to merge.

@marcinvalas
marcinvalas merged commit b860d43 into master Nov 20, 2026
2 checks passed
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.

2 participants