feat(us): US market APIs + DC-region guards#106
Open
hogan-yuan wants to merge 13 commits into
Open
Conversation
GetQuote returns nil when no WS push has been received for a symbol (e.g. non-trading hours). Appending nil into the slice and then ranging over it causes a nil-pointer dereference panic on the caller side. Fix: skip nil entries so callers receive only symbols that have data. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…ontexts - http/Client.IsUS(): detect US credentials from "us_" prefix - trade: USAssetOverview, USRealizedPL, QueryUSOrders, USOrderDetail (P0 E1/E2/#14/#16) - quote: CryptoOverview (P0 #3) - fundamental: CompanyOverview, ValuationOverview, FinancialOverview, FinancialStatementV3, KeyFinancialMetrics, AnalystConsensus, ETFDividendInfo, CompanyDividends, ETFFiles (P1/P2) - All US methods return ErrUSOnly when called with non-US credentials Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…R #554
Mirrors rust/crates/httpclient dc_restrict mechanism in Go:
- http: RegionRestrictedError{Path, Required, Current} — structured error
matching Rust HttpClientError::DcRegionRestricted message format
- http: Client.CheckRegion(path, "AP"|"US") — short-circuits with the
structured error when the session region doesn't match
- http: Client.region() helper; Client.IsUS() now uses it
AP-only guards (US token → error):
- dca: all 9 public methods (List/Create/Update/Pause/Resume/Stop/
History/Stats/CheckSupport/CalcDate/SetReminder)
- fundamental: Operating (/v1/quote/operatings)
- market: BrokerHolding, BrokerHoldingDetail, BrokerHoldingDaily
- quote: Brokers (WebSocket broker queue)
US-only guards updated to use CheckRegion (previously ErrUSOnly sentinel):
- trade: QueryUSOrders, USOrderDetail, USAssetOverview, USRealizedPL
- quote: CryptoOverview
- fundamental: all 9 US methods
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…into feat/us-market-apis
…ntinel - Merge PR #104: skip nil entries in RealtimeQuote when WS cache is empty - Remove unused ErrUSOnly sentinel from fundamental/us_context.go; all US-only guards now use CheckRegion(path, "US") uniformly Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Matches convention of all existing HK/CN methods: accept user-facing symbol (e.g. "AAPL.US", "SPY.US", "BTC.US") and convert internally to counter_id via symbolToCounterID / quoteSymbolToCounterID. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…x RankTag.rank_type type Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Embed US-ETF.csv, US-IX.csv, US-WT.csv (from Rust SDK) into the counter package. counter.SymbolToID() now resolves the correct prefix: SPY.US → ETF/US/SPY (was ST/US/SPY) AAPL.US → ST/US/AAPL (unchanged) Both fundamental.symbolToCounterID and quote.quoteSymbolToCounterID now delegate to counter.SymbolToID, fixing ETFDividendInfo and ETFFiles. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Conversion rules:
BTCUSD.HAS → VA/HAS/BTCUSD ({PAIR}.{EXCHANGE})
BTCUSD → VA/HAS/BTCUSD (default exchange HAS)
BTC/USD → VA/HAS/BTCUSD (slash removed)
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…SD.HAS) Remove BTC/USD and BTCUSD fallbacks — CLI handles those conversions upstream. BTCUSD.HAS → VA/HAS/BTCUSD; no .EXCHANGE suffix passes through as-is. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…D/IDToSymbol - SymbolToID: BTCUSD.HAS → VA/HAS/BTCUSD (non-standard market suffix = crypto exchange) - IDToSymbol: VA/HAS/BTCUSD → BTCUSD.HAS (VA prefix = crypto, returns PAIR.EXCHANGE) - CryptoOverview now uses counter.SymbolToID, same as all other symbol-based methods - Remove cryptoSymbolToCounterID private function Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…clusion Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
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
Adds 14 US-market-only API methods across the SDK, and back-ports the AP-only region guard from the Rust SDK (openapi#554).
Also merges the
fix/realtime-quote-nil-pointerfix (#104) fromfix/realtime-quote-nil-pointer.New US-only APIs
All methods call
CheckRegion(path, "US")at entry and return*http.RegionRestrictedErrorfor non-US tokens.P0 — Quote / Trade / Asset
QuoteContext.CryptoOverviewGET /v1/gemini/crypto-overviewTradeContext.QueryUSOrdersPOST /v1/orders/queryTradeContext.USOrderDetailGET /v3/orders/{order_id}TradeContext.USAssetOverviewGET /v1/us/assets/overviewTradeContext.USRealizedPLGET /v1/us/assets/pl/realizedP1 — Fundamental
FundamentalContext.CompanyOverviewGET /v1/stock-info/company-overviewFundamentalContext.ValuationOverviewGET /v1/stock-info/valuation-overviewFundamentalContext.FinancialOverviewGET /v1/stock-info/finn-overviewFundamentalContext.FinancialStatementV3GET /v1/us/quote/financials/statementsFundamentalContext.KeyFinancialMetricsGET /v1/stock-info/fin-keyfactorFundamentalContext.AnalystConsensusGET /v1/stock-info/fin-consensusFundamentalContext.ETFDividendInfoGET /v1/stock-info/etf-dividend-infoFundamentalContext.CompanyDividendsGET /v1/stock-info/company-dividendsP2 — Fundamental
FundamentalContext.ETFFilesGET /v1/stock-info/etf-filesAP-only guards (synced from Rust PR #554)
Methods that are AP-only now return
*http.RegionRestrictedErrorwhen called with a US token:DCAContext: all 9 methods (List,Create,Update,Pause,Resume,Stop,History,Stats,CheckSupport,CalcDate,SetReminder)FundamentalContext.OperatingMarketContext.BrokerHolding,BrokerHoldingDetail,BrokerHoldingDailyQuoteContext.Brokers(WebSocket)Structured error
http.RegionRestrictedErrormirrors Rust'sHttpClientError::DcRegionRestricted:http.Client.CheckRegion(path, "US"|"AP")is the single call site — returns nil on match,*RegionRestrictedErroron mismatch.🤖 Generated with Claude Code