fix: parse quotes results envelope and JSON-number num_std
This commit is contained in:
+21
-7
@@ -347,7 +347,7 @@ func (c *Client) TechnicalIndicators(ctx context.Context, req TechnicalIndicator
|
||||
args["period"] = *req.Period
|
||||
}
|
||||
if req.NumStd != nil {
|
||||
args["num_std"] = wire.Encode(*req.NumStd)
|
||||
args["num_std"] = json.Number(wire.Encode(*req.NumStd))
|
||||
}
|
||||
if req.FastPeriod != nil {
|
||||
args["fast_period"] = *req.FastPeriod
|
||||
@@ -359,7 +359,7 @@ func (c *Client) TechnicalIndicators(ctx context.Context, req TechnicalIndicator
|
||||
args["signal_period"] = *req.SignalPeriod
|
||||
}
|
||||
if req.Multiplier != nil {
|
||||
args["multiplier"] = wire.Encode(*req.Multiplier)
|
||||
args["multiplier"] = json.Number(wire.Encode(*req.Multiplier))
|
||||
}
|
||||
if req.Method != "" {
|
||||
args["method"] = req.Method
|
||||
@@ -471,13 +471,27 @@ func (r quoteRow) asQuote() (Quote, bool, error) {
|
||||
|
||||
func parseQuotes(raw json.RawMessage) ([]Quote, error) {
|
||||
var wrap struct {
|
||||
Quotes []quoteRow `json:"quotes"`
|
||||
Quotes []quoteRow `json:"quotes"`
|
||||
Results []quoteRow `json:"results"`
|
||||
}
|
||||
if err := json.Unmarshal(wire.Unwrap(raw), &wrap); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]Quote, 0, len(wrap.Quotes))
|
||||
for _, row := range wrap.Quotes {
|
||||
out := make([]Quote, 0, len(wrap.Quotes)+len(wrap.Results))
|
||||
var err error
|
||||
out, err = appendQuotes(out, wrap.Quotes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out, err = appendQuotes(out, wrap.Results)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func appendQuotes(dst []Quote, rows []quoteRow) ([]Quote, error) {
|
||||
for _, row := range rows {
|
||||
q, ok, err := row.asQuote()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -485,9 +499,9 @@ func parseQuotes(raw json.RawMessage) ([]Quote, error) {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
out = append(out, q)
|
||||
dst = append(dst, q)
|
||||
}
|
||||
return out, nil
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
type histPointJSON struct {
|
||||
|
||||
Reference in New Issue
Block a user