fix: parse MCP result payloads and drop place idempotency_key

Typed result structs replace empty envelopes. Equity place sends
ref_id only so live additionalProperties:false schemas accept the call.
This commit is contained in:
2026-09-01 14:18:39 -05:00
parent f52a19181d
commit a6bf8632ce
22 changed files with 2225 additions and 74 deletions
+59 -10
View File
@@ -25,8 +25,17 @@ type PairsRequest struct {
Limit int
}
// CurrencyPair is one row from get_currency_pairs.
type CurrencyPair struct {
ID string
Symbol string
}
// PairsResult is the parsed get_currency_pairs payload.
type PairsResult struct{}
type PairsResult struct {
Pairs []CurrencyPair
NextCursor string
}
// QuotesRequest is the argument set for get_crypto_quotes.
type QuotesRequest struct {
@@ -35,8 +44,19 @@ type QuotesRequest struct {
RHSAccountNumber string
}
// CryptoQuote is one pair quote from get_crypto_quotes.
type CryptoQuote struct {
Symbol string
Bid decimal.Decimal
Ask decimal.Decimal
Mark decimal.Decimal
PrevClose decimal.Decimal
}
// QuotesResult is the parsed get_crypto_quotes payload.
type QuotesResult struct{}
type QuotesResult struct {
Quotes []CryptoQuote
}
// PositionsRequest is the argument set for get_crypto_positions.
type PositionsRequest struct {
@@ -44,8 +64,18 @@ type PositionsRequest struct {
Cursor string
}
// CryptoPosition is one holding from get_crypto_positions.
type CryptoPosition struct {
Symbol string
Quantity decimal.Decimal
CostBasis decimal.Decimal
}
// PositionsResult is the parsed get_crypto_positions payload.
type PositionsResult struct{}
type PositionsResult struct {
Positions []CryptoPosition
NextCursor string
}
// OrdersRequest is the argument set for get_crypto_orders.
type OrdersRequest struct {
@@ -61,7 +91,10 @@ type OrdersRequest struct {
}
// OrdersResult is the parsed get_crypto_orders payload.
type OrdersResult struct{}
type OrdersResult struct {
Orders []Order
NextCursor string
}
// PlaceOrderRequest is the argument set for preview_crypto_order and place_crypto_order.
type PlaceOrderRequest struct {
@@ -78,11 +111,20 @@ type PlaceOrderRequest struct {
}
// PreviewResult is the pre-trade check from preview_crypto_order.
type PreviewResult struct{}
type PreviewResult struct {
Errors []string `json:"errors"`
Warnings []string `json:"warnings"`
Quantity decimal.Decimal `json:"-"`
Price decimal.Decimal `json:"-"`
}
// Order is a placed crypto order.
// Order is a placed or listed crypto order.
type Order struct {
ID string `json:"id"`
ID string `json:"id"`
Symbol string `json:"symbol"`
Side string `json:"side"`
State string `json:"state"`
Qty decimal.Decimal `json:"-"`
}
// CancelOrderRequest is the argument set for cancel_crypto_order.
@@ -190,11 +232,18 @@ func (c *Client) PreviewOrder(ctx context.Context, req PlaceOrderRequest) (Previ
// PlaceOrder calls place_crypto_order. RefID is sent as ref_id.
func (c *Client) PlaceOrder(ctx context.Context, req PlaceOrderRequest) (Order, error) {
var out Order
if err := c.parse(ctx, toolPlace, placeArgs(req, true), &out); err != nil {
raw, err := c.c.Call(ctx, toolPlace, placeArgs(req, true))
if err != nil {
return Order{}, err
}
return out, nil
ords, err := parseOrders(raw)
if err != nil {
return Order{}, client.ToolErrorf(toolPlace, "parse: %w", err)
}
if len(ords) > 0 {
return ords[0], nil
}
return Order{}, nil
}
// CancelOrder calls cancel_crypto_order.