mcpField
S
spot

spot

github.com/binance其他1.1k2.9k 次安装2 天前更新
代码仓库

关于 spot

用于查询 Binance Spot 公共市场数据及需认证的账户或交易接口的 Skill,并以 JSON 返回结果。涵盖价格、订单簿、成交、账户信息和订单操作,部分接口需要 API 凭证。

主要功能

  1. 01市场价格与行情统计
  2. 02订单簿及成交历史查询
  3. 03账户与佣金信息查询
  4. 04创建、查询和取消订单
  5. 05订单列表操作

适用场景

  1. 01查看交易对的当前价格
  2. 02检查订单簿深度和近期成交
  3. 03查看账户余额及佣金
  4. 04提交或管理 Spot 订单

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/binance/binance-skills-hub --skill spot

安装后在 Claude Code 中输入/spot确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

CHANGELOG.md
LICENSE.md
references/
authentication.md

详细介绍

Binance 现货技能

使用经过身份验证的 API 端点在 Binance 上进行现货请求。某些端点需要 API 密钥和密钥。以 JSON 格式返回结果。

快速参考

端点描述必填可选身份验证
/api/v3/exchangeInfo (GET)交易所信息无symbol, symbols, permissions, showPermissionSets, symbolStatus否
/api/v3/ping (GET)测试连接无无否
/api/v3/time (GET)检查服务器时间无无否
/api/v3/aggTrades (GET)压缩/聚合交易列表symbolfromId, startTime, endTime, limit否
/api/v3/avgPrice (GET)当前平均价格symbol无否
/api/v3/depth (GET)订单簿symbollimit, symbolStatus否
/api/v3/historicalTrades (GET)历史交易查询symbollimit, fromId否
/api/v3/klines (GET)K 线/蜡烛图数据symbol, intervalstartTime, endTime, timeZone, limit否
/api/v3/ticker (GET)滚动窗口价格变动统计无symbol, symbols, windowSize, type, symbolStatus否
/api/v3/ticker/24hr (GET)24 小时行情价格变动统计无symbol, symbols, type, symbolStatus否
/api/v3/ticker/bookTicker (GET)交易对订单簿行情无symbol, symbols, symbolStatus否
/api/v3/ticker/price (GET)交易对价格行情无symbol, symbols, symbolStatus否
/api/v3/ticker/tradingDay (GET)交易日行情无symbol, symbols, timeZone, type, symbolStatus否
/api/v3/trades (GET)最新交易列表symbollimit否
/api/v3/uiKlines (GET)UI K 线symbol, intervalstartTime, endTime, timeZone, limit否
/api/v3/openOrders (DELETE)取消某交易对的所有未结订单symbolrecvWindow是
/api/v3/openOrders (GET)当前未结订单无symbol, recvWindow是
/api/v3/order (POST)新建订单symbol, side, typetimeInForce, quantity, quoteOrderQty, price, newClientOrderId, strategyId, strategyType, stopPrice, trailingDelta, icebergQty, newOrderRespType, selfTradePreventionMode, pegPriceType, pegOffsetValue, pegOffsetType, recvWindow是
/api/v3/order (DELETE)取消订单symbolorderId, origClientOrderId, newClientOrderId, cancelRestrictions, recvWindow是
/api/v3/order (GET)查询订单symbolorderId, origClientOrderId, recvWindow是
/api/v3/order/amend/keepPriority (PUT)修改订单并保持优先级symbol, newQtyorderId, origClientOrderId, newClientOrderId, recvWindow是
/api/v3/order/cancelReplace (POST)取消现有订单并发送新订单symbol, side, type, cancelReplaceModetimeInForce, quantity, quoteOrderQty, price, cancelNewClientOrderId, cancelOrigClientOrderId, cancelOrderId, newClientOrderId, strategyId, strategyType, stopPrice, trailingDelta, icebergQty, newOrderRespType, selfTradePreventionMode, cancelRestrictions, orderRateLimitExceededMode, pegPriceType, pegOffsetValue, pegOffsetType, recvWindow是
/api/v3/order/oco (POST)新建 OCO——已弃用symbol, side, quantity, price, stopPricelistClientOrderId, limitClientOrderId, limitStrategyId, limitStrategyType, limitIcebergQty, trailingDelta, stopClientOrderId, stopStrategyId, stopStrategyType, stopLimitPrice, stopIcebergQty, stopLimitTimeInForce, newOrderRespType, selfTradePreventionMode, recvWindow是
/api/v3/order/test (POST)测试新订单symbol, side, typecomputeCommissionRates, timeInForce, quantity, quoteOrderQty, price, newClientOrderId, strategyId, strategyType, stopPrice, trailingDelta, icebergQty, newOrderRespType, selfTradePreventionMode, pegPriceType, pegOffsetValue, pegOffsetType, recvWindow是
/api/v3/orderList (DELETE)取消订单列表symbolorderListId, listClientOrderId, newClientOrderId, recvWindow是
/api/v3/orderList (GET)查询订单列表无orderListId, origClientOrderId, recvWindow是
/api/v3/orderList/oco (POST)新建订单列表——OCOsymbol, side, quantity, aboveType, belowTypelistClientOrderId, aboveClientOrderId, aboveIcebergQty, abovePrice, aboveStopPrice, aboveTrailingDelta, aboveTimeInForce, aboveStrategyId, aboveStrategyType, abovePegPriceType, abovePegOffsetType, abovePegOffsetValue, belowClientOrderId, belowIcebergQty, belowPrice, belowStopPrice, belowTrailingDelta, belowTimeInForce, belowStrategyId, belowStrategyType, belowPegPriceType, belowPegOffsetType, belowPegOffsetValue, newOrderRespType, selfTradePreventionMode, recvWindow是
/api/v3/orderList/opo (POST)新建订单列表——OPOsymbol, workingType, workingSide, workingPrice, workingQuantity, pendingType, pendingSidelistClientOrderId, newOrderRespType, selfTradePreventionMode, workingClientOrderId, workingIcebergQty, workingTimeInForce, workingStrategyId, workingStrategyType, workingPegPriceType, workingPegOffsetType, workingPegOffsetValue, pendingClientOrderId, pendingPrice, pendingStopPrice, pendingTrailingDelta, pendingIcebergQty, pendingTimeInForce, pendingStrategyId, pendingStrategyType, pendingPegPriceType, pendingPegOffsetType, pendingPegOffsetValue, recvWindow是
/api/v3/orderList/opoco (POST)新建订单列表——OPOCOsymbol, workingType, workingSide, workingPrice, workingQuantity, pendingSide, pendingAboveTypelistClientOrderId, newOrderRespType, selfTradePreventionMode, workingClientOrderId, workingIcebergQty, workingTimeInForce, workingStrategyId, workingStrategyType, workingPegPriceType, workingPegOffsetType, workingPegOffsetValue, pendingAboveClientOrderId, pendingAbovePrice, pendingAboveStopPrice, pendingAboveTrailingDelta, pendingAboveIcebergQty, pendingAboveTimeInForce, pendingAboveStrategyId, pendingAboveStrategyType, pendingAbovePegPriceType, pendingAbovePegOffsetType, pendingAbovePegOffsetValue, pendingBelowType, pendingBelowClientOrderId, pendingBelowPrice, pendingBelowStopPrice, pendingBelowTrailingDelta, pendingBelowIcebergQty, pendingBelowTimeInForce, pendingBelowStrategyId, pendingBelowStrategyType, pendingBelowPegPriceType, pendingBelowPegOffsetType, pendingBelowPegOffsetValue, recvWindow是
/api/v3/orderList/oto (POST)新建订单列表——OTOsymbol, workingType, workingSide, workingPrice, workingQuantity, pendingType, pendingSide, pendingQuantitylistClientOrderId, newOrderRespType, selfTradePreventionMode, workingClientOrderId, workingIcebergQty, workingTimeInForce, workingStrategyId, workingStrategyType, workingPegPriceType, workingPegOffsetType, workingPegOffsetValue, pendingClientOrderId, pendingPrice, pendingStopPrice, pendingTrailingDelta, pendingIcebergQty, pendingTimeInForce, pendingStrategyId, pendingStrategyType, pendingPegPriceType, pendingPegOffsetType, pendingPegOffsetValue, recvWindow是
/api/v3/orderList/otoco (POST)新建订单列表——OTOCOsymbol, workingType, workingSide, workingPrice, workingQuantity, pendingSide, pendingQuantity, pendingAboveTypelistClientOrderId, newOrderRespType, selfTradePreventionMode, workingClientOrderId, workingIcebergQty, workingTimeInForce, workingStrategyId, workingStrategyType, workingPegPriceType, workingPegOffsetType, workingPegOffsetValue, pendingAboveClientOrderId, pendingAbovePrice, pendingAboveStopPrice, pendingAboveTrailingDelta, pendingAboveIcebergQty, pendingAboveTimeInForce, pendingAboveStrategyId, pendingAboveStrategyType, pendingAbovePegPriceType, pendingAbovePegOffsetType, pendingAbovePegOffsetValue, pendingBelowType, pendingBelowClientOrderId, pendingBelowPrice, pendingBelowStopPrice, pendingBelowTrailingDelta, pendingBelowIcebergQty, pendingBelowTimeInForce, pendingBelowStrategyId, pendingBelowStrategyType, pendingBelowPegPriceType, pendingBelowPegOffsetType, pendingBelowPegOffsetValue, recvWindow是
/api/v3/sor/order (POST)使用 SOR 新建订单symbol, side, type, quantitytimeInForce, price, newClientOrderId, strategyId, strategyType, icebergQty, newOrderRespType, selfTradePreventionMode, recvWindow是
/api/v3/sor/order/test (POST)测试使用 SOR 新建订单symbol, side, type, quantitycomputeCommissionRates, timeInForce, price, newClientOrderId, strategyId, strategyType, icebergQty, newOrderRespType, selfTradePreventionMode, recvWindow是
/api/v3/account (GET)账户信息无omitZeroBalances, recvWindow是
/api/v3/account/commission (GET)查询佣金费率symbol无是
/api/v3/allOrderList (GET)查询所有订单列表无fromId, startTime, endTime, limit, recvWindow是
/api/v3/allOrders (GET)所有订单symbolorderId, startTime, endTime, limit, recvWindow是
/api/v3/myAllocations (GET)查询分配记录symbolstartTime, endTime, fromAllocationId, limit, orderId, recvWindow是
/api/v3/myFilters (GET)查询相关筛选器symbolrecvWindow是
/api/v3/myPreventedMatches (GET)查询被阻止的撮合symbolpreventedMatchId, orderId, fromPreventedMatchId, limit, recvWindow是
/api/v3/myTrades (GET)账户交易列表symbolorderId, startTime, endTime, fromId, limit, recvWindow是
/api/v3/openOrderList (GET)查询未结订单列表无recvWindow是
/api/v3/order/amendments (GET)查询订单修改记录symbol, orderIdfromExecutionId, limit, recvWindow是
/api/v3/rateLimit/order (GET)查询未成交订单数量无recvWindow是

