合约 V3 websock API
基本描述
- 所有标准WebSocket库都可以读取WebSockets。 数据分布在公共和私有频道,API客户端可以订阅这些频道。
- 通过WebSockets发送和接收的所有消息都以JSON格式进行编码。
- 只有支持的JSON标签会被处理,其他内容将被忽略,并返回基础错误提示。
- WebSockets服务器响应时长为30秒,收到一条消息或ping会进行处理。如果没有检测到任何活动,服务器自动结束客户端会话且没有提示。
- Private API:
wss://ws.poloniex.com/ws/v3/private
- Public API:
wss://ws.poloniex.com/ws/v3/public
限制
- WebSocket访问分为两个端点,私有端点只能访问私有频道,不可访问公共频道。 公共端点只能访问公共频道,不可访问私有频道。 端点限制仅适用于订阅请求;其他请求如ping和取消订阅不受限制。
- 单个IP在公共和私有频道上的同时连接数上限为2000个。
- 一旦建立连接,每个连接限制每秒500个请求。
消息
消息 | 描述 |
---|---|
ping (request) | 客户端可以向服务器发送ping消息来保持连接 |
pong (response) | 服务器对ping消息做出响应 |
subscribe (request) | 订阅单个或多个交易频道 |
unsubscribe (request) | 取消订阅所有或指定交易的频道 |
unsubscribe_all (request) | 移除用户当前的所有订阅 |
list_subscriptions (request) | 列出当前的所有订阅 |
调用
注:只有客户端可发出ping命令。 服务器不会发出ping命令。
命令 |
---|
{"event": "ping"} |
{"event": "pong"} |
订阅
订阅
订阅请求和初始响应
请求:
# Subscribe to channel for symbol(s)
{
"event": "subscribe",
"channel": ["<channel>"],
"symbols": ["<symbol1>", "<symbol2>", "<symbol3>"]
}
or
# Subscribe to all symbols for a given channel
{
"event": "subscribe",
"channel": ["<channel>"],
"symbols": ["all"]
}
响应:
# OK
{
"event": "subscribe",
"channel": <channel>
}
# Failure
{
"event": "error",
"message": "Error Message"
}
订阅报错
- 订阅失败(通用)
- 已订阅
- 请求错误(通用)
取消订阅
取消/全部取消
请求:
# Unsubscribe the specified symbol from the channel
{
"event": "unsubscribe",
"channel": ["<channel>"],
"symbols": [
"<symbol>"
]
}
# Unsubscribe from the entire channel
{
"event": "unsubscribe",
"channel": ["<channel>"],
"symbols": ["all"]
}
响应:
# OK
{
"channel": "<channel>",
"event": "UNSUBSCRIBE"
}
# not subscribed
{
"message": "Error Message",
"event": "error"
}
请求:
{
"event": "unsubscribe_all"
}
响应:
{
"channel": "ALL",
"event": "UNSUBSCRIBE_ALL"
}
未订阅报错
- 请求失败(通用)
- 未订阅
查询订阅
查询当前所有订阅
请求:
{
"event": "list_subscriptions"
}
响应:
{
"subscriptions": [<channel>]
}
订阅多个频道
# --> Request
{
"event": "subscribe",
"channel": ["orders", "balances"],
"symbols": ["all"]
}
# <-- Receipt Confirmation
{
"channel": "orders",
"event": "subscribe",
"symbols": ["all"]
}
# <-- Receipt Confirmation
{
"channel": "balances",
"event": "subscribe",
"symbols": ["all"]
}
# <-- Stream
{
"channel": "orders",
"data": [
{
"symbol": "LINK_USDC",
"type": "LIMIT",
"quantity": "10",
"orderId": "32482887660077056",
"tradeFee": "0",
"clientOrderId": "4436176",
"accountType": "SPOT",
"feeCurrency": "",
"eventType": "place",
"source": "API",
"side": "SELL",
"filledQuantity": "0",
"filledAmount": "0",
"state": "NEW",
"tradeTime": 0,
"tradeAmount": "0",
"orderAmount": "0",
"createTime": 1648710923921,
"price": "3",
"tradeQty": "0",
"tradePrice": "0",
"tradeId": "0",
"ts": 1648710923948
}
]
}
# <-- Stream (continued)
{
"channel": "balances",
"data": [
{
"changeTime": 1657312008411,
"accountId": "1234",
"eventType": "place_order",
"available": "9999999983.668",
"currency": "BTC",
"id": 60018450912695040,
"userId": 12345,
"hold": "16.332",
"ts": 1657312008443
}
]
}
速率限制
公共端点
公共请求受各个IP地址和端点集合的限制
已认证端点
- 对下列非资源密集型端点的认证请求限制基于用户ID和MVP状态。 速率限制适用于所有这些端点。
- 对下列资源密集型端点的认证请求限制基于用户ID和MVP状态。 速率限制适用于所有这些端点。