@nemesis-oss/binance-sdk 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -290,12 +290,331 @@ function derivedTools(client) {
290
290
  ];
291
291
  }
292
292
 
293
- // src/tools/market-data.tools.ts
293
+ // src/tools/execution.tools.ts
294
294
  import { z as z5 } from "zod";
295
295
 
296
- // src/types/market.types.ts
296
+ // src/tools/trading.tools.ts
297
297
  import { z as z4 } from "zod";
298
- var KlineIntervalSchema = z4.enum([
298
+ var symbol2 = z4.string().min(1).describe("USD-M pair, e.g. BTCUSDT");
299
+ var optionalSymbol2 = z4.string().min(1).describe("USD-M pair, e.g. BTCUSDT").optional();
300
+ var limit2 = z4.number().int().positive().max(1e3).default(100);
301
+ var startTime2 = z4.number().int().positive().optional();
302
+ var endTime2 = z4.number().int().positive().optional();
303
+ var side = z4.enum(["BUY", "SELL"]);
304
+ var positionSide = z4.enum(["BOTH", "LONG", "SHORT"]).optional();
305
+ var orderParamsSchema = z4.object({
306
+ symbol: symbol2,
307
+ side,
308
+ type: z4.enum(["LIMIT", "MARKET", "STOP", "STOP_MARKET", "TAKE_PROFIT", "TAKE_PROFIT_MARKET", "TRAILING_STOP_MARKET"]),
309
+ quantity: z4.union([z4.string(), z4.number()]).describe("Order quantity in base asset"),
310
+ price: z4.union([z4.string(), z4.number()]).optional().describe("Required for LIMIT and STOP/TAKE_PROFIT (limit-triggered) types"),
311
+ timeInForce: z4.enum(["GTC", "IOC", "FOK", "GTX"]).optional(),
312
+ stopPrice: z4.union([z4.string(), z4.number()]).optional().describe("Trigger price for STOP/STOP_MARKET/TAKE_PROFIT/TAKE_PROFIT_MARKET"),
313
+ reduceOnly: z4.boolean().optional().describe("true = only reduces the position, never opens"),
314
+ positionSide,
315
+ newClientOrderId: z4.string().optional(),
316
+ closePosition: z4.boolean().optional().describe("Close the full position on trigger (mutually exclusive with quantity)"),
317
+ newOrderRespType: z4.enum(["ACK", "RESULT"]).optional(),
318
+ priceProtect: z4.boolean().optional(),
319
+ workingType: z4.enum(["MARK_PRICE", "CONTRACT_PRICE"]).optional().describe("Trigger price basis; default CONTRACT_PRICE"),
320
+ callbackRate: z4.union([z4.string(), z4.number()]).optional().describe("Percent callback for TRAILING_STOP_MARKET, e.g. 0.5"),
321
+ activationPrice: z4.union([z4.string(), z4.number()]).optional().describe("Activation price for TRAILING_STOP_MARKET"),
322
+ selfTradePreventionMode: z4.enum(["NONE", "EXPIRE_TAKER", "EXPIRE_MAKER", "EXPIRE_BOTH"]).optional(),
323
+ goodTillDate: z4.number().int().optional().describe("Timestamp when a GTD order expires")
324
+ });
325
+ function tradingTools(client) {
326
+ const t = client.futures.trading;
327
+ return [
328
+ {
329
+ name: "futures_new_order",
330
+ description: "Place a new futures order. Types: LIMIT, MARKET, STOP, STOP_MARKET, TAKE_PROFIT, TAKE_PROFIT_MARKET, TRAILING_STOP_MARKET. Use STOP_MARKET as the take-profit/stop-loss trigger and LIMIT for the actual fill. Signed.",
331
+ inputSchema: orderParamsSchema,
332
+ handler: async (args) => textResult(await t.createOrder({ ...args, symbol: normalizeSymbol(args.symbol) }))
333
+ },
334
+ {
335
+ name: "futures_test_order",
336
+ description: "Validate a new order without submitting it. Returns 200 on success; use to validate fields and margin before real orders. Signed.",
337
+ inputSchema: orderParamsSchema,
338
+ handler: async (args) => textResult(await t.createTestOrder({ ...args, symbol: normalizeSymbol(args.symbol) }))
339
+ },
340
+ {
341
+ name: "futures_get_order",
342
+ description: "Query a specific order by orderId or client order id. Signed.",
343
+ inputSchema: z4.object({ symbol: symbol2, orderId: z4.number().int().positive().optional(), origClientOrderId: z4.string().optional() }),
344
+ handler: async ({ symbol: symbol3, orderId, origClientOrderId }) => textResult(await t.getOrder(normalizeSymbol(symbol3), { orderId, origClientOrderId }))
345
+ },
346
+ {
347
+ name: "futures_cancel_order",
348
+ description: "Cancel a specific open order by orderId or client order id. Signed.",
349
+ inputSchema: z4.object({ symbol: symbol2, orderId: z4.number().int().positive().optional(), origClientOrderId: z4.string().optional() }),
350
+ handler: async ({ symbol: symbol3, orderId, origClientOrderId }) => textResult(await t.cancelOrder(normalizeSymbol(symbol3), { orderId, origClientOrderId }))
351
+ },
352
+ {
353
+ name: "futures_get_open_order",
354
+ description: "Query a current open order (must exist in the open order book). Signed.",
355
+ inputSchema: z4.object({ symbol: symbol2, orderId: z4.number().int().positive().optional(), origClientOrderId: z4.string().optional() }),
356
+ handler: async ({ symbol: symbol3, orderId, origClientOrderId }) => textResult(await t.getCurrentOrder(normalizeSymbol(symbol3), { orderId, origClientOrderId }))
357
+ },
358
+ {
359
+ name: "futures_open_orders",
360
+ description: "Get all current open orders, for one symbol or all symbols. Signed.",
361
+ inputSchema: z4.object({ symbol: optionalSymbol2 }),
362
+ handler: async ({ symbol: symbol3 }) => textResult(await t.getOpenOrders(symbol3 ? normalizeSymbol(symbol3) : void 0))
363
+ },
364
+ {
365
+ name: "futures_all_orders",
366
+ description: "Get historical orders for a symbol with optional time range (last 7 days by default). Signed.",
367
+ inputSchema: z4.object({ symbol: symbol2, orderId: z4.number().int().positive().optional(), startTime: startTime2, endTime: endTime2, limit: limit2 }),
368
+ handler: async ({ symbol: symbol3, orderId, startTime: startTime5, endTime: endTime5, limit: limit4 }) => textResult(await t.getAllOrders(normalizeSymbol(symbol3), { orderId, startTime: startTime5, endTime: endTime5, limit: limit4 }))
369
+ },
370
+ {
371
+ name: "futures_cancel_all_orders",
372
+ description: "Cancel all open orders for a symbol. Signed.",
373
+ inputSchema: z4.object({ symbol: symbol2 }),
374
+ handler: async ({ symbol: symbol3 }) => textResult(await t.cancelAllOpenOrders(normalizeSymbol(symbol3)))
375
+ },
376
+ {
377
+ name: "futures_modify_order",
378
+ description: "Modify an open order (price/quantity/stopPrice). Cannot modify when position side is BOTH and closePosition is true. Signed.",
379
+ inputSchema: z4.object({
380
+ symbol: symbol2,
381
+ side,
382
+ quantity: z4.union([z4.string(), z4.number()]),
383
+ price: z4.union([z4.string(), z4.number()]).optional(),
384
+ orderId: z4.number().int().positive().optional(),
385
+ origClientOrderId: z4.string().optional(),
386
+ stopPrice: z4.union([z4.string(), z4.number()]).optional(),
387
+ timeInForce: z4.enum(["GTC", "IOC", "FOK", "GTX"]).optional(),
388
+ positionSide,
389
+ newClientOrderId: z4.string().optional()
390
+ }),
391
+ handler: async (args) => textResult(await t.modifyOrder({ ...args, symbol: normalizeSymbol(args.symbol) }))
392
+ },
393
+ {
394
+ name: "futures_order_modify_history",
395
+ description: "Get order modification history for a symbol. Signed.",
396
+ inputSchema: z4.object({ symbol: symbol2, startTime: startTime2, endTime: endTime2, limit: limit2 }),
397
+ handler: async ({ symbol: symbol3, startTime: startTime5, endTime: endTime5, limit: limit4 }) => textResult(await t.getOrderModifyHistory(normalizeSymbol(symbol3), { startTime: startTime5, endTime: endTime5, limit: limit4 }))
398
+ },
399
+ {
400
+ name: "futures_batch_orders",
401
+ description: "Place up to 5 orders in one request (array of order objects, max 30 per minute per symbol). Signed.",
402
+ inputSchema: z4.object({ orders: z4.array(orderParamsSchema).min(1).max(5) }),
403
+ handler: async (args) => {
404
+ const mapped = args.orders.map((o) => ({ ...o, symbol: normalizeSymbol(o.symbol) }));
405
+ return textResult(await t.createBatchOrders(mapped));
406
+ }
407
+ },
408
+ {
409
+ name: "futures_cancel_batch_orders",
410
+ description: "Cancel multiple orders at once (up to 10 by orderId list or client order id list). Signed.",
411
+ inputSchema: z4.object({
412
+ symbol: symbol2,
413
+ orderIdList: z4.array(z4.number().int().positive()).max(10).optional(),
414
+ origClientOrderIdList: z4.array(z4.string()).max(10).optional()
415
+ }),
416
+ handler: async ({ symbol: symbol3, orderIdList, origClientOrderIdList }) => textResult(await t.cancelBatchOrders(normalizeSymbol(symbol3), { orderIdList, origClientOrderIdList }))
417
+ },
418
+ {
419
+ name: "futures_set_leverage",
420
+ description: "Change initial leverage for a symbol (1-125, within bracket). Signed.",
421
+ inputSchema: z4.object({ symbol: symbol2, leverage: z4.number().int().min(1).max(125) }),
422
+ handler: async ({ symbol: symbol3, leverage }) => textResult(await t.setLeverage(normalizeSymbol(symbol3), leverage))
423
+ },
424
+ {
425
+ name: "futures_set_margin_type",
426
+ description: "Change margin type for a symbol: isolated or cross. Only allowed when no open position for the symbol. Signed.",
427
+ inputSchema: z4.object({ symbol: symbol2, marginType: z4.enum(["isolated", "cross"]) }),
428
+ handler: async ({ symbol: symbol3, marginType }) => textResult(await t.setMarginType(normalizeSymbol(symbol3), marginType))
429
+ },
430
+ {
431
+ name: "futures_modify_position_margin",
432
+ description: "Add or reduce isolated position margin. marginType: 1 = add margin, 2 = reduce margin. Signed.",
433
+ inputSchema: z4.object({ symbol: symbol2, amount: z4.number().positive(), marginType: z4.enum(["1", "2"]).describe("1 = add margin, 2 = reduce margin") }),
434
+ handler: async ({ symbol: symbol3, amount, marginType }) => textResult(await t.modifyPositionMargin(normalizeSymbol(symbol3), amount, Number(marginType)))
435
+ },
436
+ {
437
+ name: "futures_countdown_cancel_all",
438
+ description: "Auto-cancel all open orders for a symbol after countdownTime ms (0 = cancel the countdown). Emergency circuit breaker. Signed.",
439
+ inputSchema: z4.object({ symbol: symbol2, countdownTime: z4.number().int().min(100).max(6e4) }),
440
+ handler: async ({ symbol: symbol3, countdownTime }) => textResult(await t.setCountdownCancelAll(normalizeSymbol(symbol3), countdownTime))
441
+ },
442
+ {
443
+ name: "futures_new_algo_order",
444
+ description: "Place a conditional algo order (CONDITIONAL or VP). CONDITIONAL supports STOP_MARKET/TAKE_PROFIT_MARKET types with triggerPrice; VP is a volume-participation order with urgency and quantity. Signed.",
445
+ inputSchema: z4.object({
446
+ algoType: z4.enum(["CONDITIONAL", "VP"]),
447
+ symbol: symbol2,
448
+ side,
449
+ positionSide,
450
+ type: z4.enum(["STOP_MARKET", "TAKE_PROFIT_MARKET", "LIMIT"]).describe("For CONDITIONAL: STOP_MARKET/TAKE_PROFIT_MARKET. For VP: LIMIT"),
451
+ quantity: z4.union([z4.string(), z4.number()]),
452
+ triggerPrice: z4.union([z4.string(), z4.number()]).optional().describe("Required for CONDITIONAL"),
453
+ price: z4.union([z4.string(), z4.number()]).optional(),
454
+ timeInForce: z4.enum(["GTC", "IOC", "FOK", "GTX"]).optional(),
455
+ workingType: z4.enum(["MARK_PRICE", "CONTRACT_PRICE"]).optional(),
456
+ priceProtect: z4.boolean().optional(),
457
+ reduceOnly: z4.boolean().optional(),
458
+ closePosition: z4.boolean().optional(),
459
+ urgency: z4.enum(["LOW", "MEDIUM", "HIGH"]).optional().describe("Required for VP"),
460
+ clientAlgoId: z4.string().optional()
461
+ }),
462
+ handler: async (args) => textResult(await t.createAlgoOrder({ ...args, symbol: normalizeSymbol(args.symbol) }))
463
+ },
464
+ {
465
+ name: "futures_cancel_algo_order",
466
+ description: "Cancel an open algo order by algoId or clientAlgoId. Signed.",
467
+ inputSchema: z4.object({ symbol: symbol2, algoId: z4.number().int().positive().optional(), clientAlgoId: z4.string().optional() }),
468
+ handler: async ({ symbol: symbol3, algoId, clientAlgoId }) => textResult(await t.cancelAlgoOrder(normalizeSymbol(symbol3), { algoId, clientAlgoId }))
469
+ },
470
+ {
471
+ name: "futures_cancel_all_algo_orders",
472
+ description: "Cancel all open algo orders for a symbol. Signed.",
473
+ inputSchema: z4.object({ symbol: symbol2 }),
474
+ handler: async ({ symbol: symbol3 }) => textResult(await t.cancelAllOpenAlgoOrders(normalizeSymbol(symbol3)))
475
+ },
476
+ {
477
+ name: "futures_get_algo_order",
478
+ description: "Query an algo order by algoId or clientAlgoId. Signed.",
479
+ inputSchema: z4.object({ symbol: symbol2, algoId: z4.number().int().positive().optional(), clientAlgoId: z4.string().optional() }),
480
+ handler: async ({ symbol: symbol3, algoId, clientAlgoId }) => textResult(await t.getAlgoOrder(normalizeSymbol(symbol3), { algoId, clientAlgoId }))
481
+ },
482
+ {
483
+ name: "futures_open_algo_orders",
484
+ description: "Get all current open algo orders, optionally filtered by symbol. Signed.",
485
+ inputSchema: z4.object({ symbol: optionalSymbol2 }),
486
+ handler: async ({ symbol: symbol3 }) => textResult(await t.getOpenAlgoOrders(symbol3 ? normalizeSymbol(symbol3) : void 0))
487
+ },
488
+ {
489
+ name: "futures_all_algo_orders",
490
+ description: "Get historical algo orders for a symbol with optional time range. Signed.",
491
+ inputSchema: z4.object({ symbol: symbol2, startTime: startTime2, endTime: endTime2, limit: limit2 }),
492
+ handler: async ({ symbol: symbol3, startTime: startTime5, endTime: endTime5, limit: limit4 }) => textResult(await t.getAllAlgoOrders(normalizeSymbol(symbol3), { startTime: startTime5, endTime: endTime5, limit: limit4 }))
493
+ },
494
+ {
495
+ name: "futures_convert_exchange_info",
496
+ description: "List asset pairs eligible for futures Convert, optionally filtered by fromAsset/toAsset.",
497
+ inputSchema: z4.object({ fromAsset: z4.string().optional(), toAsset: z4.string().optional() }),
498
+ handler: async ({ fromAsset, toAsset }) => textResult(await t.convertExchangeInfo({ fromAsset, toAsset }))
499
+ },
500
+ {
501
+ name: "futures_convert_get_quote",
502
+ description: "Request a Convert quote between two assets (quote expires quickly; accept with futures_convert_accept_quote). Signed.",
503
+ inputSchema: z4.object({
504
+ fromAsset: z4.string().min(1),
505
+ toAsset: z4.string().min(1),
506
+ fromAmount: z4.number().positive().optional(),
507
+ toAmount: z4.number().positive().optional(),
508
+ validTime: z4.enum(["10s", "30s", "1m", "2m"]).optional()
509
+ }),
510
+ handler: async (args) => textResult(await t.convertGetQuote(args))
511
+ },
512
+ {
513
+ name: "futures_convert_accept_quote",
514
+ description: "Accept a previously requested Convert quote by quoteId. Signed.",
515
+ inputSchema: z4.object({ quoteId: z4.string().min(1) }),
516
+ handler: async ({ quoteId }) => textResult(await t.convertAcceptQuote(quoteId))
517
+ },
518
+ {
519
+ name: "futures_convert_order_status",
520
+ description: "Query the status of a Convert order by orderId or quoteId. Signed.",
521
+ inputSchema: z4.object({ orderId: z4.string().optional(), quoteId: z4.string().optional() }),
522
+ handler: async ({ orderId, quoteId }) => textResult(await t.convertOrderStatus({ orderId, quoteId }))
523
+ }
524
+ ];
525
+ }
526
+
527
+ // src/tools/execution.tools.ts
528
+ var backend = z5.enum(["live", "paper"]).optional().describe("Execution backend for this call; default is the gateway's default backend");
529
+ var intentId = z5.string().min(1).optional().describe(
530
+ "Idempotency key. Re-submitting the same intentId returns the original execution instead of placing a second order. Recommended for any retry loop."
531
+ );
532
+ function executionTools(gateway, client) {
533
+ return [
534
+ {
535
+ name: "execution_place_order",
536
+ description: "Place an order through the execution gateway: idempotent (retry with the same intentId returns the original execution), reconciled on ambiguous failures, and routable to the live exchange or the paper simulator via `backend`. Paper orders need no API keys. MARKET and LIMIT types supported on paper.",
537
+ inputSchema: orderParamsSchema.extend({ intentId, backend }),
538
+ handler: async (args) => {
539
+ const { intentId: intent, backend: route } = args;
540
+ return textResult(
541
+ await gateway.placeOrder(
542
+ { ...args, intentId: intent, symbol: normalizeSymbol(args.symbol) },
543
+ { backend: route }
544
+ )
545
+ );
546
+ }
547
+ },
548
+ {
549
+ name: "execution_cancel_order",
550
+ description: "Cancel an order idempotently by exchange orderId, clientOrderId, or the intentId from execution_place_order. Cancels of already-gone orders resolve to a terminal CANCELED execution (never a thrown -2011).",
551
+ inputSchema: z5.object({
552
+ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
553
+ orderId: z5.number().int().positive().optional().describe("Exchange order id"),
554
+ origClientOrderId: z5.string().optional().describe("Client order id (the reconciliation key)"),
555
+ intentId,
556
+ backend
557
+ }),
558
+ handler: async ({ symbol: symbol3, orderId, origClientOrderId, intentId: intent, backend: route }) => textResult(
559
+ await gateway.cancelOrder(
560
+ normalizeSymbol(symbol3),
561
+ { orderId, origClientOrderId, intentId: intent, backend: route }
562
+ )
563
+ )
564
+ },
565
+ {
566
+ name: "execution_get_order",
567
+ description: "Fetch an execution from the ledger by its intentId. When `backend` is omitted both ledgers are searched (paper first), so callers do not need to remember where an intent ran.",
568
+ inputSchema: z5.object({ intentId: z5.string().min(1), backend }),
569
+ handler: async ({ intentId: intent, backend: route }) => {
570
+ const execution = route ? gateway.getExecution(intent, route) : gateway.getExecution(intent, "paper") ?? gateway.getExecution(intent, "live");
571
+ if (!execution) throw new Error(`No execution for intentId ${intent}`);
572
+ return textResult(execution);
573
+ }
574
+ },
575
+ {
576
+ name: "execution_list_orders",
577
+ description: "List the execution ledger (most recent first) for a backend. Each entry carries status, fills, and reconciliation state. Paper and live ledgers are independent.",
578
+ inputSchema: z5.object({ backend }),
579
+ handler: async ({ backend: route }) => textResult(gateway.listExecutions(route))
580
+ },
581
+ {
582
+ name: "execution_reconcile_order",
583
+ description: "Force a reconciliation pass for an intent whose outcome is unknown (e.g. after a timeout). Recovers the true state from the exchange (live) or simulator (paper) instead of guessing.",
584
+ inputSchema: z5.object({ intentId: z5.string().min(1), backend }),
585
+ handler: async ({ intentId: intent, backend: route }) => textResult(await gateway.reconcile(intent, route))
586
+ },
587
+ {
588
+ name: "execution_status",
589
+ description: "Snapshot of the execution environment: default backend, risk-gateway state (when a trading policy is configured), and the paper simulator account (balance, positions, unrealized PnL). Read-only, never places orders.",
590
+ inputSchema: z5.object({}),
591
+ handler: async () => {
592
+ const risk = client?.getRiskStatus?.();
593
+ const paper = gateway.paperEngine.getAccountInfo();
594
+ return textResult({
595
+ defaultBackend: gateway.backend,
596
+ risk: risk ?? null,
597
+ paper: {
598
+ balance: paper.balance,
599
+ availableBalance: paper.availableBalance,
600
+ totalWalletBalance: paper.totalWalletBalance,
601
+ unrealizedPnl: paper.unrealizedPnl,
602
+ realizedPnl: paper.realizedPnl,
603
+ positions: Object.values(paper.positions).filter((p) => p.quantity > 0),
604
+ orderCount: paper.orders.length
605
+ }
606
+ });
607
+ }
608
+ }
609
+ ];
610
+ }
611
+
612
+ // src/tools/market-data.tools.ts
613
+ import { z as z7 } from "zod";
614
+
615
+ // src/types/market.types.ts
616
+ import { z as z6 } from "zod";
617
+ var KlineIntervalSchema = z6.enum([
299
618
  "1m",
300
619
  "3m",
301
620
  "5m",
@@ -312,19 +631,19 @@ var KlineIntervalSchema = z4.enum([
312
631
  "1w",
313
632
  "1M"
314
633
  ]);
315
- var RawKlineSchema = z4.tuple([
316
- z4.number(),
317
- z4.string(),
318
- z4.string(),
319
- z4.string(),
320
- z4.string(),
321
- z4.string(),
322
- z4.number(),
323
- z4.string(),
324
- z4.number(),
325
- z4.string(),
326
- z4.string(),
327
- z4.string()
634
+ var RawKlineSchema = z6.tuple([
635
+ z6.number(),
636
+ z6.string(),
637
+ z6.string(),
638
+ z6.string(),
639
+ z6.string(),
640
+ z6.string(),
641
+ z6.number(),
642
+ z6.string(),
643
+ z6.number(),
644
+ z6.string(),
645
+ z6.string(),
646
+ z6.string()
328
647
  ]);
329
648
  var KlineSchema = RawKlineSchema.transform(
330
649
  ([openTime, open, high, low, close, volume, closeTime, quoteAssetVolume, trades, takerBuyBaseVolume, takerBuyQuoteVolume]) => ({
@@ -341,87 +660,87 @@ var KlineSchema = RawKlineSchema.transform(
341
660
  takerBuyQuoteVolume: Number(takerBuyQuoteVolume)
342
661
  })
343
662
  );
344
- var KlinesResponseSchema = z4.array(KlineSchema);
345
- var TickerPriceSchema = z4.object({
346
- symbol: z4.string(),
347
- price: z4.string().transform(Number),
348
- time: z4.number().optional()
663
+ var KlinesResponseSchema = z6.array(KlineSchema);
664
+ var TickerPriceSchema = z6.object({
665
+ symbol: z6.string(),
666
+ price: z6.string().transform(Number),
667
+ time: z6.number().optional()
349
668
  });
350
- var Ticker24hrSchema = z4.object({
351
- symbol: z4.string(),
352
- priceChange: z4.string().transform(Number),
353
- priceChangePercent: z4.string().transform(Number),
354
- weightedAvgPrice: z4.string().transform(Number),
355
- lastPrice: z4.string().transform(Number),
356
- lastQty: z4.string().transform(Number),
357
- openPrice: z4.string().transform(Number),
358
- highPrice: z4.string().transform(Number),
359
- lowPrice: z4.string().transform(Number),
360
- volume: z4.string().transform(Number),
361
- quoteVolume: z4.string().transform(Number),
362
- openTime: z4.number(),
363
- closeTime: z4.number(),
364
- firstId: z4.number(),
365
- lastId: z4.number(),
366
- count: z4.number()
669
+ var Ticker24hrSchema = z6.object({
670
+ symbol: z6.string(),
671
+ priceChange: z6.string().transform(Number),
672
+ priceChangePercent: z6.string().transform(Number),
673
+ weightedAvgPrice: z6.string().transform(Number),
674
+ lastPrice: z6.string().transform(Number),
675
+ lastQty: z6.string().transform(Number),
676
+ openPrice: z6.string().transform(Number),
677
+ highPrice: z6.string().transform(Number),
678
+ lowPrice: z6.string().transform(Number),
679
+ volume: z6.string().transform(Number),
680
+ quoteVolume: z6.string().transform(Number),
681
+ openTime: z6.number(),
682
+ closeTime: z6.number(),
683
+ firstId: z6.number(),
684
+ lastId: z6.number(),
685
+ count: z6.number()
367
686
  });
368
- var BookTickerSchema = z4.object({
369
- symbol: z4.string(),
370
- bidPrice: z4.string().transform(Number),
371
- bidQty: z4.string().transform(Number),
372
- askPrice: z4.string().transform(Number),
373
- askQty: z4.string().transform(Number),
374
- time: z4.number().optional()
687
+ var BookTickerSchema = z6.object({
688
+ symbol: z6.string(),
689
+ bidPrice: z6.string().transform(Number),
690
+ bidQty: z6.string().transform(Number),
691
+ askPrice: z6.string().transform(Number),
692
+ askQty: z6.string().transform(Number),
693
+ time: z6.number().optional()
375
694
  });
376
- var DepthLevelSchema = z4.tuple([z4.string(), z4.string()]).transform(([price, qty]) => ({ price: Number(price), qty: Number(qty) }));
377
- var DepthSnapshotSchema = z4.object({
378
- lastUpdateId: z4.number(),
379
- bids: z4.array(DepthLevelSchema),
380
- asks: z4.array(DepthLevelSchema)
695
+ var DepthLevelSchema = z6.tuple([z6.string(), z6.string()]).transform(([price, qty]) => ({ price: Number(price), qty: Number(qty) }));
696
+ var DepthSnapshotSchema = z6.object({
697
+ lastUpdateId: z6.number(),
698
+ bids: z6.array(DepthLevelSchema),
699
+ asks: z6.array(DepthLevelSchema)
381
700
  });
382
- var TradeSchema = z4.object({
383
- id: z4.number(),
384
- price: z4.string().transform(Number),
385
- qty: z4.string().transform(Number),
386
- quoteQty: z4.string().transform(Number),
387
- time: z4.number(),
388
- isBuyerMaker: z4.boolean()
701
+ var TradeSchema = z6.object({
702
+ id: z6.number(),
703
+ price: z6.string().transform(Number),
704
+ qty: z6.string().transform(Number),
705
+ quoteQty: z6.string().transform(Number),
706
+ time: z6.number(),
707
+ isBuyerMaker: z6.boolean()
389
708
  });
390
- var TradesResponseSchema = z4.array(TradeSchema);
391
- var AggTradeSchema = z4.object({
392
- a: z4.number(),
393
- p: z4.string().transform(Number),
394
- q: z4.string().transform(Number),
395
- f: z4.number(),
396
- l: z4.number(),
397
- T: z4.number(),
398
- m: z4.boolean()
709
+ var TradesResponseSchema = z6.array(TradeSchema);
710
+ var AggTradeSchema = z6.object({
711
+ a: z6.number(),
712
+ p: z6.string().transform(Number),
713
+ q: z6.string().transform(Number),
714
+ f: z6.number(),
715
+ l: z6.number(),
716
+ T: z6.number(),
717
+ m: z6.boolean()
399
718
  });
400
- var AggTradesResponseSchema = z4.array(AggTradeSchema);
401
- var AvgPriceSchema = z4.object({
402
- mins: z4.number(),
403
- price: z4.string().transform(Number)
719
+ var AggTradesResponseSchema = z6.array(AggTradeSchema);
720
+ var AvgPriceSchema = z6.object({
721
+ mins: z6.number(),
722
+ price: z6.string().transform(Number)
404
723
  });
405
- var ExchangeSymbolSchema = z4.object({
406
- symbol: z4.string(),
407
- status: z4.string(),
408
- baseAsset: z4.string(),
409
- quoteAsset: z4.string()
724
+ var ExchangeSymbolSchema = z6.object({
725
+ symbol: z6.string(),
726
+ status: z6.string(),
727
+ baseAsset: z6.string(),
728
+ quoteAsset: z6.string()
410
729
  }).loose();
411
- var ExchangeInfoSchema = z4.object({
412
- timezone: z4.string(),
413
- serverTime: z4.number(),
414
- symbols: z4.array(ExchangeSymbolSchema)
730
+ var ExchangeInfoSchema = z6.object({
731
+ timezone: z6.string(),
732
+ serverTime: z6.number(),
733
+ symbols: z6.array(ExchangeSymbolSchema)
415
734
  }).loose();
416
735
 
417
736
  // src/tools/market-data.tools.ts
418
737
  var u = (s) => s.optional();
419
- var optSymbol = u(z5.string().min(1)).describe("USD-M pair, e.g. BTCUSDT");
420
- var limitDefault = z5.number().int().positive().max(1500).default(100);
421
- var startTime2 = z5.number().int().positive().optional();
422
- var endTime2 = z5.number().int().positive().optional();
423
- var period = z5.enum(["5m", "15m", "30m", "1h", "2h", "4h", "6h", "12h", "1d"]).default("1h");
424
- var contractType = z5.enum(["perpetual", "current_quarter", "next_quarter"]).default("perpetual");
738
+ var optSymbol = u(z7.string().min(1)).describe("USD-M pair, e.g. BTCUSDT");
739
+ var limitDefault = z7.number().int().positive().max(1500).default(100);
740
+ var startTime3 = z7.number().int().positive().optional();
741
+ var endTime3 = z7.number().int().positive().optional();
742
+ var period = z7.enum(["5m", "15m", "30m", "1h", "2h", "4h", "6h", "12h", "1d"]).default("1h");
743
+ var contractType = z7.enum(["perpetual", "current_quarter", "next_quarter"]).default("perpetual");
425
744
  function marketDataTools(client) {
426
745
  const m = client.futures.market;
427
746
  const d = client.futures.data;
@@ -429,65 +748,65 @@ function marketDataTools(client) {
429
748
  {
430
749
  name: "futures_ping",
431
750
  description: "Test connectivity to the Binance USD-M futures REST API. Returns empty object {} on success.",
432
- inputSchema: z5.object({}),
751
+ inputSchema: z7.object({}),
433
752
  handler: async () => textResult(await m.ping())
434
753
  },
435
754
  {
436
755
  name: "futures_server_time",
437
756
  description: "Get the current Binance USD-M futures server time in milliseconds since epoch.",
438
- inputSchema: z5.object({}),
757
+ inputSchema: z7.object({}),
439
758
  handler: async () => textResult(await m.serverTime())
440
759
  },
441
760
  {
442
761
  name: "futures_exchange_info",
443
762
  description: "Get exchange trading rules and symbol metadata: contract type, status, base/quote assets, price/quantity filters, tick size, step size, notional and leverage brackets, delivery dates.",
444
- inputSchema: z5.object({}),
763
+ inputSchema: z7.object({}),
445
764
  handler: async () => textResult(await m.exchangeInfo())
446
765
  },
447
766
  {
448
767
  name: "futures_ticker_price",
449
768
  description: "Get latest price for one symbol (v1).",
450
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
769
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
451
770
  handler: async ({ symbol: symbol3 }) => textResult(await m.tickerPrice(normalizeSymbol(symbol3)))
452
771
  },
453
772
  {
454
773
  name: "futures_ticker_price_v2",
455
774
  description: "Get latest price for one symbol, or for all symbols when symbol is omitted (v2 endpoint). Use all-symbols mode for market overviews.",
456
- inputSchema: z5.object({ symbol: optSymbol }),
775
+ inputSchema: z7.object({ symbol: optSymbol }),
457
776
  handler: async ({ symbol: symbol3 }) => textResult(await m.tickerPriceV2(symbol3 ? normalizeSymbol(symbol3) : void 0))
458
777
  },
459
778
  {
460
779
  name: "futures_ticker_24hr",
461
780
  description: "Get 24-hour rolling price change statistics for a symbol: price change %, high, low, volume, quote volume, open interest.",
462
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
781
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
463
782
  handler: async ({ symbol: symbol3 }) => textResult(await m.ticker24hr(normalizeSymbol(symbol3)))
464
783
  },
465
784
  {
466
785
  name: "futures_book_ticker",
467
786
  description: "Get best bid/ask (top of book) for a single symbol (v1).",
468
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
787
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
469
788
  handler: async ({ symbol: symbol3 }) => textResult(await m.bookTicker(normalizeSymbol(symbol3)))
470
789
  },
471
790
  {
472
791
  name: "futures_book_ticker_v2",
473
792
  description: "Get best bid/ask (top of book) for one symbol, or all symbols when omitted (v2 endpoint).",
474
- inputSchema: z5.object({ symbol: optSymbol }),
793
+ inputSchema: z7.object({ symbol: optSymbol }),
475
794
  handler: async ({ symbol: symbol3 }) => textResult(await m.bookTickerV2(symbol3 ? normalizeSymbol(symbol3) : void 0))
476
795
  },
477
796
  {
478
797
  name: "futures_order_book",
479
798
  description: "Get order book depth for a symbol. Limits: 5, 10, 20, 50, 100, 500, 1000.",
480
- inputSchema: z5.object({
481
- symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
482
- limit: z5.enum(["5", "10", "20", "50", "100", "500", "1000"]).default("100")
799
+ inputSchema: z7.object({
800
+ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
801
+ limit: z7.enum(["5", "10", "20", "50", "100", "500", "1000"]).default("100")
483
802
  }),
484
803
  handler: async ({ symbol: symbol3, limit: limit4 }) => textResult(await m.depth(normalizeSymbol(symbol3), Number(limit4)))
485
804
  },
486
805
  {
487
806
  name: "futures_recent_trades",
488
807
  description: "Get the most recent executed trades for a symbol (public endpoint).",
489
- inputSchema: z5.object({
490
- symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
808
+ inputSchema: z7.object({
809
+ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
491
810
  limit: limitDefault.default(500)
492
811
  }),
493
812
  handler: async ({ symbol: symbol3, limit: limit4 }) => textResult(await m.trades(normalizeSymbol(symbol3), Number(limit4)))
@@ -495,184 +814,184 @@ function marketDataTools(client) {
495
814
  {
496
815
  name: "futures_historical_trades",
497
816
  description: "Get older trades for a symbol by fromId (older than recent).",
498
- inputSchema: z5.object({
499
- symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
817
+ inputSchema: z7.object({
818
+ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
500
819
  limit: limitDefault.default(500),
501
- fromId: z5.number().int().positive().optional()
820
+ fromId: z7.number().int().positive().optional()
502
821
  }),
503
822
  handler: async ({ symbol: symbol3, limit: limit4, fromId }) => textResult(await m.historicalTrades(normalizeSymbol(symbol3), { limit: Number(limit4), fromId }))
504
823
  },
505
824
  {
506
825
  name: "futures_agg_trades",
507
826
  description: "Get compressed/aggregate trades for a symbol within an optional time window. Each entry aggregates trades with the same price and side.",
508
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), limit: limitDefault.default(500), startTime: startTime2, endTime: endTime2 }),
827
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), limit: limitDefault.default(500), startTime: startTime3, endTime: endTime3 }),
509
828
  handler: async ({ symbol: symbol3, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await m.aggTrades(normalizeSymbol(symbol3), { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
510
829
  },
511
830
  {
512
831
  name: "futures_klines",
513
832
  description: "Get candlestick (OHLCV) data for a symbol. Intervals: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M. Max 1500 per request.",
514
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), interval: KlineIntervalSchema, limit: limitDefault.default(500), startTime: startTime2, endTime: endTime2 }),
833
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), interval: KlineIntervalSchema, limit: limitDefault.default(500), startTime: startTime3, endTime: endTime3 }),
515
834
  handler: async ({ symbol: symbol3, interval, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await m.klines(normalizeSymbol(symbol3), interval, { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
516
835
  },
517
836
  {
518
837
  name: "futures_continuous_klines",
519
838
  description: "Get klines for a continuous contract (perpetual, current_quarter, next_quarter) identified by base pair (e.g. BTCUSDT).",
520
- inputSchema: z5.object({
521
- symbol: z5.string().min(1).describe("Base pair, e.g. BTCUSDT"),
839
+ inputSchema: z7.object({
840
+ symbol: z7.string().min(1).describe("Base pair, e.g. BTCUSDT"),
522
841
  contractType,
523
842
  interval: KlineIntervalSchema,
524
843
  limit: limitDefault.default(500),
525
- startTime: startTime2,
526
- endTime: endTime2
844
+ startTime: startTime3,
845
+ endTime: endTime3
527
846
  }),
528
847
  handler: async ({ symbol: symbol3, contractType: contractType2, interval, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await m.continuousKlines(normalizeSymbol(symbol3), contractType2, interval, { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
529
848
  },
530
849
  {
531
850
  name: "futures_index_price_klines",
532
851
  description: "Get index price candlesticks for a pair (e.g. BTCUSDT index).",
533
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("Base pair, e.g. BTCUSDT"), interval: KlineIntervalSchema, limit: limitDefault.default(500), startTime: startTime2, endTime: endTime2 }),
852
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("Base pair, e.g. BTCUSDT"), interval: KlineIntervalSchema, limit: limitDefault.default(500), startTime: startTime3, endTime: endTime3 }),
534
853
  handler: async ({ symbol: symbol3, interval, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await m.indexPriceKlines(normalizeSymbol(symbol3), interval, { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
535
854
  },
536
855
  {
537
856
  name: "futures_mark_price_klines",
538
857
  description: "Get mark price candlesticks for a symbol.",
539
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), interval: KlineIntervalSchema, limit: limitDefault.default(500), startTime: startTime2, endTime: endTime2 }),
858
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), interval: KlineIntervalSchema, limit: limitDefault.default(500), startTime: startTime3, endTime: endTime3 }),
540
859
  handler: async ({ symbol: symbol3, interval, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await m.markPriceKlines(normalizeSymbol(symbol3), interval, { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
541
860
  },
542
861
  {
543
862
  name: "futures_trading_day_ticker",
544
863
  description: "Get the trading-day ticker (v1: rolling window stats by symbol, including open, close, high, low, volume, closeTime).",
545
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
864
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
546
865
  handler: async ({ symbol: symbol3 }) => textResult(await m.tradingDayTicker(normalizeSymbol(symbol3)))
547
866
  },
548
867
  {
549
868
  name: "futures_mark_price",
550
869
  description: "Get mark price, index price, estimated settle price, last funding rate, next funding time and interest rate for a symbol.",
551
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
870
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
552
871
  handler: async ({ symbol: symbol3 }) => textResult(await d.premiumIndex(normalizeSymbol(symbol3)))
553
872
  },
554
873
  {
555
874
  name: "futures_funding_rate_history",
556
875
  description: "Get historical funding rates for a symbol.",
557
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), limit: limitDefault.default(100), startTime: startTime2, endTime: endTime2 }),
876
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), limit: limitDefault.default(100), startTime: startTime3, endTime: endTime3 }),
558
877
  handler: async ({ symbol: symbol3, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await d.fundingRateHistory(normalizeSymbol(symbol3), { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
559
878
  },
560
879
  {
561
880
  name: "futures_funding_info",
562
881
  description: "Get funding rate configuration for all symbols with adjusted funding cap/floor or interval (e.g. under extreme volatility).",
563
- inputSchema: z5.object({}),
882
+ inputSchema: z7.object({}),
564
883
  handler: async () => textResult(await d.fundingInfo())
565
884
  },
566
885
  {
567
886
  name: "futures_open_interest",
568
887
  description: "Get the current total open interest for a symbol.",
569
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
888
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
570
889
  handler: async ({ symbol: symbol3 }) => textResult(await d.openInterest(normalizeSymbol(symbol3)))
571
890
  },
572
891
  {
573
892
  name: "futures_open_interest_hist",
574
893
  description: "Get historical open interest statistics per period.",
575
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), period, limit: limitDefault.default(30) }),
894
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), period, limit: limitDefault.default(30) }),
576
895
  handler: async ({ symbol: symbol3, period: period2, limit: limit4 }) => textResult(await d.openInterestHist(normalizeSymbol(symbol3), period2, Number(limit4)))
577
896
  },
578
897
  {
579
898
  name: "futures_top_long_short_account_ratio",
580
899
  description: "Get top trader long/short account ratio (number of accounts) for a symbol.",
581
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), period, limit: limitDefault.default(30) }),
900
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), period, limit: limitDefault.default(30) }),
582
901
  handler: async ({ symbol: symbol3, period: period2, limit: limit4 }) => textResult(await d.topLongShortAccountRatio(normalizeSymbol(symbol3), period2, Number(limit4)))
583
902
  },
584
903
  {
585
904
  name: "futures_top_long_short_position_ratio",
586
905
  description: "Get top trader long/short position ratio (accounts with net positions) for a symbol.",
587
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), period, limit: limitDefault.default(30) }),
906
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), period, limit: limitDefault.default(30) }),
588
907
  handler: async ({ symbol: symbol3, period: period2, limit: limit4 }) => textResult(await d.topLongShortPositionRatio(normalizeSymbol(symbol3), period2, Number(limit4)))
589
908
  },
590
909
  {
591
910
  name: "futures_global_long_short_ratio",
592
911
  description: "Get global long/short account ratio for a symbol (all accounts).",
593
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), period, limit: limitDefault.default(30) }),
912
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), period, limit: limitDefault.default(30) }),
594
913
  handler: async ({ symbol: symbol3, period: period2, limit: limit4 }) => textResult(await d.globalLongShortAccountRatio(normalizeSymbol(symbol3), period2, Number(limit4)))
595
914
  },
596
915
  {
597
916
  name: "futures_taker_long_short_ratio",
598
917
  description: "Get taker buy/sell volume ratio for a symbol.",
599
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), period, limit: limitDefault.default(30) }),
918
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), period, limit: limitDefault.default(30) }),
600
919
  handler: async ({ symbol: symbol3, period: period2, limit: limit4 }) => textResult(await d.takerLongShortRatio(normalizeSymbol(symbol3), period2, Number(limit4)))
601
920
  },
602
921
  {
603
922
  name: "futures_basis",
604
923
  description: "Get basis data (spot-futures spread, mark price - index price) for a pair and contract type.",
605
- inputSchema: z5.object({
606
- symbol: z5.string().min(1).describe("Base pair, e.g. BTCUSDT"),
924
+ inputSchema: z7.object({
925
+ symbol: z7.string().min(1).describe("Base pair, e.g. BTCUSDT"),
607
926
  period,
608
927
  limit: limitDefault.default(30),
609
- startTime: startTime2,
610
- endTime: endTime2
928
+ startTime: startTime3,
929
+ endTime: endTime3
611
930
  }),
612
931
  handler: async ({ symbol: symbol3, period: period2, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await d.basis(normalizeSymbol(symbol3), period2, { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
613
932
  },
614
933
  {
615
934
  name: "futures_asset_index",
616
935
  description: "Get multi-assets mode asset index (collateral price) for one asset or all assets.",
617
- inputSchema: z5.object({ symbol: optSymbol.describe("Asset index symbol, e.g. ADAUSD") }),
936
+ inputSchema: z7.object({ symbol: optSymbol.describe("Asset index symbol, e.g. ADAUSD") }),
618
937
  handler: async ({ symbol: symbol3 }) => textResult(await d.assetIndex(symbol3 ? normalizeSymbol(symbol3) : void 0))
619
938
  },
620
939
  {
621
940
  name: "futures_composite_index_info",
622
941
  description: "Get composite index symbol information (e.g. DEFIUSDT) with constituent weights.",
623
- inputSchema: z5.object({ symbol: optSymbol }),
942
+ inputSchema: z7.object({ symbol: optSymbol }),
624
943
  handler: async ({ symbol: symbol3 }) => textResult(await d.compositeIndexInfo(symbol3 ? normalizeSymbol(symbol3) : void 0))
625
944
  },
626
945
  {
627
946
  name: "futures_insurance_balance",
628
947
  description: "Get insurance fund balance snapshots for a symbol.",
629
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BNBUSDT"), limit: limitDefault.default(100), startTime: startTime2, endTime: endTime2 }),
948
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BNBUSDT"), limit: limitDefault.default(100), startTime: startTime3, endTime: endTime3 }),
630
949
  handler: async ({ symbol: symbol3, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await d.insuranceFundBalance({ symbol: normalizeSymbol(symbol3), limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
631
950
  },
632
951
  {
633
952
  name: "futures_index_price_constituents",
634
953
  description: "Get the index price constituents (exchange weights) for a symbol.",
635
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
954
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
636
955
  handler: async ({ symbol: symbol3 }) => textResult(await d.indexPriceConstituents(normalizeSymbol(symbol3)))
637
956
  },
638
957
  {
639
958
  name: "futures_premium_index_klines",
640
959
  description: "Get premium index candlesticks for a symbol (mark price premium over index price).",
641
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), interval: KlineIntervalSchema, limit: limitDefault.default(500), startTime: startTime2, endTime: endTime2 }),
960
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), interval: KlineIntervalSchema, limit: limitDefault.default(500), startTime: startTime3, endTime: endTime3 }),
642
961
  handler: async ({ symbol: symbol3, interval, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await m.premiumIndexKlines(normalizeSymbol(symbol3), interval, { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
643
962
  },
644
963
  {
645
964
  name: "futures_rpi_depth",
646
965
  description: "Get the RPI (Retail Price Improvement) order book depth for a symbol.",
647
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), limit: z5.number().int().positive().default(1e3) }),
966
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), limit: z7.number().int().positive().default(1e3) }),
648
967
  handler: async ({ symbol: symbol3, limit: limit4 }) => textResult(await m.rpiDepth(normalizeSymbol(symbol3), Number(limit4)))
649
968
  },
650
969
  {
651
970
  name: "futures_delivery_price",
652
971
  description: "Get historical quarterly contract settlement/delivery prices for a pair.",
653
- inputSchema: z5.object({ symbol: z5.string().min(1).describe("Base pair, e.g. BTCUSDT") }),
972
+ inputSchema: z7.object({ symbol: z7.string().min(1).describe("Base pair, e.g. BTCUSDT") }),
654
973
  handler: async ({ symbol: symbol3 }) => textResult(await d.deliveryPrice(normalizeSymbol(symbol3)))
655
974
  },
656
975
  {
657
976
  name: "futures_symbol_adl_risk",
658
977
  description: "Get the auto-deleveraging (ADL) risk level for one symbol or all symbols on the account (signed).",
659
- inputSchema: z5.object({ symbol: optSymbol }),
978
+ inputSchema: z7.object({ symbol: optSymbol }),
660
979
  handler: async ({ symbol: symbol3 }) => textResult(await d.symbolAdlRisk(symbol3 ? normalizeSymbol(symbol3) : void 0))
661
980
  },
662
981
  {
663
982
  name: "futures_adl_quantile",
664
983
  description: "Get the position ADL (auto-deleveraging) quantile estimation for one symbol or all symbols (signed).",
665
- inputSchema: z5.object({ symbol: optSymbol }),
984
+ inputSchema: z7.object({ symbol: optSymbol }),
666
985
  handler: async ({ symbol: symbol3 }) => textResult(await d.adlQuantile(symbol3 ? normalizeSymbol(symbol3) : void 0))
667
986
  },
668
987
  {
669
988
  name: "futures_force_orders",
670
989
  description: "Get the user's force-liquidation orders (LIQUIDATION) and ADL orders for a symbol or all symbols (signed).",
671
- inputSchema: z5.object({
990
+ inputSchema: z7.object({
672
991
  symbol: optSymbol,
673
- autoCloseType: z5.enum(["LIQUIDATION", "ADL"]).optional(),
674
- startTime: startTime2,
675
- endTime: endTime2,
992
+ autoCloseType: z7.enum(["LIQUIDATION", "ADL"]).optional(),
993
+ startTime: startTime3,
994
+ endTime: endTime3,
676
995
  limit: limitDefault.default(50)
677
996
  }),
678
997
  handler: async ({ symbol: symbol3, autoCloseType, startTime: startTime5, endTime: endTime5, limit: limit4 }) => textResult(
@@ -690,7 +1009,7 @@ function marketDataTools(client) {
690
1009
  }
691
1010
 
692
1011
  // src/tools/paper.tools.ts
693
- import { z as z6 } from "zod";
1012
+ import { z as z8 } from "zod";
694
1013
  function createPaperContext(client, initialState = {}) {
695
1014
  return {
696
1015
  client,
@@ -708,7 +1027,7 @@ function paperTools(ctx) {
708
1027
  {
709
1028
  name: "paper_init",
710
1029
  description: "Initialize paper-trading state (reset balances, positions, history). No API keys required.",
711
- inputSchema: z6.object({ balance: z6.number().positive().default(1e4).describe("Starting USDT balance") }),
1030
+ inputSchema: z8.object({ balance: z8.number().positive().default(1e4).describe("Starting USDT balance") }),
712
1031
  handler: async ({ balance }) => {
713
1032
  s.balance = balance;
714
1033
  s.positions = [];
@@ -719,17 +1038,17 @@ function paperTools(ctx) {
719
1038
  {
720
1039
  name: "paper_balance",
721
1040
  description: "Get current paper-trading balance and open-position equity (uses live market prices if an open position exists). No API keys required.",
722
- inputSchema: z6.object({}),
1041
+ inputSchema: z8.object({}),
723
1042
  handler: async () => textResult(s)
724
1043
  },
725
1044
  {
726
1045
  name: "paper_open_position",
727
1046
  description: "Open an in-memory paper position at the live ticker price (or a fixed price). No API keys required.",
728
- inputSchema: z6.object({
729
- symbol: z6.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
730
- side: z6.enum(["LONG", "SHORT"]),
731
- quantity: z6.number().positive(),
732
- price: z6.number().positive().optional().describe("If omitted, uses live ticker price")
1047
+ inputSchema: z8.object({
1048
+ symbol: z8.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
1049
+ side: z8.enum(["LONG", "SHORT"]),
1050
+ quantity: z8.number().positive(),
1051
+ price: z8.number().positive().optional().describe("If omitted, uses live ticker price")
733
1052
  }),
734
1053
  handler: async ({ symbol: symbol3, side: side3, quantity, price }) => {
735
1054
  const sym = normalizeSymbol(symbol3);
@@ -743,10 +1062,10 @@ function paperTools(ctx) {
743
1062
  {
744
1063
  name: "paper_close_position",
745
1064
  description: "Close a paper position by id (or symbol) and realize PnL at the live/last price.",
746
- inputSchema: z6.object({
747
- id: z6.string().optional().describe("Position id from paper_open_position"),
748
- symbol: z6.string().min(1).optional().describe("Close the position for this symbol"),
749
- price: z6.number().positive().optional().describe("If omitted, uses live ticker price")
1065
+ inputSchema: z8.object({
1066
+ id: z8.string().optional().describe("Position id from paper_open_position"),
1067
+ symbol: z8.string().min(1).optional().describe("Close the position for this symbol"),
1068
+ price: z8.number().positive().optional().describe("If omitted, uses live ticker price")
750
1069
  }),
751
1070
  handler: async ({ id, symbol: symbol3, price }) => {
752
1071
  const idx = s.positions.findIndex((p) => id ? p.id === id : normalizeSymbol(p.symbol) === normalizeSymbol(symbol3 ?? ""));
@@ -764,7 +1083,7 @@ function paperTools(ctx) {
764
1083
  {
765
1084
  name: "paper_positions",
766
1085
  description: "List open paper positions with live unrealized PnL (marked to market).",
767
- inputSchema: z6.object({}),
1086
+ inputSchema: z8.object({}),
768
1087
  handler: async () => {
769
1088
  const out = await Promise.all(
770
1089
  s.positions.map(async (p) => {
@@ -778,39 +1097,39 @@ function paperTools(ctx) {
778
1097
  {
779
1098
  name: "paper_history",
780
1099
  description: "List paper-trading history of open/close events with realized PnL.",
781
- inputSchema: z6.object({}),
1100
+ inputSchema: z8.object({}),
782
1101
  handler: async () => textResult(s.history)
783
1102
  },
784
1103
  {
785
1104
  name: "paper_summary",
786
1105
  description: "Summarize paper-trading state: balance, open positions, trade count.",
787
- inputSchema: z6.object({}),
1106
+ inputSchema: z8.object({}),
788
1107
  handler: async () => textResult({ balance: s.balance, openPositions: s.positions.length, trades: s.history.length })
789
1108
  }
790
1109
  ];
791
1110
  }
792
1111
 
793
1112
  // src/tools/spot.tools.ts
794
- import { z as z7 } from "zod";
795
- var spotSymbol = z7.string().min(1).describe("Spot pair, e.g. BTCUSDT");
796
- var optionalSymbol2 = z7.string().min(1).describe("Spot pair, e.g. BTCUSDT").optional();
797
- var limit2 = z7.number().int().positive().max(1e3).default(100);
798
- var startTime3 = z7.number().int().positive().optional();
799
- var endTime3 = z7.number().int().positive().optional();
800
- var side = z7.enum(["BUY", "SELL"]);
801
- var spotOrderParamsSchema = z7.object({
1113
+ import { z as z9 } from "zod";
1114
+ var spotSymbol = z9.string().min(1).describe("Spot pair, e.g. BTCUSDT");
1115
+ var optionalSymbol3 = z9.string().min(1).describe("Spot pair, e.g. BTCUSDT").optional();
1116
+ var limit3 = z9.number().int().positive().max(1e3).default(100);
1117
+ var startTime4 = z9.number().int().positive().optional();
1118
+ var endTime4 = z9.number().int().positive().optional();
1119
+ var side2 = z9.enum(["BUY", "SELL"]);
1120
+ var spotOrderParamsSchema = z9.object({
802
1121
  symbol: spotSymbol,
803
- side,
804
- type: z7.enum(["LIMIT", "MARKET", "LIMIT_MAKER", "STOP_LOSS", "STOP_LOSS_LIMIT", "TAKE_PROFIT", "TAKE_PROFIT_LIMIT"]),
805
- quantity: z7.union([z7.string(), z7.number()]).optional().describe("Base-asset quantity; omit if using quoteOrderQty"),
806
- quoteOrderQty: z7.union([z7.string(), z7.number()]).optional().describe("Quote-asset quantity (e.g. spend 100 USDT on a MARKET order)"),
807
- price: z7.union([z7.string(), z7.number()]).optional().describe("Required for LIMIT / STOP_LOSS_LIMIT / TAKE_PROFIT_LIMIT"),
808
- stopPrice: z7.union([z7.string(), z7.number()]).optional().describe("Trigger price for STOP_LOSS / TAKE_PROFIT variants"),
809
- timeInForce: z7.enum(["GTC", "IOC", "FOK"]).optional().describe("Required for LIMIT"),
810
- newClientOrderId: z7.string().optional(),
811
- newOrderRespType: z7.enum(["ACK", "RESULT", "FULL"]).optional(),
812
- icebergQty: z7.union([z7.string(), z7.number()]).optional(),
813
- selfTradePreventionMode: z7.enum(["NONE", "EXPIRE_TAKER", "EXPIRE_MAKER", "EXPIRE_BOTH"]).optional()
1122
+ side: side2,
1123
+ type: z9.enum(["LIMIT", "MARKET", "LIMIT_MAKER", "STOP_LOSS", "STOP_LOSS_LIMIT", "TAKE_PROFIT", "TAKE_PROFIT_LIMIT"]),
1124
+ quantity: z9.union([z9.string(), z9.number()]).optional().describe("Base-asset quantity; omit if using quoteOrderQty"),
1125
+ quoteOrderQty: z9.union([z9.string(), z9.number()]).optional().describe("Quote-asset quantity (e.g. spend 100 USDT on a MARKET order)"),
1126
+ price: z9.union([z9.string(), z9.number()]).optional().describe("Required for LIMIT / STOP_LOSS_LIMIT / TAKE_PROFIT_LIMIT"),
1127
+ stopPrice: z9.union([z9.string(), z9.number()]).optional().describe("Trigger price for STOP_LOSS / TAKE_PROFIT variants"),
1128
+ timeInForce: z9.enum(["GTC", "IOC", "FOK"]).optional().describe("Required for LIMIT"),
1129
+ newClientOrderId: z9.string().optional(),
1130
+ newOrderRespType: z9.enum(["ACK", "RESULT", "FULL"]).optional(),
1131
+ icebergQty: z9.union([z9.string(), z9.number()]).optional(),
1132
+ selfTradePreventionMode: z9.enum(["NONE", "EXPIRE_TAKER", "EXPIRE_MAKER", "EXPIRE_BOTH"]).optional()
814
1133
  });
815
1134
  function spotTools(client) {
816
1135
  const m = client.spot.market;
@@ -821,128 +1140,128 @@ function spotTools(client) {
821
1140
  {
822
1141
  name: "spot_ping",
823
1142
  description: "Test connectivity to the Binance Spot REST API.",
824
- inputSchema: z7.object({}),
1143
+ inputSchema: z9.object({}),
825
1144
  handler: async () => textResult(await m.ping())
826
1145
  },
827
1146
  {
828
1147
  name: "spot_server_time",
829
1148
  description: "Get the current Binance Spot server time in ms since epoch.",
830
- inputSchema: z7.object({}),
1149
+ inputSchema: z9.object({}),
831
1150
  handler: async () => textResult(await m.serverTime())
832
1151
  },
833
1152
  {
834
1153
  name: "spot_exchange_info",
835
1154
  description: "Get Spot exchange trading rules and symbol metadata (status, base/quote assets, filters, permissions).",
836
- inputSchema: z7.object({}),
1155
+ inputSchema: z9.object({}),
837
1156
  handler: async () => textResult(await m.exchangeInfo())
838
1157
  },
839
1158
  {
840
1159
  name: "spot_ticker_price",
841
1160
  description: "Get the latest price for a Spot symbol.",
842
- inputSchema: z7.object({ symbol: spotSymbol }),
1161
+ inputSchema: z9.object({ symbol: spotSymbol }),
843
1162
  handler: async ({ symbol: symbol3 }) => textResult(await m.tickerPrice(normalizeSymbol(symbol3)))
844
1163
  },
845
1164
  {
846
1165
  name: "spot_ticker_24hr",
847
1166
  description: "Get 24-hour rolling price change statistics for a Spot symbol.",
848
- inputSchema: z7.object({ symbol: spotSymbol }),
1167
+ inputSchema: z9.object({ symbol: spotSymbol }),
849
1168
  handler: async ({ symbol: symbol3 }) => textResult(await m.ticker24hr(normalizeSymbol(symbol3)))
850
1169
  },
851
1170
  {
852
1171
  name: "spot_book_ticker",
853
1172
  description: "Get the best bid/ask (top of book) for a Spot symbol.",
854
- inputSchema: z7.object({ symbol: spotSymbol }),
1173
+ inputSchema: z9.object({ symbol: spotSymbol }),
855
1174
  handler: async ({ symbol: symbol3 }) => textResult(await m.bookTicker(normalizeSymbol(symbol3)))
856
1175
  },
857
1176
  {
858
1177
  name: "spot_order_book",
859
1178
  description: "Get the Spot order book depth for a symbol (limits 5/10/20/50/100/500/1000/5000).",
860
- inputSchema: z7.object({
1179
+ inputSchema: z9.object({
861
1180
  symbol: spotSymbol,
862
- limit: z7.enum(["5", "10", "20", "50", "100", "500", "1000", "5000"]).default("100")
1181
+ limit: z9.enum(["5", "10", "20", "50", "100", "500", "1000", "5000"]).default("100")
863
1182
  }),
864
1183
  handler: async ({ symbol: symbol3, limit: limit4 }) => textResult(await m.depth(normalizeSymbol(symbol3), Number(limit4)))
865
1184
  },
866
1185
  {
867
1186
  name: "spot_recent_trades",
868
1187
  description: "Get the most recent executed trades for a Spot symbol.",
869
- inputSchema: z7.object({ symbol: spotSymbol, limit: limit2.default(500) }),
1188
+ inputSchema: z9.object({ symbol: spotSymbol, limit: limit3.default(500) }),
870
1189
  handler: async ({ symbol: symbol3, limit: limit4 }) => textResult(await m.trades(normalizeSymbol(symbol3), Number(limit4)))
871
1190
  },
872
1191
  {
873
1192
  name: "spot_historical_trades",
874
1193
  description: "Get older Spot trades for a symbol by fromId.",
875
- inputSchema: z7.object({ symbol: spotSymbol, limit: limit2.default(500), fromId: z7.number().int().positive().optional() }),
1194
+ inputSchema: z9.object({ symbol: spotSymbol, limit: limit3.default(500), fromId: z9.number().int().positive().optional() }),
876
1195
  handler: async ({ symbol: symbol3, limit: limit4, fromId }) => textResult(await m.historicalTrades(normalizeSymbol(symbol3), { limit: Number(limit4), fromId }))
877
1196
  },
878
1197
  {
879
1198
  name: "spot_agg_trades",
880
1199
  description: "Get compressed/aggregate Spot trades for a symbol within an optional time window.",
881
- inputSchema: z7.object({ symbol: spotSymbol, limit: limit2.default(500), startTime: startTime3, endTime: endTime3 }),
1200
+ inputSchema: z9.object({ symbol: spotSymbol, limit: limit3.default(500), startTime: startTime4, endTime: endTime4 }),
882
1201
  handler: async ({ symbol: symbol3, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await m.aggTrades(normalizeSymbol(symbol3), { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
883
1202
  },
884
1203
  {
885
1204
  name: "spot_klines",
886
1205
  description: "Get Spot candlesticks (OHLCV). Intervals 1m\u20261M; max 1000 per request.",
887
- inputSchema: z7.object({ symbol: spotSymbol, interval: KlineIntervalSchema, limit: limit2.default(500), startTime: startTime3, endTime: endTime3 }),
1206
+ inputSchema: z9.object({ symbol: spotSymbol, interval: KlineIntervalSchema, limit: limit3.default(500), startTime: startTime4, endTime: endTime4 }),
888
1207
  handler: async ({ symbol: symbol3, interval, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await m.klines(normalizeSymbol(symbol3), interval, { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
889
1208
  },
890
1209
  {
891
1210
  name: "spot_ui_klines",
892
1211
  description: "Get Spot candlesticks via the optimized uiKlines endpoint (same shape as spot_klines).",
893
- inputSchema: z7.object({ symbol: spotSymbol, interval: KlineIntervalSchema, limit: limit2.default(500), startTime: startTime3, endTime: endTime3 }),
1212
+ inputSchema: z9.object({ symbol: spotSymbol, interval: KlineIntervalSchema, limit: limit3.default(500), startTime: startTime4, endTime: endTime4 }),
894
1213
  handler: async ({ symbol: symbol3, interval, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await m.uiKlines(normalizeSymbol(symbol3), interval, { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
895
1214
  },
896
1215
  {
897
1216
  name: "spot_avg_price",
898
1217
  description: "Get the current average price (5-minute rolling average) for a Spot symbol.",
899
- inputSchema: z7.object({ symbol: spotSymbol }),
1218
+ inputSchema: z9.object({ symbol: spotSymbol }),
900
1219
  handler: async ({ symbol: symbol3 }) => textResult(await m.avgPrice(normalizeSymbol(symbol3)))
901
1220
  },
902
1221
  {
903
1222
  name: "spot_rolling_window_ticker",
904
1223
  description: "Get rolling-window price change statistics (1d/7d/30d). Omit symbol for all symbols.",
905
- inputSchema: z7.object({
906
- symbol: optionalSymbol2,
907
- windowSize: z7.enum(["1d", "7d", "30d"]).optional()
1224
+ inputSchema: z9.object({
1225
+ symbol: optionalSymbol3,
1226
+ windowSize: z9.enum(["1d", "7d", "30d"]).optional()
908
1227
  }),
909
1228
  handler: async ({ symbol: symbol3, windowSize }) => textResult(await m.rollingWindowTicker(symbol3 ? normalizeSymbol(symbol3) : void 0, windowSize))
910
1229
  },
911
1230
  {
912
1231
  name: "spot_trading_day_ticker",
913
1232
  description: "Get the Spot trading-day ticker (open/close/high/low/volume by UTC day). Omit symbol for all symbols.",
914
- inputSchema: z7.object({ symbol: optionalSymbol2, timeZone: z7.string().optional(), type: z7.enum(["FULL", "MINI"]).optional() }),
1233
+ inputSchema: z9.object({ symbol: optionalSymbol3, timeZone: z9.string().optional(), type: z9.enum(["FULL", "MINI"]).optional() }),
915
1234
  handler: async ({ symbol: symbol3, timeZone, type }) => textResult(await m.tradingDayTicker(symbol3 ? normalizeSymbol(symbol3) : void 0, { timeZone, type }))
916
1235
  },
917
1236
  // ---- Account (signed) ----
918
1237
  {
919
1238
  name: "spot_account",
920
1239
  description: "Get the Spot account: balances (free/locked), commissions, permissions (signed).",
921
- inputSchema: z7.object({}),
1240
+ inputSchema: z9.object({}),
922
1241
  handler: async () => textResult(await a.account())
923
1242
  },
924
1243
  {
925
1244
  name: "spot_my_trades",
926
1245
  description: "Get the Spot account trade list (filled trades) for a symbol with optional time range (signed).",
927
- inputSchema: z7.object({ symbol: spotSymbol, orderId: z7.number().int().positive().optional(), startTime: startTime3, endTime: endTime3, fromId: z7.number().int().positive().optional(), limit: limit2.default(500) }),
1246
+ inputSchema: z9.object({ symbol: spotSymbol, orderId: z9.number().int().positive().optional(), startTime: startTime4, endTime: endTime4, fromId: z9.number().int().positive().optional(), limit: limit3.default(500) }),
928
1247
  handler: async ({ symbol: symbol3, orderId, startTime: startTime5, endTime: endTime5, fromId, limit: limit4 }) => textResult(await a.myTrades(normalizeSymbol(symbol3), { orderId, startTime: startTime5, endTime: endTime5, fromId, limit: Number(limit4) }))
929
1248
  },
930
1249
  {
931
1250
  name: "spot_my_prevented_matches",
932
1251
  description: "Get Spot orders that were expired by the self-trade-prevention (STP) mechanism (signed).",
933
- inputSchema: z7.object({ symbol: spotSymbol, preventedMatchId: z7.number().int().positive().optional(), orderId: z7.number().int().positive().optional(), limit: limit2.default(500) }),
1252
+ inputSchema: z9.object({ symbol: spotSymbol, preventedMatchId: z9.number().int().positive().optional(), orderId: z9.number().int().positive().optional(), limit: limit3.default(500) }),
934
1253
  handler: async ({ symbol: symbol3, preventedMatchId, orderId, limit: limit4 }) => textResult(await a.myPreventedMatches(normalizeSymbol(symbol3), { preventedMatchId, orderId, limit: Number(limit4) }))
935
1254
  },
936
1255
  {
937
1256
  name: "spot_account_commission",
938
1257
  description: "Get the Spot account commission rates for a symbol (signed).",
939
- inputSchema: z7.object({ symbol: spotSymbol }),
1258
+ inputSchema: z9.object({ symbol: spotSymbol }),
940
1259
  handler: async ({ symbol: symbol3 }) => textResult(await a.accountCommission(normalizeSymbol(symbol3)))
941
1260
  },
942
1261
  {
943
1262
  name: "spot_rate_limit_order",
944
1263
  description: "Query the current Spot order rate limit usage (signed).",
945
- inputSchema: z7.object({}),
1264
+ inputSchema: z9.object({}),
946
1265
  handler: async () => textResult(await a.rateLimitOrder())
947
1266
  },
948
1267
  // ---- Trading (signed) ----
@@ -961,109 +1280,109 @@ function spotTools(client) {
961
1280
  {
962
1281
  name: "spot_get_order",
963
1282
  description: "Query a specific Spot order by orderId or client order id. Signed.",
964
- inputSchema: z7.object({ symbol: spotSymbol, orderId: z7.number().int().positive().optional(), origClientOrderId: z7.string().optional() }),
1283
+ inputSchema: z9.object({ symbol: spotSymbol, orderId: z9.number().int().positive().optional(), origClientOrderId: z9.string().optional() }),
965
1284
  handler: async ({ symbol: symbol3, orderId, origClientOrderId }) => textResult(await t.getOrder(normalizeSymbol(symbol3), { orderId, origClientOrderId }))
966
1285
  },
967
1286
  {
968
1287
  name: "spot_cancel_order",
969
1288
  description: "Cancel a specific open Spot order by orderId or client order id. Signed.",
970
- inputSchema: z7.object({ symbol: spotSymbol, orderId: z7.number().int().positive().optional(), origClientOrderId: z7.string().optional(), newClientOrderId: z7.string().optional() }),
1289
+ inputSchema: z9.object({ symbol: spotSymbol, orderId: z9.number().int().positive().optional(), origClientOrderId: z9.string().optional(), newClientOrderId: z9.string().optional() }),
971
1290
  handler: async ({ symbol: symbol3, orderId, origClientOrderId, newClientOrderId }) => textResult(await t.cancelOrder(normalizeSymbol(symbol3), { orderId, origClientOrderId, newClientOrderId }))
972
1291
  },
973
1292
  {
974
1293
  name: "spot_open_orders",
975
1294
  description: "Get all current open Spot orders, for one symbol or all symbols. Signed.",
976
- inputSchema: z7.object({ symbol: optionalSymbol2 }),
1295
+ inputSchema: z9.object({ symbol: optionalSymbol3 }),
977
1296
  handler: async ({ symbol: symbol3 }) => textResult(await t.getOpenOrders(symbol3 ? normalizeSymbol(symbol3) : void 0))
978
1297
  },
979
1298
  {
980
1299
  name: "spot_all_orders",
981
1300
  description: "Get historical Spot orders for a symbol with optional time range. Signed.",
982
- inputSchema: z7.object({ symbol: spotSymbol, orderId: z7.number().int().positive().optional(), startTime: startTime3, endTime: endTime3, limit: limit2 }),
1301
+ inputSchema: z9.object({ symbol: spotSymbol, orderId: z9.number().int().positive().optional(), startTime: startTime4, endTime: endTime4, limit: limit3 }),
983
1302
  handler: async ({ symbol: symbol3, orderId, startTime: startTime5, endTime: endTime5, limit: limit4 }) => textResult(await t.getAllOrders(normalizeSymbol(symbol3), { orderId, startTime: startTime5, endTime: endTime5, limit: limit4 }))
984
1303
  },
985
1304
  {
986
1305
  name: "spot_cancel_open_orders",
987
1306
  description: "Cancel all open Spot orders for a symbol. Signed.",
988
- inputSchema: z7.object({ symbol: spotSymbol }),
1307
+ inputSchema: z9.object({ symbol: spotSymbol }),
989
1308
  handler: async ({ symbol: symbol3 }) => textResult(await t.cancelOpenOrders(normalizeSymbol(symbol3)))
990
1309
  },
991
1310
  {
992
1311
  name: "spot_cancel_replace_order",
993
1312
  description: "Cancel an existing Spot order and place a new one on the same symbol (cancel-replace). Signed.",
994
- inputSchema: z7.object({
1313
+ inputSchema: z9.object({
995
1314
  symbol: spotSymbol,
996
- side,
997
- type: z7.enum(["LIMIT", "MARKET", "STOP_LOSS", "STOP_LOSS_LIMIT", "TAKE_PROFIT", "TAKE_PROFIT_LIMIT"]),
998
- cancelReplaceMode: z7.enum(["STOP_ON_FAILURE", "ALLOW_FAILURE"]).default("STOP_ON_FAILURE"),
999
- cancelOrderId: z7.number().int().positive().optional(),
1000
- cancelOrigClientOrderId: z7.string().optional(),
1001
- cancelNewClientOrderId: z7.string().optional(),
1002
- quantity: z7.union([z7.string(), z7.number()]).optional(),
1003
- price: z7.union([z7.string(), z7.number()]).optional(),
1004
- timeInForce: z7.enum(["GTC", "IOC", "FOK"]).optional(),
1005
- newClientOrderId: z7.string().optional()
1315
+ side: side2,
1316
+ type: z9.enum(["LIMIT", "MARKET", "STOP_LOSS", "STOP_LOSS_LIMIT", "TAKE_PROFIT", "TAKE_PROFIT_LIMIT"]),
1317
+ cancelReplaceMode: z9.enum(["STOP_ON_FAILURE", "ALLOW_FAILURE"]).default("STOP_ON_FAILURE"),
1318
+ cancelOrderId: z9.number().int().positive().optional(),
1319
+ cancelOrigClientOrderId: z9.string().optional(),
1320
+ cancelNewClientOrderId: z9.string().optional(),
1321
+ quantity: z9.union([z9.string(), z9.number()]).optional(),
1322
+ price: z9.union([z9.string(), z9.number()]).optional(),
1323
+ timeInForce: z9.enum(["GTC", "IOC", "FOK"]).optional(),
1324
+ newClientOrderId: z9.string().optional()
1006
1325
  }),
1007
1326
  handler: async (args) => textResult(await t.cancelReplaceOrder({ ...args, symbol: normalizeSymbol(args.symbol) }))
1008
1327
  },
1009
1328
  {
1010
1329
  name: "spot_new_oco_order",
1011
1330
  description: "Place a new Spot OCO (one-cancels-other) order: a stop-loss limit + a limit-maker take-profit. Signed.",
1012
- inputSchema: z7.object({
1331
+ inputSchema: z9.object({
1013
1332
  symbol: spotSymbol,
1014
- side,
1015
- quantity: z7.union([z7.string(), z7.number()]).describe("Total base-asset quantity for both legs"),
1016
- price: z7.union([z7.string(), z7.number()]).describe("Limit (take-profit) price"),
1017
- stopPrice: z7.union([z7.string(), z7.number()]).describe("Stop-loss trigger price"),
1018
- stopLimitPrice: z7.union([z7.string(), z7.number()]).optional().describe("Stop-loss limit price (defaults to stopPrice)"),
1019
- stopLimitTimeInForce: z7.enum(["GTC", "IOC", "FOK"]).optional(),
1020
- listClientOrderId: z7.string().optional(),
1021
- limitClientOrderId: z7.string().optional(),
1022
- stopClientOrderId: z7.string().optional()
1333
+ side: side2,
1334
+ quantity: z9.union([z9.string(), z9.number()]).describe("Total base-asset quantity for both legs"),
1335
+ price: z9.union([z9.string(), z9.number()]).describe("Limit (take-profit) price"),
1336
+ stopPrice: z9.union([z9.string(), z9.number()]).describe("Stop-loss trigger price"),
1337
+ stopLimitPrice: z9.union([z9.string(), z9.number()]).optional().describe("Stop-loss limit price (defaults to stopPrice)"),
1338
+ stopLimitTimeInForce: z9.enum(["GTC", "IOC", "FOK"]).optional(),
1339
+ listClientOrderId: z9.string().optional(),
1340
+ limitClientOrderId: z9.string().optional(),
1341
+ stopClientOrderId: z9.string().optional()
1023
1342
  }),
1024
1343
  handler: async (args) => textResult(await t.createOCOOrder({ ...args, symbol: normalizeSymbol(args.symbol) }))
1025
1344
  },
1026
1345
  {
1027
1346
  name: "spot_cancel_oco_order",
1028
1347
  description: "Cancel an entire Spot OCO order list by orderListId or listClientOrderId. Signed.",
1029
- inputSchema: z7.object({ symbol: spotSymbol, orderListId: z7.number().int().positive().optional(), listClientOrderId: z7.string().optional(), newClientOrderId: z7.string().optional() }),
1348
+ inputSchema: z9.object({ symbol: spotSymbol, orderListId: z9.number().int().positive().optional(), listClientOrderId: z9.string().optional(), newClientOrderId: z9.string().optional() }),
1030
1349
  handler: async ({ symbol: symbol3, orderListId, listClientOrderId, newClientOrderId }) => textResult(await t.cancelOCOOrder(normalizeSymbol(symbol3), { orderListId, listClientOrderId, newClientOrderId }))
1031
1350
  },
1032
1351
  {
1033
1352
  name: "spot_get_oco_order",
1034
1353
  description: "Query a Spot OCO order list by orderListId or listClientOrderId. Signed.",
1035
- inputSchema: z7.object({ symbol: spotSymbol, orderListId: z7.number().int().positive().optional(), origClientOrderId: z7.string().optional() }),
1354
+ inputSchema: z9.object({ symbol: spotSymbol, orderListId: z9.number().int().positive().optional(), origClientOrderId: z9.string().optional() }),
1036
1355
  handler: async ({ symbol: symbol3, orderListId, origClientOrderId }) => textResult(await t.getOCOOrder(normalizeSymbol(symbol3), { orderListId, origClientOrderId }))
1037
1356
  },
1038
1357
  {
1039
1358
  name: "spot_open_oco_orders",
1040
1359
  description: "Get all current open Spot OCO order lists. Signed.",
1041
- inputSchema: z7.object({}),
1360
+ inputSchema: z9.object({}),
1042
1361
  handler: async () => textResult(await t.getOpenOCOOrders())
1043
1362
  },
1044
1363
  {
1045
1364
  name: "spot_all_oco_orders",
1046
1365
  description: "Get historical Spot OCO order lists for a symbol with optional time range. Signed.",
1047
- inputSchema: z7.object({ symbol: spotSymbol, fromId: z7.number().int().positive().optional(), startTime: startTime3, endTime: endTime3, limit: limit2 }),
1366
+ inputSchema: z9.object({ symbol: spotSymbol, fromId: z9.number().int().positive().optional(), startTime: startTime4, endTime: endTime4, limit: limit3 }),
1048
1367
  handler: async ({ symbol: symbol3, fromId, startTime: startTime5, endTime: endTime5, limit: limit4 }) => textResult(await t.getAllOCOOrders(normalizeSymbol(symbol3), { fromId, startTime: startTime5, endTime: endTime5, limit: limit4 }))
1049
1368
  },
1050
1369
  {
1051
1370
  name: "spot_cancel_open_oco_orders",
1052
1371
  description: "Cancel all open Spot OCO order lists for a symbol. Signed.",
1053
- inputSchema: z7.object({ symbol: spotSymbol }),
1372
+ inputSchema: z9.object({ symbol: spotSymbol }),
1054
1373
  handler: async ({ symbol: symbol3 }) => textResult(await t.cancelOpenOCOOrders(normalizeSymbol(symbol3)))
1055
1374
  },
1056
1375
  // ---- User data stream (signed) ----
1057
1376
  {
1058
1377
  name: "spot_ws_start_user_stream",
1059
1378
  description: "Start the Spot user data stream: creates a listenKey, connects the private WebSocket, and begins keep-alive. Emits executionReport, outboundAccountPosition, balanceUpdate, listStatus.",
1060
- inputSchema: z7.object({}),
1379
+ inputSchema: z9.object({}),
1061
1380
  handler: async () => textResult({ listenKey: await client.startSpotUserStream() })
1062
1381
  },
1063
1382
  {
1064
1383
  name: "spot_ws_stop_user_stream",
1065
1384
  description: "Stop the Spot user data stream: closes the private WebSocket and invalidates the listenKey.",
1066
- inputSchema: z7.object({}),
1385
+ inputSchema: z9.object({}),
1067
1386
  handler: async () => {
1068
1387
  client.closeSpotUserStream();
1069
1388
  return textResult({ stopped: true });
@@ -1073,239 +1392,8 @@ function spotTools(client) {
1073
1392
  return tools;
1074
1393
  }
1075
1394
 
1076
- // src/tools/trading.tools.ts
1077
- import { z as z8 } from "zod";
1078
- var symbol2 = z8.string().min(1).describe("USD-M pair, e.g. BTCUSDT");
1079
- var optionalSymbol3 = z8.string().min(1).describe("USD-M pair, e.g. BTCUSDT").optional();
1080
- var limit3 = z8.number().int().positive().max(1e3).default(100);
1081
- var startTime4 = z8.number().int().positive().optional();
1082
- var endTime4 = z8.number().int().positive().optional();
1083
- var side2 = z8.enum(["BUY", "SELL"]);
1084
- var positionSide = z8.enum(["BOTH", "LONG", "SHORT"]).optional();
1085
- var orderParamsSchema = z8.object({
1086
- symbol: symbol2,
1087
- side: side2,
1088
- type: z8.enum(["LIMIT", "MARKET", "STOP", "STOP_MARKET", "TAKE_PROFIT", "TAKE_PROFIT_MARKET", "TRAILING_STOP_MARKET"]),
1089
- quantity: z8.union([z8.string(), z8.number()]).describe("Order quantity in base asset"),
1090
- price: z8.union([z8.string(), z8.number()]).optional().describe("Required for LIMIT and STOP/TAKE_PROFIT (limit-triggered) types"),
1091
- timeInForce: z8.enum(["GTC", "IOC", "FOK", "GTX"]).optional(),
1092
- stopPrice: z8.union([z8.string(), z8.number()]).optional().describe("Trigger price for STOP/STOP_MARKET/TAKE_PROFIT/TAKE_PROFIT_MARKET"),
1093
- reduceOnly: z8.boolean().optional().describe("true = only reduces the position, never opens"),
1094
- positionSide,
1095
- newClientOrderId: z8.string().optional(),
1096
- closePosition: z8.boolean().optional().describe("Close the full position on trigger (mutually exclusive with quantity)"),
1097
- newOrderRespType: z8.enum(["ACK", "RESULT"]).optional(),
1098
- priceProtect: z8.boolean().optional(),
1099
- workingType: z8.enum(["MARK_PRICE", "CONTRACT_PRICE"]).optional().describe("Trigger price basis; default CONTRACT_PRICE"),
1100
- callbackRate: z8.union([z8.string(), z8.number()]).optional().describe("Percent callback for TRAILING_STOP_MARKET, e.g. 0.5"),
1101
- activationPrice: z8.union([z8.string(), z8.number()]).optional().describe("Activation price for TRAILING_STOP_MARKET"),
1102
- selfTradePreventionMode: z8.enum(["NONE", "EXPIRE_TAKER", "EXPIRE_MAKER", "EXPIRE_BOTH"]).optional(),
1103
- goodTillDate: z8.number().int().optional().describe("Timestamp when a GTD order expires")
1104
- });
1105
- function tradingTools(client) {
1106
- const t = client.futures.trading;
1107
- return [
1108
- {
1109
- name: "futures_new_order",
1110
- description: "Place a new futures order. Types: LIMIT, MARKET, STOP, STOP_MARKET, TAKE_PROFIT, TAKE_PROFIT_MARKET, TRAILING_STOP_MARKET. Use STOP_MARKET as the take-profit/stop-loss trigger and LIMIT for the actual fill. Signed.",
1111
- inputSchema: orderParamsSchema,
1112
- handler: async (args) => textResult(await t.createOrder({ ...args, symbol: normalizeSymbol(args.symbol) }))
1113
- },
1114
- {
1115
- name: "futures_test_order",
1116
- description: "Validate a new order without submitting it. Returns 200 on success; use to validate fields and margin before real orders. Signed.",
1117
- inputSchema: orderParamsSchema,
1118
- handler: async (args) => textResult(await t.createTestOrder({ ...args, symbol: normalizeSymbol(args.symbol) }))
1119
- },
1120
- {
1121
- name: "futures_get_order",
1122
- description: "Query a specific order by orderId or client order id. Signed.",
1123
- inputSchema: z8.object({ symbol: symbol2, orderId: z8.number().int().positive().optional(), origClientOrderId: z8.string().optional() }),
1124
- handler: async ({ symbol: symbol3, orderId, origClientOrderId }) => textResult(await t.getOrder(normalizeSymbol(symbol3), { orderId, origClientOrderId }))
1125
- },
1126
- {
1127
- name: "futures_cancel_order",
1128
- description: "Cancel a specific open order by orderId or client order id. Signed.",
1129
- inputSchema: z8.object({ symbol: symbol2, orderId: z8.number().int().positive().optional(), origClientOrderId: z8.string().optional() }),
1130
- handler: async ({ symbol: symbol3, orderId, origClientOrderId }) => textResult(await t.cancelOrder(normalizeSymbol(symbol3), { orderId, origClientOrderId }))
1131
- },
1132
- {
1133
- name: "futures_get_open_order",
1134
- description: "Query a current open order (must exist in the open order book). Signed.",
1135
- inputSchema: z8.object({ symbol: symbol2, orderId: z8.number().int().positive().optional(), origClientOrderId: z8.string().optional() }),
1136
- handler: async ({ symbol: symbol3, orderId, origClientOrderId }) => textResult(await t.getCurrentOrder(normalizeSymbol(symbol3), { orderId, origClientOrderId }))
1137
- },
1138
- {
1139
- name: "futures_open_orders",
1140
- description: "Get all current open orders, for one symbol or all symbols. Signed.",
1141
- inputSchema: z8.object({ symbol: optionalSymbol3 }),
1142
- handler: async ({ symbol: symbol3 }) => textResult(await t.getOpenOrders(symbol3 ? normalizeSymbol(symbol3) : void 0))
1143
- },
1144
- {
1145
- name: "futures_all_orders",
1146
- description: "Get historical orders for a symbol with optional time range (last 7 days by default). Signed.",
1147
- inputSchema: z8.object({ symbol: symbol2, orderId: z8.number().int().positive().optional(), startTime: startTime4, endTime: endTime4, limit: limit3 }),
1148
- handler: async ({ symbol: symbol3, orderId, startTime: startTime5, endTime: endTime5, limit: limit4 }) => textResult(await t.getAllOrders(normalizeSymbol(symbol3), { orderId, startTime: startTime5, endTime: endTime5, limit: limit4 }))
1149
- },
1150
- {
1151
- name: "futures_cancel_all_orders",
1152
- description: "Cancel all open orders for a symbol. Signed.",
1153
- inputSchema: z8.object({ symbol: symbol2 }),
1154
- handler: async ({ symbol: symbol3 }) => textResult(await t.cancelAllOpenOrders(normalizeSymbol(symbol3)))
1155
- },
1156
- {
1157
- name: "futures_modify_order",
1158
- description: "Modify an open order (price/quantity/stopPrice). Cannot modify when position side is BOTH and closePosition is true. Signed.",
1159
- inputSchema: z8.object({
1160
- symbol: symbol2,
1161
- side: side2,
1162
- quantity: z8.union([z8.string(), z8.number()]),
1163
- price: z8.union([z8.string(), z8.number()]).optional(),
1164
- orderId: z8.number().int().positive().optional(),
1165
- origClientOrderId: z8.string().optional(),
1166
- stopPrice: z8.union([z8.string(), z8.number()]).optional(),
1167
- timeInForce: z8.enum(["GTC", "IOC", "FOK", "GTX"]).optional(),
1168
- positionSide,
1169
- newClientOrderId: z8.string().optional()
1170
- }),
1171
- handler: async (args) => textResult(await t.modifyOrder({ ...args, symbol: normalizeSymbol(args.symbol) }))
1172
- },
1173
- {
1174
- name: "futures_order_modify_history",
1175
- description: "Get order modification history for a symbol. Signed.",
1176
- inputSchema: z8.object({ symbol: symbol2, startTime: startTime4, endTime: endTime4, limit: limit3 }),
1177
- handler: async ({ symbol: symbol3, startTime: startTime5, endTime: endTime5, limit: limit4 }) => textResult(await t.getOrderModifyHistory(normalizeSymbol(symbol3), { startTime: startTime5, endTime: endTime5, limit: limit4 }))
1178
- },
1179
- {
1180
- name: "futures_batch_orders",
1181
- description: "Place up to 5 orders in one request (array of order objects, max 30 per minute per symbol). Signed.",
1182
- inputSchema: z8.object({ orders: z8.array(orderParamsSchema).min(1).max(5) }),
1183
- handler: async (args) => {
1184
- const mapped = args.orders.map((o) => ({ ...o, symbol: normalizeSymbol(o.symbol) }));
1185
- return textResult(await t.createBatchOrders(mapped));
1186
- }
1187
- },
1188
- {
1189
- name: "futures_cancel_batch_orders",
1190
- description: "Cancel multiple orders at once (up to 10 by orderId list or client order id list). Signed.",
1191
- inputSchema: z8.object({
1192
- symbol: symbol2,
1193
- orderIdList: z8.array(z8.number().int().positive()).max(10).optional(),
1194
- origClientOrderIdList: z8.array(z8.string()).max(10).optional()
1195
- }),
1196
- handler: async ({ symbol: symbol3, orderIdList, origClientOrderIdList }) => textResult(await t.cancelBatchOrders(normalizeSymbol(symbol3), { orderIdList, origClientOrderIdList }))
1197
- },
1198
- {
1199
- name: "futures_set_leverage",
1200
- description: "Change initial leverage for a symbol (1-125, within bracket). Signed.",
1201
- inputSchema: z8.object({ symbol: symbol2, leverage: z8.number().int().min(1).max(125) }),
1202
- handler: async ({ symbol: symbol3, leverage }) => textResult(await t.setLeverage(normalizeSymbol(symbol3), leverage))
1203
- },
1204
- {
1205
- name: "futures_set_margin_type",
1206
- description: "Change margin type for a symbol: isolated or cross. Only allowed when no open position for the symbol. Signed.",
1207
- inputSchema: z8.object({ symbol: symbol2, marginType: z8.enum(["isolated", "cross"]) }),
1208
- handler: async ({ symbol: symbol3, marginType }) => textResult(await t.setMarginType(normalizeSymbol(symbol3), marginType))
1209
- },
1210
- {
1211
- name: "futures_modify_position_margin",
1212
- description: "Add or reduce isolated position margin. marginType: 1 = add margin, 2 = reduce margin. Signed.",
1213
- inputSchema: z8.object({ symbol: symbol2, amount: z8.number().positive(), marginType: z8.enum(["1", "2"]).describe("1 = add margin, 2 = reduce margin") }),
1214
- handler: async ({ symbol: symbol3, amount, marginType }) => textResult(await t.modifyPositionMargin(normalizeSymbol(symbol3), amount, Number(marginType)))
1215
- },
1216
- {
1217
- name: "futures_countdown_cancel_all",
1218
- description: "Auto-cancel all open orders for a symbol after countdownTime ms (0 = cancel the countdown). Emergency circuit breaker. Signed.",
1219
- inputSchema: z8.object({ symbol: symbol2, countdownTime: z8.number().int().min(100).max(6e4) }),
1220
- handler: async ({ symbol: symbol3, countdownTime }) => textResult(await t.setCountdownCancelAll(normalizeSymbol(symbol3), countdownTime))
1221
- },
1222
- {
1223
- name: "futures_new_algo_order",
1224
- description: "Place a conditional algo order (CONDITIONAL or VP). CONDITIONAL supports STOP_MARKET/TAKE_PROFIT_MARKET types with triggerPrice; VP is a volume-participation order with urgency and quantity. Signed.",
1225
- inputSchema: z8.object({
1226
- algoType: z8.enum(["CONDITIONAL", "VP"]),
1227
- symbol: symbol2,
1228
- side: side2,
1229
- positionSide,
1230
- type: z8.enum(["STOP_MARKET", "TAKE_PROFIT_MARKET", "LIMIT"]).describe("For CONDITIONAL: STOP_MARKET/TAKE_PROFIT_MARKET. For VP: LIMIT"),
1231
- quantity: z8.union([z8.string(), z8.number()]),
1232
- triggerPrice: z8.union([z8.string(), z8.number()]).optional().describe("Required for CONDITIONAL"),
1233
- price: z8.union([z8.string(), z8.number()]).optional(),
1234
- timeInForce: z8.enum(["GTC", "IOC", "FOK", "GTX"]).optional(),
1235
- workingType: z8.enum(["MARK_PRICE", "CONTRACT_PRICE"]).optional(),
1236
- priceProtect: z8.boolean().optional(),
1237
- reduceOnly: z8.boolean().optional(),
1238
- closePosition: z8.boolean().optional(),
1239
- urgency: z8.enum(["LOW", "MEDIUM", "HIGH"]).optional().describe("Required for VP"),
1240
- clientAlgoId: z8.string().optional()
1241
- }),
1242
- handler: async (args) => textResult(await t.createAlgoOrder({ ...args, symbol: normalizeSymbol(args.symbol) }))
1243
- },
1244
- {
1245
- name: "futures_cancel_algo_order",
1246
- description: "Cancel an open algo order by algoId or clientAlgoId. Signed.",
1247
- inputSchema: z8.object({ symbol: symbol2, algoId: z8.number().int().positive().optional(), clientAlgoId: z8.string().optional() }),
1248
- handler: async ({ symbol: symbol3, algoId, clientAlgoId }) => textResult(await t.cancelAlgoOrder(normalizeSymbol(symbol3), { algoId, clientAlgoId }))
1249
- },
1250
- {
1251
- name: "futures_cancel_all_algo_orders",
1252
- description: "Cancel all open algo orders for a symbol. Signed.",
1253
- inputSchema: z8.object({ symbol: symbol2 }),
1254
- handler: async ({ symbol: symbol3 }) => textResult(await t.cancelAllOpenAlgoOrders(normalizeSymbol(symbol3)))
1255
- },
1256
- {
1257
- name: "futures_get_algo_order",
1258
- description: "Query an algo order by algoId or clientAlgoId. Signed.",
1259
- inputSchema: z8.object({ symbol: symbol2, algoId: z8.number().int().positive().optional(), clientAlgoId: z8.string().optional() }),
1260
- handler: async ({ symbol: symbol3, algoId, clientAlgoId }) => textResult(await t.getAlgoOrder(normalizeSymbol(symbol3), { algoId, clientAlgoId }))
1261
- },
1262
- {
1263
- name: "futures_open_algo_orders",
1264
- description: "Get all current open algo orders, optionally filtered by symbol. Signed.",
1265
- inputSchema: z8.object({ symbol: optionalSymbol3 }),
1266
- handler: async ({ symbol: symbol3 }) => textResult(await t.getOpenAlgoOrders(symbol3 ? normalizeSymbol(symbol3) : void 0))
1267
- },
1268
- {
1269
- name: "futures_all_algo_orders",
1270
- description: "Get historical algo orders for a symbol with optional time range. Signed.",
1271
- inputSchema: z8.object({ symbol: symbol2, startTime: startTime4, endTime: endTime4, limit: limit3 }),
1272
- handler: async ({ symbol: symbol3, startTime: startTime5, endTime: endTime5, limit: limit4 }) => textResult(await t.getAllAlgoOrders(normalizeSymbol(symbol3), { startTime: startTime5, endTime: endTime5, limit: limit4 }))
1273
- },
1274
- {
1275
- name: "futures_convert_exchange_info",
1276
- description: "List asset pairs eligible for futures Convert, optionally filtered by fromAsset/toAsset.",
1277
- inputSchema: z8.object({ fromAsset: z8.string().optional(), toAsset: z8.string().optional() }),
1278
- handler: async ({ fromAsset, toAsset }) => textResult(await t.convertExchangeInfo({ fromAsset, toAsset }))
1279
- },
1280
- {
1281
- name: "futures_convert_get_quote",
1282
- description: "Request a Convert quote between two assets (quote expires quickly; accept with futures_convert_accept_quote). Signed.",
1283
- inputSchema: z8.object({
1284
- fromAsset: z8.string().min(1),
1285
- toAsset: z8.string().min(1),
1286
- fromAmount: z8.number().positive().optional(),
1287
- toAmount: z8.number().positive().optional(),
1288
- validTime: z8.enum(["10s", "30s", "1m", "2m"]).optional()
1289
- }),
1290
- handler: async (args) => textResult(await t.convertGetQuote(args))
1291
- },
1292
- {
1293
- name: "futures_convert_accept_quote",
1294
- description: "Accept a previously requested Convert quote by quoteId. Signed.",
1295
- inputSchema: z8.object({ quoteId: z8.string().min(1) }),
1296
- handler: async ({ quoteId }) => textResult(await t.convertAcceptQuote(quoteId))
1297
- },
1298
- {
1299
- name: "futures_convert_order_status",
1300
- description: "Query the status of a Convert order by orderId or quoteId. Signed.",
1301
- inputSchema: z8.object({ orderId: z8.string().optional(), quoteId: z8.string().optional() }),
1302
- handler: async ({ orderId, quoteId }) => textResult(await t.convertOrderStatus({ orderId, quoteId }))
1303
- }
1304
- ];
1305
- }
1306
-
1307
1395
  // src/tools/ws.tools.ts
1308
- import { z as z9 } from "zod";
1396
+ import { z as z10 } from "zod";
1309
1397
  var buffers = /* @__PURE__ */ new Map();
1310
1398
  var MAX_BUFFER = 500;
1311
1399
  function bufferFor(client) {
@@ -1332,8 +1420,8 @@ function wsTools(client) {
1332
1420
  {
1333
1421
  name: "futures_ws_subscribe",
1334
1422
  description: "Subscribe to real-time market data streams. Topic format: <symbol>@<stream>, e.g. btcusdt@aggTrade, btcusdt@kline_1m, btcusdt@depth20, btcusdt@markPrice@1s, btcusdt@bookTicker, btcusdt@ticker, btcusdt@miniTicker, btcusdt@forceOrder, or all-market topics !ticker@arr, !bookTicker, !markPrice@arr, !forceOrder@arr, !miniTicker@arr. Multiple topics can be passed at once.",
1335
- inputSchema: z9.object({
1336
- topics: z9.array(z9.string().min(1)).min(1).describe('Stream topics, e.g. ["btcusdt@aggTrade", "btcusdt@kline_1m"]')
1423
+ inputSchema: z10.object({
1424
+ topics: z10.array(z10.string().min(1)).min(1).describe('Stream topics, e.g. ["btcusdt@aggTrade", "btcusdt@kline_1m"]')
1337
1425
  }),
1338
1426
  handler: async ({ topics }) => {
1339
1427
  const normalized = topics.map((t) => t.trim().toLowerCase());
@@ -1345,7 +1433,7 @@ function wsTools(client) {
1345
1433
  {
1346
1434
  name: "futures_ws_unsubscribe",
1347
1435
  description: "Unsubscribe from previously subscribed market data streams.",
1348
- inputSchema: z9.object({ topics: z9.array(z9.string().min(1)).min(1) }),
1436
+ inputSchema: z10.object({ topics: z10.array(z10.string().min(1)).min(1) }),
1349
1437
  handler: async ({ topics }) => {
1350
1438
  const normalized = topics.map((t) => t.trim().toLowerCase());
1351
1439
  client.futures.ws.unsubscribe(normalized);
@@ -1356,19 +1444,19 @@ function wsTools(client) {
1356
1444
  {
1357
1445
  name: "futures_ws_subscriptions",
1358
1446
  description: "List the currently subscribed WebSocket market streams for this client.",
1359
- inputSchema: z9.object({}),
1447
+ inputSchema: z10.object({}),
1360
1448
  handler: async () => textResult({ active: [...buffer.subscriptions] })
1361
1449
  },
1362
1450
  {
1363
1451
  name: "futures_ws_events",
1364
1452
  description: "Read the buffered real-time payloads received since the last read for the subscribed streams (aggregate trades, klines, depth deltas, mark price, book tickers, tickers, force orders). Payloads are parsed; depth deltas must be applied to a snapshot from futures_order_book.",
1365
- inputSchema: z9.object({ limit: z9.number().int().min(1).max(200).default(50) }),
1453
+ inputSchema: z10.object({ limit: z10.number().int().min(1).max(200).default(50) }),
1366
1454
  handler: async ({ limit: limit4 }) => textResult(getBufferedWsEvents(client, limit4))
1367
1455
  },
1368
1456
  {
1369
1457
  name: "futures_ws_clear_events",
1370
1458
  description: "Clear the buffered WebSocket events so the next read only returns new payloads.",
1371
- inputSchema: z9.object({}),
1459
+ inputSchema: z10.object({}),
1372
1460
  handler: async () => {
1373
1461
  clearBufferedWsEvents(client);
1374
1462
  return textResult({ cleared: true });
@@ -1377,13 +1465,13 @@ function wsTools(client) {
1377
1465
  {
1378
1466
  name: "futures_ws_start_user_stream",
1379
1467
  description: "Start the user data stream: creates a listenKey, connects the private WebSocket, and begins a 30-minute keep-alive. Emits private events (ACCOUNT_UPDATE, ORDER_TRADE_UPDATE, MARGIN_CALL, ACCOUNT_CONFIG_UPDATE, listenKeyExpired) that the application can consume from the client.",
1380
- inputSchema: z9.object({}),
1468
+ inputSchema: z10.object({}),
1381
1469
  handler: async () => textResult({ listenKey: await client.startUserStream() })
1382
1470
  },
1383
1471
  {
1384
1472
  name: "futures_ws_stop_user_stream",
1385
1473
  description: "Stop the user data stream: closes the private WebSocket and invalidates the listenKey.",
1386
- inputSchema: z9.object({}),
1474
+ inputSchema: z10.object({}),
1387
1475
  handler: async () => {
1388
1476
  client.closeUserStream();
1389
1477
  return textResult({ stopped: true });
@@ -1392,49 +1480,49 @@ function wsTools(client) {
1392
1480
  {
1393
1481
  name: "futures_ws_api_order_status",
1394
1482
  description: "Query an order via the signed WebSocket API (order.status) \u2014 lower-latency alternative to futures_get_order.",
1395
- inputSchema: z9.object({
1396
- symbol: z9.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
1397
- orderId: z9.number().int().positive().optional(),
1398
- origClientOrderId: z9.string().optional()
1483
+ inputSchema: z10.object({
1484
+ symbol: z10.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
1485
+ orderId: z10.number().int().positive().optional(),
1486
+ origClientOrderId: z10.string().optional()
1399
1487
  }),
1400
1488
  handler: async ({ symbol: symbol3, orderId, origClientOrderId }) => textResult(await client.futures.wsApi.orderStatus({ symbol: normalizeSymbol(symbol3), orderId, origClientOrderId }))
1401
1489
  },
1402
1490
  {
1403
1491
  name: "futures_ws_api_account_status",
1404
1492
  description: "Get account info via the signed WebSocket API (account.status).",
1405
- inputSchema: z9.object({}),
1493
+ inputSchema: z10.object({}),
1406
1494
  handler: async () => textResult(await client.futures.wsApi.accountStatus())
1407
1495
  },
1408
1496
  {
1409
1497
  name: "futures_ws_api_account_position",
1410
1498
  description: "Get current positions via the signed WebSocket API (account.position).",
1411
- inputSchema: z9.object({ symbol: z9.string().min(1).describe("USD-M pair, e.g. BTCUSDT").optional() }),
1499
+ inputSchema: z10.object({ symbol: z10.string().min(1).describe("USD-M pair, e.g. BTCUSDT").optional() }),
1412
1500
  handler: async ({ symbol: symbol3 }) => textResult(await client.futures.wsApi.accountPosition(symbol3 ? { symbol: normalizeSymbol(symbol3) } : {}))
1413
1501
  },
1414
1502
  {
1415
1503
  name: "futures_ws_api_user_data_stream_start",
1416
1504
  description: "Create a listenKey via the signed WebSocket API (userDataStream.start) \u2014 no REST call required.",
1417
- inputSchema: z9.object({}),
1505
+ inputSchema: z10.object({}),
1418
1506
  handler: async () => textResult(await client.futures.wsApi.userDataStreamStart())
1419
1507
  },
1420
1508
  {
1421
1509
  name: "futures_ws_api_user_data_stream_stop",
1422
1510
  description: "Invalidate a listenKey via the signed WebSocket API (userDataStream.stop).",
1423
- inputSchema: z9.object({ listenKey: z9.string().min(1) }),
1511
+ inputSchema: z10.object({ listenKey: z10.string().min(1) }),
1424
1512
  handler: async ({ listenKey }) => textResult(await client.futures.wsApi.userDataStreamStop(listenKey))
1425
1513
  },
1426
1514
  {
1427
1515
  name: "futures_ws_api_ticker_price",
1428
1516
  description: "Get latest price via the unsigned WebSocket API (ticker.price); omit symbol for all symbols.",
1429
- inputSchema: z9.object({ symbol: z9.string().min(1).describe("USD-M pair, e.g. BTCUSDT").optional() }),
1517
+ inputSchema: z10.object({ symbol: z10.string().min(1).describe("USD-M pair, e.g. BTCUSDT").optional() }),
1430
1518
  handler: async ({ symbol: symbol3 }) => textResult(await client.futures.wsApi.tickerPrice(symbol3 ? { symbol: normalizeSymbol(symbol3) } : {}))
1431
1519
  },
1432
1520
  {
1433
1521
  name: "futures_ws_api_order_book",
1434
1522
  description: "Get order-book depth via the unsigned WebSocket API (depth).",
1435
- inputSchema: z9.object({
1436
- symbol: z9.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
1437
- limit: z9.enum(["5", "10", "20", "50", "100", "500", "1000"]).optional()
1523
+ inputSchema: z10.object({
1524
+ symbol: z10.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
1525
+ limit: z10.enum(["5", "10", "20", "50", "100", "500", "1000"]).optional()
1438
1526
  }),
1439
1527
  handler: async ({ symbol: symbol3, limit: limit4 }) => textResult(await client.futures.wsApi.depth({ symbol: normalizeSymbol(symbol3), limit: limit4 }))
1440
1528
  }
@@ -1442,7 +1530,7 @@ function wsTools(client) {
1442
1530
  }
1443
1531
 
1444
1532
  // src/tools/index.ts
1445
- function createFuturesToolkit(client) {
1533
+ function createFuturesToolkit(client, options = {}) {
1446
1534
  const market = marketDataTools(client);
1447
1535
  const account = accountTools(client);
1448
1536
  const trading = tradingTools(client);
@@ -1451,9 +1539,14 @@ function createFuturesToolkit(client) {
1451
1539
  const derived = derivedTools(client);
1452
1540
  const paperContext = createPaperContext(client);
1453
1541
  const paper = paperTools(paperContext);
1542
+ const gateway = client.createExecutionGateway({
1543
+ paper: options.paper,
1544
+ defaultBackend: options.executionBackend
1545
+ });
1546
+ const execution = executionTools(gateway, client);
1454
1547
  return {
1455
1548
  client,
1456
- tools: [...market, ...account, ...trading, ...spot, ...ws, ...derived, ...paper],
1549
+ tools: [...market, ...account, ...trading, ...spot, ...ws, ...derived, ...paper, ...execution],
1457
1550
  market,
1458
1551
  account,
1459
1552
  trading,
@@ -1461,7 +1554,9 @@ function createFuturesToolkit(client) {
1461
1554
  ws,
1462
1555
  derived,
1463
1556
  paper,
1464
- paperContext
1557
+ paperContext,
1558
+ execution,
1559
+ gateway
1465
1560
  };
1466
1561
  }
1467
1562
  function toolkitToFormats(toolkit) {
@@ -1477,6 +1572,7 @@ export {
1477
1572
  createFuturesToolkit,
1478
1573
  createPaperContext,
1479
1574
  derivedTools,
1575
+ executionTools,
1480
1576
  getBufferedWsEvents,
1481
1577
  marketDataTools,
1482
1578
  paperTools,