fix(gemini-titan): lazily build symbol index in fetchRawOrderBook (closes #2037) - #2051
Open
chiliec wants to merge 1 commit into
Open
fix(gemini-titan): lazily build symbol index in fetchRawOrderBook (closes #2037)#2051chiliec wants to merge 1 commit into
chiliec wants to merge 1 commit into
Conversation
Closes pmxt-dev#2037. GeminiTitanExchange.fetchOrderBook() depended on the in-memory symbolToEventTicker index, which is only populated as a side effect of a prior fetchMarkets/fetchEvents call on the same fetcher instance. The server creates a fresh GeminiTitanExchange (and a fresh, empty-indexed GeminiFetcher) on every REST dispatch for a credentialed client, so fetchRawOrderBook() always threw for any credentialed GeminiTitan SDK client regardless of call order. Populate the index lazily: when the event ticker for the requested symbol is not found, call fetchRawEvents once to build the index, then retry the lookup. Only throw if the symbol is still unknown after that. Adds regression tests: fetchRawOrderBook succeeds when called first on a fresh fetcher, and still throws for a genuinely unknown symbol.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Closes #2037.
GeminiTitanExchange.fetchOrderBook()was unconditionally broken for any credentialed client.fetchRawOrderBook()reads the instance-levelsymbolToEventTickerindex, which is only populated as a side effect of a priorfetchRawEvents/fetchRawMarketscall on the same fetcher instance. Since the server constructs a brand-newGeminiTitanExchange(and a fresh, empty-indexedGeminiFetcher) on every REST dispatch when credentials are present, the index was always empty andfetchRawOrderBook()threw regardless of call order.Fix
In
fetchRawOrderBook(), when the event ticker for the requested symbol isn't in the index, build it lazily by callingfetchRawEvents({})once, then retry the lookup. Only throw if the symbol is still unknown afterwards. No other behaviour changes — a fetcher that already has a populated index (e.g. afterfetchMarkets) skips the extra call.Tests
Added regression coverage in
core/test/exchanges/gemini-titan-fetcher.test.ts:fetchRawOrderBooksucceeds when called first on a fresh fetcher (asserts it lists events to build the index, then fetches the single event) — this is the GeminiTitan fetchOrderBook() is unconditionally broken through both SDKs for any credentialed client #2037 scenario.Validation
npx jest gemini-titan-fetcher→ 5 passed (3 existing + 2 new)npx tsc --noEmit(core) → passesFirst-time contributor — happy to adjust the approach (e.g. cache/scope of the lazy fetch) to match your preferences.