fix: parse quotes results envelope and JSON-number num_std

This commit is contained in:
2026-09-01 12:39:00 -05:00
parent 658ba5efba
commit 21170bcf15
2 changed files with 53 additions and 9 deletions
+32 -2
View File
@@ -170,11 +170,11 @@ func TestEquity_toolNames(t *testing.T) {
"adjustment_type": "split",
"output": "latest",
"period": 14,
"num_std": "2",
"num_std": json.Number("2"),
"fast_period": 12,
"slow_period": 26,
"signal_period": 9,
"multiplier": "3",
"multiplier": json.Number("3"),
"method": "classic",
},
},
@@ -270,6 +270,36 @@ func TestQuotes_rhntest(t *testing.T) {
}
}
func TestQuotes_rhntestResultsEnvelope(t *testing.T) {
t.Parallel()
s := rhntest.New(t)
s.Set("get_equity_quotes", json.RawMessage(`{"data":{"results":[{"quote":{"symbol":"SPY","last_trade_price":"763.470000","bid_price":"763.760000","ask_price":"764.100000"},"close":{"symbol":"SPY","price":"765.72"}}]}}`))
c := equity.New(&client.Client{URL: s.URL})
got, err := c.Quotes(context.Background(), equity.QuotesRequest{Symbols: []string{"SPY"}})
if err != nil {
t.Fatal(err)
}
if len(got.Quotes) != 1 {
t.Fatalf("%+v", got)
}
q := got.Quotes[0]
if q.Symbol != "SPY" {
t.Fatalf("%+v", q)
}
if !q.Last.Equal(decimal.RequireFromString("763.470000")) {
t.Fatalf("last %s", q.Last)
}
if !q.Bid.Equal(decimal.RequireFromString("763.760000")) {
t.Fatalf("bid %s", q.Bid)
}
if !q.Ask.Equal(decimal.RequireFromString("764.100000")) {
t.Fatalf("ask %s", q.Ask)
}
if !q.PrevClose.Equal(decimal.RequireFromString("765.72")) {
t.Fatalf("prev close %s", q.PrevClose)
}
}
func TestHistoricals_rhntest(t *testing.T) {
t.Parallel()
s := rhntest.New(t)