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:
+34
-10
@@ -57,11 +57,18 @@ type ReplaceOrderRequest struct {
|
||||
}
|
||||
|
||||
// ReviewResult is the pre-trade check from review_option_order.
|
||||
type ReviewResult struct{}
|
||||
type ReviewResult struct {
|
||||
Errors []string `json:"errors"`
|
||||
Warnings []string `json:"warnings"`
|
||||
Alerts []string `json:"alerts"`
|
||||
}
|
||||
|
||||
// Order is a placed or replaced option order.
|
||||
// Order is a placed, replaced, or listed option order.
|
||||
type Order struct {
|
||||
ID string `json:"id"`
|
||||
ID string `json:"id"`
|
||||
State string `json:"state"`
|
||||
Qty decimal.Decimal `json:"-"`
|
||||
Price decimal.Decimal `json:"-"`
|
||||
}
|
||||
|
||||
// CancelOrderRequest is the argument set for cancel_option_order.
|
||||
@@ -81,7 +88,10 @@ type ExerciseRequest struct {
|
||||
}
|
||||
|
||||
// ExerciseResult is the parsed exercise_option payload.
|
||||
type ExerciseResult struct{}
|
||||
type ExerciseResult struct {
|
||||
ID string `json:"id"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
// CancelExerciseRequest is the argument set for cancel_option_exercise.
|
||||
type CancelExerciseRequest struct {
|
||||
@@ -100,11 +110,18 @@ func (c *Client) ReviewOrder(ctx context.Context, req PlaceOrderRequest) (Review
|
||||
|
||||
// PlaceOrder calls place_option_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, false), &out); err != nil {
|
||||
raw, err := c.c.Call(ctx, toolPlace, placeArgs(req, true, false))
|
||||
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_option_order.
|
||||
@@ -137,11 +154,18 @@ func (c *Client) ReplaceOrder(ctx context.Context, req ReplaceOrderRequest) (Ord
|
||||
if req.OrderID != "" {
|
||||
args["order_id"] = req.OrderID
|
||||
}
|
||||
var out Order
|
||||
if err := c.parse(ctx, toolReplace, args, &out); err != nil {
|
||||
raw, err := c.c.Call(ctx, toolReplace, args)
|
||||
if err != nil {
|
||||
return Order{}, err
|
||||
}
|
||||
return out, nil
|
||||
ords, err := parseOrders(raw)
|
||||
if err != nil {
|
||||
return Order{}, client.ToolErrorf(toolReplace, "parse: %w", err)
|
||||
}
|
||||
if len(ords) > 0 {
|
||||
return ords[0], nil
|
||||
}
|
||||
return Order{}, nil
|
||||
}
|
||||
|
||||
// Exercise calls exercise_option.
|
||||
|
||||
Reference in New Issue
Block a user