a6bf8632ce
Typed result structs replace empty envelopes. Equity place sends ref_id only so live additionalProperties:false schemas accept the call.
112 lines
2.6 KiB
Go
112 lines
2.6 KiB
Go
package scanner
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"s1d3sw1ped/robinhood-agentic-mcp/internal/wire"
|
|
)
|
|
|
|
func (r *FilterSpecsResult) UnmarshalJSON(b []byte) error {
|
|
type row struct {
|
|
FilterType string `json:"filter_type"`
|
|
Name string `json:"name"`
|
|
}
|
|
rows, _, err := wire.UnmarshalRows[row](b, "specs", "filters", "results")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
r.Specs = make([]FilterSpec, 0, len(rows))
|
|
for _, row := range rows {
|
|
r.Specs = append(r.Specs, FilterSpec{FilterType: row.FilterType, Name: row.Name})
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (r *DatapointsResult) UnmarshalJSON(b []byte) error {
|
|
type row struct {
|
|
Name string `json:"name"`
|
|
}
|
|
rows, _, err := wire.UnmarshalRows[row](b, "datapoints", "results")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
r.Datapoints = make([]Datapoint, 0, len(rows))
|
|
for _, row := range rows {
|
|
r.Datapoints = append(r.Datapoints, Datapoint{Name: row.Name})
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func unmarshalScan(b []byte) (ScanResult, error) {
|
|
var wrap struct {
|
|
ID string `json:"id"`
|
|
ScanID string `json:"scan_id"`
|
|
Title string `json:"title"`
|
|
Total int `json:"total"`
|
|
Rows []struct {
|
|
Symbol string `json:"symbol"`
|
|
Ticker string `json:"ticker"`
|
|
InstrumentID string `json:"instrument_id"`
|
|
} `json:"rows"`
|
|
Results []struct {
|
|
Symbol string `json:"symbol"`
|
|
InstrumentID string `json:"instrument_id"`
|
|
} `json:"results"`
|
|
}
|
|
if err := json.Unmarshal(wire.Unwrap(b), &wrap); err != nil {
|
|
return ScanResult{}, err
|
|
}
|
|
out := ScanResult{ID: wrap.ID, Title: wrap.Title, Total: wrap.Total}
|
|
if out.ID == "" {
|
|
out.ID = wrap.ScanID
|
|
}
|
|
src := wrap.Rows
|
|
if len(src) == 0 {
|
|
for _, row := range wrap.Results {
|
|
src = append(src, struct {
|
|
Symbol string `json:"symbol"`
|
|
Ticker string `json:"ticker"`
|
|
InstrumentID string `json:"instrument_id"`
|
|
}{Symbol: row.Symbol, InstrumentID: row.InstrumentID})
|
|
}
|
|
}
|
|
for _, row := range src {
|
|
sym := row.Symbol
|
|
if sym == "" {
|
|
sym = row.Ticker
|
|
}
|
|
out.Rows = append(out.Rows, ScanRow{Symbol: sym, InstrumentID: row.InstrumentID})
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (r *CreateResult) UnmarshalJSON(b []byte) error {
|
|
s, err := unmarshalScan(b)
|
|
r.ScanResult = s
|
|
return err
|
|
}
|
|
|
|
func (r *PreviewResult) UnmarshalJSON(b []byte) error {
|
|
s, err := unmarshalScan(b)
|
|
r.ScanResult = s
|
|
return err
|
|
}
|
|
|
|
func (r *RunResult) UnmarshalJSON(b []byte) error {
|
|
s, err := unmarshalScan(b)
|
|
r.ScanResult = s
|
|
return err
|
|
}
|
|
|
|
func (r *UpdateFiltersResult) UnmarshalJSON(b []byte) error {
|
|
s, err := unmarshalScan(b)
|
|
r.ScanResult = s
|
|
return err
|
|
}
|
|
|
|
func (r *UpdateConfigResult) UnmarshalJSON(b []byte) error {
|
|
s, err := unmarshalScan(b)
|
|
r.ScanResult = s
|
|
return err
|
|
}
|