Repository navigation
feat(quote): add Transport to serve quote pull APIs over HTTP - #130
Open
hogan-yuan wants to merge 2 commits into
Open
hogan-yuan wants to merge 2 commits into
hogan-yuan wants to merge 2 commits into
Conversation
Port longbridge/openapi#604. Add `quote.Transport` (`TransportWebSocket`, default, or `TransportHTTP`), set with `quote.WithTransport`, `config.Config.QuoteTransport` or env `LONGBRIDGE_QUOTE_TRANSPORT=ws|http`. With `TransportHTTP` the 19 `QuoteContext` pull APIs that have a REST equivalent are sent as `POST /quote/*` instead of over the quote WebSocket: the request is the same protobuf message encoded as proto-JSON and the response is decoded back into the same message, so method signatures and return types are unchanged. The WebSocket is dialed lazily, only when subscriptions, push callbacks, `Profile()` or an API without a REST equivalent is first used, so a context that only pulls data never opens a connection. Results are aligned with the WebSocket, including US overnight data, which REST always returns but the WebSocket only returns with `WithEnableOvernight(true)`: on the HTTP path the SDK clears `OverNightQuote`, filters overnight intraday lines for US equities and, for `CandlestickTradeSessionAll` history queries, drops overnight bars and tops up count/range-capped windows with offset queries (unit-tested). Add `examples/quote_http_compare`, which calls every pull API over both transports and diffs the results.
- normalise gateway proto-JSON before protojson: "" on numeric/enum fields, "true"/"false" on bool fields, numbers on string fields and null elements in scalar lists (descriptor-driven, unit-tested) - WithTransport validates its value and warns on unknown names; New fails fast when no HTTP client is configured instead of panicking later - refill: once a page yields no usable bar the cursor is inside the contiguous overnight block; fetch a full page to jump it (regression tests for both directions) - extract alignCandlesticks/windowTarget as pure functions and unit-test the target / capped / early-exit rules - docs: Profile() semantics, CHANGELOG split (CalcIndex name, top-up endpoint, nil-client error), brokers region label
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
Ports longbridge/openapi#604 to the Go SDK. Adds
quote.Transport(quote.TransportWebSocket, default /quote.TransportHTTP), set withquote.WithTransport(...),config.Config.QuoteTransportor envLONGBRIDGE_QUOTE_TRANSPORT=ws|http. WithTransportHTTPthe 19QuoteContextpull APIs that have a REST equivalent (StaticInfo,Quote,OptionQuote,WarrantQuote,Depth,Brokers,Participants,Trades,Intraday,Candlesticks,HistoryCandlesticksByOffset/ByDate,OptionChainExpiryDateList,WarrantIssuers,WarrantList,TradingSession,TradingDays,CapitalFlow,CapitalDistribution,CalcIndex) go overPOST /quote/*instead of the quote WebSocket. Method signatures and return types are unchanged.Why
Same motivation as the Rust PR: longbridge/longbridge-mcp#162 re-implemented every quote tool on the REST endpoints inside the MCP to get rid of its per-user WebSocket pool. That belongs in the SDK, and Go consumers should get the same switch.
How
quote/transport.go:httpPathsmaps WebSocket commands to REST paths;core.dobranches on the transport. Requests are the same protobuf messages encoded withprotojson(proto field names, absent sub-messages omitted); responses are decoded withprotojson(DiscardUnknown, so the gateway's extravolume_stris ignored; int64-as-string andnullsub-messages are handled natively).newCoreno longer dials unconditionally. WithTransportWebSocketit dials and fetches the profile up front exactly as before; withTransportHTTPthe socket is dialed on first need (Subscribe,On*callbacks,Profile(),Subscriptions, or any command without a REST path) viacore.ws(). Push handlers registered before the dial are queued and attached when it happens.Close()is a no-op if never dialed.quote/overnight.goaligns the one known server-side difference: REST always returns US overnight data and has no opt-out, while the WebSocket only returns it withWithEnableOvernight(true). On the HTTP path (and only there) the SDK clearsOverNightQuote, filters overnightIntradaylines for US equities, and forCandlestickTradeSessionAllhistory queries dropsOVERNIGHT_TRADEbars and tops up count/range-capped windows with offset queries (≤1000 per request, ≤8 rounds). The WebSocket path is behaviourally identical tomain.examples/quote_http_comparecalls every pull API over both transports and diffs the JSON output.Verification
go test ./quote/passes (new tests: refill paging scenarios, US overnight window in EDT/EST, command→path map completeness, gateway proto-JSON decode replay, request encoding). The two failingconfigpackage tests (Test_YamlConfig/Test_TomlConfig) fail identically onmain(missing fixture files) and are unrelated.go vet ./quote/reports only the pre-existingcopylockswarnings fromutil.Copy(same 8 onmain).openapi-global.longbridge.xyz), overnight off: 30/32 cases identical between transports; the 2 remaining are the gateway error-code gap below. Production and overnight-on runs plus the full input/output report follow in a comment.Known gateway gaps (not fixable in the SDK)
500 internal server errorinstead of passing the code through (WS:301600,301604,301607)./quote/*replicas are not consistent with each other (value-level differences inavg_price/volume; two consecutive REST calls can disagree while the WS is stable).🤖 Generated with Claude Code