Parameters

Common Parameters
  • symbol:要查询的交易对(例如,BNBUSDT)
  • symbols:要查询的交易对列表
  • permissions:要查询的权限列表
  • showPermissionSets:控制是否填充 permissionSets 字段的内容。默认值为 true(例如,true)
  • symbol:(例如,BNBUSDT)
  • fromId:获取大于或等于此 ID 的聚合交易。(例如,1)
  • startTime:获取大于或等于此时间戳(毫秒)的聚合交易。(例如,1735693200000)
  • endTime:获取截至此时间戳(毫秒)的聚合交易,包含此时间戳。(例如,1735693200000)
  • limit:默认值:500;最大值:1000。(例如,500)
  • timeZone:默认值:0(UTC)
  • recvWindow:该值不能大于 60000。支持最多三位小数(例如,6000.346),因此可以指定微秒。(例如,5000)
  • timestamp:(例如,1)
  • quantity:(例如,1)
  • quoteOrderQty:(例如,1)
  • price:(例如,400)
  • newClientOrderId:未完成订单中的唯一 ID。若未发送,则自动生成。只有在之前的订单已成交时,才会接受具有相同 newClientOrderID 的订单;否则订单将被拒绝。
  • strategyId:(例如,1)
  • strategyType:该值不能小于 1000000。(例如,1)
  • stopPrice:与 STOP_LOSS、STOP_LOSS_LIMIT、TAKE_PROFIT 和 TAKE_PROFIT_LIMIT 订单搭配使用。(例如,1)
  • trailingDelta:请参阅追踪止损订单常见问题。(例如,1)
  • icebergQty:与 LIMIT、STOP_LOSS_LIMIT 和 TAKE_PROFIT_LIMIT 搭配使用,以创建冰山订单。(例如,1)
  • pegOffsetValue:用于将价格挂钩至某个价格的价格级别(最大值:100)。请参阅挂钩订单信息(例如,1)
  • orderId:(例如,1)
  • origClientOrderId:
  • newQty:newQty 必须大于 0 且小于订单数量。(例如,1)
  • cancelNewClientOrderId:用于唯一标识此次撤单。默认自动生成。
  • cancelOrigClientOrderId:必须发送 cancelOrderId 或 cancelOrigClientOrderId。
    如果同时提供 cancelOrderId 和 cancelOrigClientOrderId 参数,系统会先搜索 cancelOrderId,然后检查该结果中的 cancelOrigClientOrderId 是否与该订单匹配。
    如果这两个条件均不满足,请求将被拒绝。
  • cancelOrderId:必须发送 cancelOrderId 或 cancelOrigClientOrderId。
    如果同时提供 cancelOrderId 和 cancelOrigClientOrderId 参数,系统会先搜索 cancelOrderId,然后检查该结果中的 cancelOrigClientOrderId 是否与该订单匹配。
    如果这两个条件均不满足,请求将被拒绝。(例如,1)
  • listClientOrderId:整个订单列表的唯一 ID
  • quantity:(例如,1)
  • limitClientOrderId:限价订单的唯一 ID
  • price:(例如,1)
  • limitStrategyId:(例如,1)
  • limitStrategyType:该值不能小于 1000000。(例如,1)
  • limitIcebergQty:用于将 LIMIT_MAKER 订单部分设为冰山订单。(例如,1)
  • stopClientOrderId:止损/止损限价订单部分的唯一 ID
  • stopPrice:(例如,1)
  • stopStrategyId:(例如,1)
  • stopStrategyType:该值不能小于 1000000。(例如,1)
  • stopLimitPrice:如果提供此参数,则必须提供 stopLimitTimeInForce。(例如,1)
  • stopIcebergQty:与 STOP_LOSS_LIMIT 订单部分搭配使用,以创建冰山订单。(例如,1)
  • computeCommissionRates:默认值:false。请参阅佣金常见问题了解详情。
  • orderListId:必须提供 orderListId 或 listClientOrderId(例如,1)
  • aboveClientOrderId:above 订单在未完成订单中的任意唯一 ID。若未发送,则自动生成
  • aboveIcebergQty:请注意,此参数只能在 aboveTimeInForce 为 GTC 时使用。(例如,1)
  • abovePrice:当 aboveType 为 STOP_LOSS_LIMIT、LIMIT_MAKER 或 TAKE_PROFIT_LIMIT 时,可用于指定限价。(例如,1)
  • aboveStopPrice:当 aboveType 为 STOP_LOSS、STOP_LOSS_LIMIT、TAKE_PROFIT 或 TAKE_PROFIT_LIMIT 时可用。必须指定 aboveStopPrice、aboveTrailingDelta,或同时指定两者。(例如,1)
  • aboveTrailingDelta:请参阅追踪止损订单常见问题。(例如,1)
  • aboveStrategyId:用于在订单策略中标识 above 订单的任意数值。(例如,1)
  • aboveStrategyType:用于标识 above 订单策略的任意数值。小于 1000000 的值为保留值,不能使用。(例如,1)
  • abovePegOffsetValue:(例如,1)
  • belowClientOrderId:below 订单在未完成订单中的任意唯一 ID。若未发送,则自动生成
  • belowIcebergQty:请注意,此参数只能在 belowTimeInForce 为 GTC 时使用。(例如,1)
  • belowPrice:当 belowType 为 STOP_LOSS_LIMIT、LIMIT_MAKER 或 TAKE_PROFIT_LIMIT 时,可用于指定限价。(例如,1)
  • belowStopPrice:当 belowType 为 STOP_LOSS、STOP_LOSS_LIMIT、TAKE_PROFIT 或 TAKE_PROFIT_LIMIT 时可用。必须指定 belowStopPrice、belowTrailingDelta,或同时指定两者。(例如,1)
  • belowTrailingDelta:请参阅追踪止损订单常见问题。(例如,1)
  • belowStrategyId:用于在订单策略中标识 below 订单的任意数值。(例如,1)
  • belowStrategyType:用于标识 below 订单策略的任意数值。小于 1000000 的值为保留值,不能使用。(例如,1)
  • belowPegOffsetValue:(例如,1)
  • workingClientOrderId:working 订单在未完成订单中的任意唯一 ID。若未发送,则自动生成。
  • workingPrice:(例如,1)
  • workingQuantity:设置 working 订单的数量。(例如,1)
  • workingIcebergQty:只有在 workingTimeInForce 为 GTC 或 workingType 为 LIMIT_MAKER 时才能使用。(例如,1)
  • workingStrategyId:用于在订单策略中标识 working 订单的任意数值。(例如,1)
  • workingStrategyType:用于标识 working 订单策略的任意数值。小于 1000000 的值为保留值,不能使用。(例如,1)
  • workingPegOffsetValue:(例如,1)
  • pendingClientOrderId:pending 订单在未完成订单中的任意唯一 ID。若未发送,则自动生成。
  • pendingPrice:(例如,1)
  • pendingStopPrice:(例如,1)
  • pendingTrailingDelta:(例如,1)
  • pendingIcebergQty:只有在 pendingTimeInForce 为 GTC 或 pendingType 为 LIMIT_MAKER 时才能使用。(例如,1)
  • pendingStrategyId:用于在订单策略中标识 pending 订单的任意数值。(例如,1)
  • pendingStrategyType:用于标识 pending 订单策略的任意数值。小于 1000000 的值为保留值,不能使用。(例如,1)
  • pendingPegOffsetValue:(例如,1)
  • pendingAboveClientOrderId:pending above 订单在未完成订单中的任意唯一 ID。若未发送,则自动生成。
  • pendingAbovePrice:当 pendingAboveType 为 STOP_LOSS_LIMIT、LIMIT_MAKER 或 TAKE_PROFIT_LIMIT 时,可用于指定限价。(例如,1)
  • pendingAboveStopPrice:当 pendingAboveType 为 STOP_LOSS、STOP_LOSS_LIMIT、TAKE_PROFIT 或 TAKE_PROFIT_LIMIT 时可用。(例如,1)
  • pendingAboveTrailingDelta:请参阅追踪止损常见问题(例如,1)
  • pendingAboveIcebergQty:只有在 pendingAboveTimeInForce 为 GTC 或 pendingAboveType 为 LIMIT_MAKER 时才能使用。(例如,1)
  • pendingAboveStrategyId:用于在订单策略中标识 pending above 订单的任意数值。(例如,1)
  • pendingAboveStrategyType:用于标识 pending above 订单策略的任意数值。小于 1000000 的值为保留值,不能使用。(例如,1)
  • pendingAbovePegOffsetValue:(例如,1)
  • pendingBelowClientOrderId:pending below 订单在未完成订单中的任意唯一 ID。若未发送,则自动生成。
  • pendingBelowPrice:当 pendingBelowType 为 STOP_LOSS_LIMIT 或 TAKE_PROFIT_LIMIT 时,可用于指定限价(例如,1)
  • pendingBelowStopPrice:当 pendingBelowType 为 STOP_LOSS、STOP_LOSS_LIMIT、TAKE_PROFIT 或 TAKE_PROFIT_LIMIT 时可用。必须指定 pendingBelowStopPrice、pendingBelowTrailingDelta,或同时指定两者。(例如,1)
  • pendingBelowTrailingDelta:(例如,1)
  • pendingBelowIcebergQty:只有在 pendingBelowTimeInForce 为 GTC 或 pendingBelowType 为 LIMIT_MAKER 时才能使用。(例如,1)
  • pendingBelowStrategyId:用于在订单策略中标识 pending below 订单的任意数值。(例如,1)
  • pendingBelowStrategyType:用于标识 pending below 订单策略的任意数值。小于 1000000 的值为保留值,不能使用。(例如,1)
  • pendingBelowPegOffsetValue:(例如,1)
  • pendingQuantity:设置 pending 订单的数量。(例如,1)
  • omitZeroBalances:设为 true 时,仅返回账户中余额不为零的资产。默认值:false
  • fromAllocationId:(例如,1)
  • timestamp:(例如,1)
  • preventedMatchId:(例如,1)
  • fromPreventedMatchId:(例如,1)
  • orderId:(例如,1)
  • fromExecutionId:(例如,1)
  • limit:默认值:500;最大值:1000(例如,500)
