Fix Interactive Brokers v2 crypto market data (support PAXOS and ZeroHash)#4389
Fix Interactive Brokers v2 crypto market data (support PAXOS and ZeroHash)#4389bebop23 wants to merge 1 commit into
Conversation
28127b9 to
b3b5c62
Compare
…Hash) IBKR routes retail crypto to both PAXOS and ZeroHash (which venue applies depends on the account/region). The v2 IB adapter hardcoded PAXOS, so ZeroHash-routed instruments like BTC/USD.ZEROHASH were unusable, and several stacked defects broke crypto market data: - Crypto venue was hardcoded to PAXOS, so BTC/USD.ZEROHASH failed contract resolution ([200] No security definition). Derive the venue from the contract's exchange (ZEROHASH or PAXOS), fall back to PAXOS when unspecified, and accept both in VENUES_CRYPTO. PAXOS continues to work unchanged. - The data client registered for a single venue, so venue-routed subscriptions (e.g. BTC/USD.ZEROHASH) were silently dropped by the data engine. Return None from venue() for default multi-venue routing, matching Tardis/Databento. - Real-time (5s) bars hardcoded whatToShow=TRADES, ignoring the bar's price type. Honor the requested price type. - TWS rejects whatToShow=TRADES for crypto with error 10299 on both reqHistoricalData and reqRealTimeBars (for PAXOS and ZeroHash alike); the venue serves trade-price data only under AGGTRADES. Map crypto trade-price bars to AGGTRADES on the realtime path, the live-client historical path, and the standalone HistoricalInteractiveBrokersClient path. AGGTRADES requires a WhatToShow::AggTrades variant that stock ibapi 3.0.1 lacks; this is added via a temporary [patch.crates-io] ibapi (submitted upstream to wboayue/rust-ibapi), to be replaced by a version bump once released. Adds Rust unit tests for both PAXOS and ZeroHash venue derivation (explicit and fallback), the crypto AGGTRADES mapping on all bar paths, and default routing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
b3b5c62 to
73cb00f
Compare
|
Hi @bebop23, Thanks for the detailed write-up, especially the note about the temporary One process note: this PR has triggered several project CI runs while the branch was still changing, including builds that were canceled by later pushes. Please avoid using the project CI as the main feedback loop. For future PRs, please run the relevant checks locally first and open the PR once the branch is in its final shape and ready for review. If there is a known external blocker, it is fine to call that out clearly, but please avoid pushing intermediate WIP states that burn CI compute. Let me know if anything is unclear. |
|
Hi @bebop23, Regarding the upstream This PR will need to wait until wboayue/rust-ibapi#693 lands in an upstream crates.io release. Once that is available, please remove the |
Pull Request
CONTRIBUTING.mdand followed the established practicesSummary
Makes the v2 Interactive Brokers adapter work with both of IBKR's crypto
venues — PAXOS and ZeroHash (which one applies depends on the account/region,
see IBKR's crypto trading-permissions docs). The adapter previously hardcoded
PAXOS, so ZeroHash-routed instruments like
BTC/USD.ZEROHASHfailed contractresolution, and several stacked defects broke crypto market data. This PR
derives the crypto venue from the contract's exchange (falling back to PAXOS),
registers the client for default multi-venue routing, honors the bar's price
type on real-time bars, and maps crypto trade-price bars to
AGGTRADES(TWSrejects
TRADESfor crypto with error 10299 on both venues). PAXOS continuesto work unchanged.
Related Issues/PRs
ibapiexposing aWhatToShow::AggTradesvariant:Add AggTrades (AGGTRADES) variant to WhatToShow enums wboayue/rust-ibapi#693. Until that lands in a release, this PR patches
ibapivia a temporary
[patch.crates-io]git dependency; once released it becomes aplain version bump with the patch removed. This PR is a draft until then.
Type of change
Breaking change details (if applicable)
None. Both PAXOS and ZeroHash are supported concurrently — PAXOS is retained as
the fallback and in
VENUES_CRYPTO, so existing PAXOS routing is unchanged.venue()now returnsNone(default routing), matching the other multi-venueadapters (Tardis, Databento).
Documentation
docs/developer_guide/docs.md)Release notes
RELEASES.mdthat follows the existing conventions (when applicable)Testing
Ensure new or changed logic is covered by tests.
Rust unit tests added in
parse.rs(ZeroHash and PAXOS symbol parse +contract→instrument venue derivation, explicit and fallback),
convert.rs(crypto→AGGTRADES on historical and realtime paths, non-crypto unaffected,
wire-string check), and
core.rs(venue()isNonefor default routing);the standalone
HistoricalInteractiveBrokersClientbar path now applies thesame crypto AGGTRADES rule. Live-verified against an IB paper gateway
(2026-07-05):
BTC/USD.ZEROHASH5-second bars flow post-fix (3/3 bars in ~19s),cross-checked against a direct TWS-API
reqRealTimeBars(
secType=CRYPTO, exchange=ZEROHASH, whatToShow=AGGTRADES).