equity: Accept open_price aliases in historicals
CI / Test and build (pull_request) Successful in 16s

Live Agentic get_equity_historicals returns
data.results[].bars[] with open_price/high_price/low_price/close_price.
parseHistoricals only read historicals[].data_points[] with short OHLC
names, so CT113 saw bars_len=30 on the wire but 0 parsed bars and VWAP
stayed 0 all day (insufficient_data mass skip).

Accept results|historicals envelopes, bars|data_points arrays, and
*_price aliases alongside short names. Fixture uses the live shape;
legacy short-name envelope stays covered.

Link: #18
This commit is contained in:
ash
2026-09-09 10:07:23 +00:00
parent 51e1539124
commit 27ca0a97c4
2 changed files with 48 additions and 14 deletions
+29 -4
View File
@@ -306,10 +306,11 @@ func TestQuotes_rhntestResultsEnvelope(t *testing.T) {
func TestHistoricals_rhntest(t *testing.T) {
t.Parallel()
s := rhntest.New(t)
s.Set("get_equity_historicals", json.RawMessage(`{"historicals":[{"symbol":"MU","data_points":[
{"begins_at":"2026-08-18T13:30:00Z","open":"10","high":"11","low":"9","close":"10","volume":"100","interpolated":false},
{"begins_at":"2026-08-18T13:31:00Z","open":"10","high":"10","low":"10","close":"10","volume":"1","interpolated":true}
]}]}`))
// Live Agentic shape (Jerry CT113): data.results[].bars[] with *_price fields.
s.Set("get_equity_historicals", json.RawMessage(`{"data":{"results":[{"symbol":"MU","bars":[
{"begins_at":"2026-08-18T13:30:00Z","open_price":"10","high_price":"11","low_price":"9","close_price":"10","volume":"100","session":"reg","interpolated":false},
{"begins_at":"2026-08-18T13:31:00Z","open_price":"10","high_price":"10","low_price":"10","close_price":"10","volume":"1","session":"reg","interpolated":true}
]}]}}`))
c := equity.New(&client.Client{URL: s.URL})
got, err := c.Historicals(context.Background(), equity.HistoricalsRequest{
Symbols: []string{"MU"},
@@ -335,3 +336,27 @@ func TestHistoricals_rhntest(t *testing.T) {
t.Fatalf("%+v", got.Bars[1])
}
}
func TestHistoricals_legacyShortNames(t *testing.T) {
t.Parallel()
s := rhntest.New(t)
s.Set("get_equity_historicals", json.RawMessage(`{"historicals":[{"symbol":"MU","data_points":[
{"begins_at":"2026-08-18T13:30:00Z","open":"10","high":"11","low":"9","close":"10","volume":"100","interpolated":false},
{"begins_at":"2026-08-18T13:31:00Z","open":"10","high":"10","low":"10","close":"10","volume":"1","interpolated":true}
]}]}`))
c := equity.New(&client.Client{URL: s.URL})
got, err := c.Historicals(context.Background(), equity.HistoricalsRequest{
Symbols: []string{"MU"},
StartTime: time.Date(2026, 8, 18, 13, 30, 0, 0, time.UTC),
})
if err != nil {
t.Fatal(err)
}
if len(got.Bars) != 2 {
t.Fatalf("bars %d", len(got.Bars))
}
b0 := got.Bars[0]
if !b0.Open.Equal(decimal.RequireFromString("10")) || !b0.High.Equal(decimal.RequireFromString("11")) || !b0.Volume.Equal(decimal.RequireFromString("100")) {
t.Fatalf("%+v", b0)
}
}