枚举
  • interval:1s | 1m | 3m | 5m | 15m | 30m | 1h | 2h | 4h | 6h | 8h | 12h | 1d | 3d | 1w | 1M
  • windowSize:1m | 2m | 3m | 4m | 5m | 6m | 7m | 8m | 9m | 10m | 11m | 12m | 13m | 14m | 15m | 16m | 17m | 18m | 19m | 20m | 21m | 22m | 23m | 24m | 25m | 26m | 27m | 28m | 29m | 30m | 31m | 32m | 33m | 34m | 35m | 36m | 37m | 38m | 39m | 40m | 41m | 42m | 43m | 44m | 45m | 46m | 47m | 48m | 49m | 50m | 51m | 52m | 53m | 54m | 55m | 56m | 57m | 58m | 59m | 1h | 2h | 3h | 4h | 5h | 6h | 7h | 8h | 9h | 10h | 11h | 12h | 13h | 14h | 15h | 16h | 17h | 18h | 19h | 20h | 21h | 22h | 23h | 1d | 2d | 3d | 4d | 5d | 6d
  • type:FULL | MINI
  • type:MARKET | LIMIT | STOP_LOSS | STOP_LOSS_LIMIT | TAKE_PROFIT | TAKE_PROFIT_LIMIT | LIMIT_MAKER | NON_REPRESENTABLE
  • selfTradePreventionMode:NONE | EXPIRE_TAKER | EXPIRE_MAKER | EXPIRE_BOTH | DECREMENT | NON_REPRESENTABLE
  • symbolStatus:TRADING | END_OF_DAY | HALT | BREAK | NON_REPRESENTABLE
  • timeInForce:GTC | IOC | FOK | NON_REPRESENTABLE
  • pegPriceType:PRIMARY_PEG | MARKET_PEG | NON_REPRESENTABLE
  • pegOffsetType:PRICE_LEVEL | NON_REPRESENTABLE
  • newOrderRespType:ACK | RESULT | FULL | MARKET | LIMIT
  • cancelRestrictions:ONLY_NEW | NEW | ONLY_PARTIALLY_FILLED | PARTIALLY_FILLED
  • cancelReplaceMode:STOP_ON_FAILURE | ALLOW_FAILURE
  • orderRateLimitExceededMode:DO_NOTHING | CANCEL_ONLY
  • stopLimitTimeInForce:GTC | IOC | FOK
  • side:BUY | SELL
  • aboveType:STOP_LOSS_LIMIT | STOP_LOSS | LIMIT_MAKER | TAKE_PROFIT | TAKE_PROFIT_LIMIT
  • aboveTimeInForce:GTC | IOC | FOK
  • abovePegPriceType:PRIMARY_PEG | MARKET_PEG
  • abovePegOffsetType:PRICE_LEVEL
  • belowType:STOP_LOSS | STOP_LOSS_LIMIT | TAKE_PROFIT | TAKE_PROFIT_LIMIT
  • belowTimeInForce:GTC | IOC | FOK
  • belowPegPriceType:PRIMARY_PEG | MARKET_PEG
  • belowPegOffsetType:PRICE_LEVEL
  • workingType:LIMIT | LIMIT_MAKER
  • workingPegPriceType:PRIMARY_PEG | MARKET_PEG
  • workingPegOffsetType:PRICE_LEVEL
  • pendingPegPriceType:PRIMARY_PEG | MARKET_PEG
  • pendingPegOffsetType:PRICE_LEVEL
  • pendingAboveType:STOP_LOSS_LIMIT | STOP_LOSS | LIMIT_MAKER | TAKE_PROFIT | TAKE_PROFIT_LIMIT
  • pendingAbovePegPriceType:PRIMARY_PEG | MARKET_PEG
  • pendingAbovePegOffsetType:PRICE_LEVEL
  • pendingBelowType:STOP_LOSS | STOP_LOSS_LIMIT | TAKE_PROFIT | TAKE_PROFIT_LIMIT
  • pendingBelowPegPriceType:PRIMARY_PEG | MARKET_PEG
  • pendingBelowPegOffsetType:PRICE_LEVEL
  • workingSide:BUY | SELL
  • workingTimeInForce:GTC | IOC | FOK
  • pendingType:LIMIT | MARKET | STOP_LOSS | STOP_LOSS_LIMIT | TAKE_PROFIT | TAKE_PROFIT_LIMIT | LIMIT_MAKER
  • pendingSide:BUY | SELL
  • pendingTimeInForce:GTC | IOC | FOK
  • pendingAboveTimeInForce:GTC | IOC | FOK
  • pendingBelowTimeInForce:GTC | IOC | FOK

