a6bf8632ce
Typed result structs replace empty envelopes. Equity place sends ref_id only so live additionalProperties:false schemas accept the call.
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package watchlists
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"s1d3sw1ped/robinhood-agentic-mcp/internal/wire"
|
|
)
|
|
|
|
func (r *OptionListResult) UnmarshalJSON(b []byte) error {
|
|
type row struct {
|
|
OptionID string `json:"option_id"`
|
|
ID string `json:"id"`
|
|
Symbol string `json:"symbol"`
|
|
Title string `json:"title"`
|
|
PositionType string `json:"position_type"`
|
|
}
|
|
rows, _, err := wire.UnmarshalRows[row](b, "items", "results", "options")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
r.Items = make([]OptionWatchItem, 0, len(rows))
|
|
for _, row := range rows {
|
|
id := row.OptionID
|
|
if id == "" {
|
|
id = row.ID
|
|
}
|
|
r.Items = append(r.Items, OptionWatchItem{
|
|
OptionID: id, Symbol: row.Symbol, Title: row.Title, PositionType: row.PositionType,
|
|
})
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (r *PopularResult) UnmarshalJSON(b []byte) error {
|
|
type row struct {
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
Name string `json:"name"`
|
|
}
|
|
rows, _, err := wire.UnmarshalRows[row](b, "watchlists", "results")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
r.Watchlists = make([]Watchlist, 0, len(rows))
|
|
for _, row := range rows {
|
|
title := row.Title
|
|
if title == "" {
|
|
title = row.Name
|
|
}
|
|
r.Watchlists = append(r.Watchlists, Watchlist{ID: row.ID, Title: title})
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var _ json.Unmarshaler = (*OptionListResult)(nil)
|