fix: parse quotes results envelope and JSON-number num_std
This commit is contained in:
+32
-2
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user