身份验证

对于需要身份验证的端点,您需要提供 Binance API 凭据。 所需凭据:

  • apiKey:您的 Binance API 密钥(用于请求头)
  • secretKey:您的 Binance API 密钥(用于签名)

基础 URL:

安全

分享凭据

用户可以通过不同方式提供 Binance API 凭据。Agent 会先尝试通过前两种方式自动获取凭据;用户也可以明确告知 Agent 已设置凭据或将凭据存储在 .env 文件中,此时 Agent 应重新读取该文件。使用前两种方式时,Agent 也可以在未经用户确认的情况下发出 HTTP 请求。

  1. 环境变量

仅搜索以下特定变量(绝不输出完整环境变量):

允许的环境变量

  • 主网:BINANCE_API_KEY 和 BINANCE_SECRET_KEY
  • 测试网:BINANCE_TESTNET_API_KEY 和 BINANCE_TESTNET_SECRET_KEY
  • 演示环境:BINANCE_DEMO_API_KEY 和 BINANCE_DEMO_SECRET_KEY

在单次 exec 调用中读取并使用,避免原始密钥进入 Agent 的上下文:

KEY="$BINANCE_API_KEY"
SECRET="$BINANCE_SECRET_KEY"

response=$(curl -s -X GET "$URL" \
  -H "X-MBX-APIKEY: $KEY" \
  --data-urlencode "param1=value1")

