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
+33 -10
View File
@@ -40,6 +40,26 @@ func TestPlaceOrder_decimalStrings(t *testing.T) {
if got["ref_id"] != "buy:2026-08-18:MU" {
t.Fatalf("ref %v", got["ref_id"])
}
if _, ok := got["idempotency_key"]; ok {
t.Fatalf("idempotency_key %v", got["idempotency_key"])
}
}
func TestPlaceOrder_ordersEnvelope(t *testing.T) {
t.Parallel()
c := equity.New(client.Func(func(ctx context.Context, name string, args map[string]any) (json.RawMessage, error) {
return json.RawMessage(`{"orders":[{"id":"o2","symbol":"MU","side":"buy","quantity":"3","state":"confirmed"}]}`), nil
}))
got, err := c.PlaceOrder(context.Background(), equity.PlaceOrderRequest{Symbol: "MU"})
if err != nil {
t.Fatal(err)
}
if got.ID != "o2" || got.Symbol != "MU" || got.Side != "buy" || got.State != "confirmed" {
t.Fatalf("%+v", got)
}
if !got.Qty.Equal(decimal.NewFromInt(3)) {
t.Fatalf("qty %s", got.Qty)
}
}
func TestEquity_writeArgs(t *testing.T) {
@@ -98,14 +118,13 @@ func TestEquity_writeArgs(t *testing.T) {
},
wantName: "place_equity_order",
wantArgs: map[string]any{
"account_number": "acct",
"symbol": "MU",
"side": "sell",
"type": "stop_market",
"quantity": "3",
"stop_price": "99.6",
"ref_id": "sell:2026-08-18:MU",
"idempotency_key": "sell:2026-08-18:MU",
"account_number": "acct",
"symbol": "MU",
"side": "sell",
"type": "stop_market",
"quantity": "3",
"stop_price": "99.6",
"ref_id": "sell:2026-08-18:MU",
},
},
{
@@ -135,8 +154,7 @@ func TestEquity_writeArgs(t *testing.T) {
"tax_lots": []map[string]any{
{"open_lot_id": "lot-1", "quantity": "1.5"},
},
"ref_id": "sell:lots",
"idempotency_key": "sell:lots",
"ref_id": "sell:lots",
},
},
{
@@ -182,6 +200,11 @@ func TestEquity_writeArgs(t *testing.T) {
t.Fatalf("time_in_force injected: %+v", gotArgs)
}
}
if tc.wantName == "place_equity_order" {
if _, ok := gotArgs["idempotency_key"]; ok {
t.Fatalf("idempotency_key on place: %+v", gotArgs)
}
}
})
}
}