echo "$response"

必须在 OpenClaw 启动前设置环境变量。它们会在进程启动时继承,无法注入正在运行的实例。如果需要在不重启的情况下添加或更新凭据,请使用机密文件(见选项 2)。

  1. 机密文件(.env)

检查 ~/.openclaw/secrets.env、~/.env 或工作区中的 .env 文件。使用 grep 读取单个密钥,绝不要加载整个文件:

# Try all credential locations in order
API_KEY=$(grep '^BINANCE_API_KEY=' ~/.openclaw/secrets.env 2>/dev/null | cut -d= -f2-)
SECRET_KEY=$(grep '^BINANCE_SECRET_KEY=' ~/.openclaw/secrets.env 2>/dev/null | cut -d= -f2-)

# Fallback: search .env in known directories (KEY=VALUE then raw line format)
for dir in ~/.openclaw ~; do
  [ -n "$API_KEY" ] && break
  env_file="$dir/.env"
  [ -f "$env_file" ] || continue

  # Read first two lines
  line1=$(sed -n '1p' "$env_file")
  line2=$(sed -n '2p' "$env_file")

  # Check if lines contain '=' indicating KEY=VALUE format
  if [[ "$line1" == *=* && "$line2" == *=* ]]; then
    API_KEY=$(grep '^BINANCE_API_KEY=' "$env_file" 2>/dev/null | cut -d= -f2-)
    SECRET_KEY=$(grep '^BINANCE_SECRET_KEY=' "$env_file" 2>/dev/null | cut -d= -f2-)
  else
    # Treat lines as raw values
    API_KEY="$line1"
    SECRET_KEY="$line2"
  fi
done

此文件可随时更新,无需重启 OpenClaw;每次调用都会重新读取密钥。用户可以告知你变量现已设置或存储在 .env 文件中,此时你应重新读取该文件。

  1. 内联文件

发送内容采用以下格式的文件:

abc123...xyz
secret123...key
  • 绝不要运行 printenv、env、export 或未指定具体变量名的 set
  • 绝不要在未锚定到特定密钥('^VARNAME=')的情况下对 env 文件运行 grep
  • 绝不要将机密文件加载到 shell 环境中(source .env 或 . .env)
  • 只读取当前任务明确需要的凭据
  • 绝不要在输出或回复中回显或记录原始凭据
  • 如果 TOOLS.md 中包含真实凭据,绝不要将其提交到版本控制;应将其添加到 .gitignore
绝不泄露 API 密钥和密钥

绝不泄露 API 密钥和密钥文件的位置。

绝不要将 API 密钥和密钥发送到主网和测试网以外的任何网站。

绝不显示完整密钥

向用户显示凭据时:

  • **API 密钥:**显示前 5 位和后 4 位字符:su1Qc...8akf
  • **Secret Key:**始终遮蔽,仅显示最后 5 位:***...aws1

用户询问凭据时的回复示例: 账户:main API 密钥:su1Qc...8akf Secret:***...aws1 环境:主网

列出账户

列出账户时,只显示名称和环境,绝不显示密钥: Binance 账户:

  • main(主网/测试网)
  • testnet-dev(测试网)
  • futures-keys(主网)
主网交易

在主网执行交易时,继续操作前始终先向用户确认,请用户输入 “CONFIRM”。


Binance 账户

main
  • API 密钥:your_mainnet_api_key
  • Secret:your_mainnet_secret
  • 测试网:false
testnet-dev
  • API 密钥:your_testnet_api_key
  • Secret:your_testnet_secret
  • 测试网:true
TOOLS.md 结构
## Binance Accounts

### main
- API Key: abc123...xyz
- Secret: secret123...key
- Testnet: false
- Description: Primary trading account

### testnet-dev
- API Key: test456...abc
- Secret: testsecret...xyz
- Testnet: true
- Description: Development/testing

### futures-keys
- API Key: futures789...def
- Secret: futuressecret...uvw
- Testnet: false
- Description: Futures trading account

Agent 行为

  1. 请求凭据:遮蔽密钥(仅显示最后 5 个字符)
  2. 列出账户:显示名称和环境,绝不显示密钥
  3. 选择账户:如果不明确则询问,默认使用 main
  4. 在主网进行交易时,继续操作前先向用户确认,请用户输入 “CONFIRM”
  5. 新凭据:提示用户提供名称、环境和签名模式
  6. 如果请求需要签名,且该请求不是订单,同时 API 密钥未注明为 mainnet、testnet 或 demo 密钥,则尝试向不同的基础 URL 发出请求,查看是否可用,无需询问用户。如果可用,则将密钥与对应环境一同存储。

添加新账户

当用户通过内联文件或消息提供新凭据时:

  • 询问账户名称
  • 询问:主网、测试网还是演示环境
  • 将凭据存储在 TOOLS.md 中,并确认已遮蔽显示

签名请求

对于需要签名的交易端点:

  1. 先检测密钥类型,签名前检查密钥格式。
  2. 使用所有参数构建查询字符串,包括时间戳(Unix 毫秒)。
  3. 根据 RFC 3986 使用 UTF-8 对参数进行百分比编码。
  4. 根据账户配置,使用 secretKey 通过 HMAC SHA256、RSA 或 Ed25519 对查询字符串签名。
  5. 将签名附加到查询字符串。
  6. 包含 X-MBX-APIKEY 请求头。

否则,不要执行步骤 4–6。

新客户端订单 ID

对于包含 newClientOrderId 参数的端点,其值必须始终以 agent- 开头。如果未提供该参数,将自动生成由 agent- 后接 18 个随机字母数字字符组成的值。如果提供了值,则会在其前面加上 agent-

示例:agent-1a2b3c4d5e6f7g8h9i

User Agent 请求头

包含 User-Agent 请求头,其字符串如下:binance-spot/1.1.0 (Skill)

实现详情请参阅 references/authentication.md。

评论

支持 Markdown