Joh*_*n R 3 wss websocket cryptocurrency kucoin
问题是关于 kucoin websocket 公共通道(不是交易)的最后交易。
我只想要像其他加密货币交易所一样实时交易,但当我想连接时,"wss://ws-api-futures.kucoin.com/endpoint" 我得到:
WebSocketError:收到意外状态代码(401 未经授权)
文档https://docs.kucoin.com/futures/#create-connection缺乏解释:(
通常,对于其他交易所,我可以在 JavaScript 中执行此操作:
bybit_market_ws = new WebSocket("wss://stream.bybit.com/spot/quote/ws/v2");
bybit_market_ws.onmessage = event => bybit_trades(event.data);
bybit_market_ws.onopen = event => bybit_market_ws.send(JSON.stringify({"topic":"trade","params":{"symbol":"BTCUSDT","binary":false},"event":"sub"}));
function bybit_trades (jsonx) { console.log(JSON.parse(jsonx)); }
Run Code Online (Sandbox Code Playgroud)
那么我该如何使用 kucoin websocket 来做到这一点呢?
根据文档,我需要一个“公共令牌”,但没有解释如何获取该令牌:(
有人知道我如何通过 websocket(公共)通道检索最后的交易吗?
请注意,API 更新时,以下步骤可能会发生变化。所有信息均可在https://docs.kucoin.com/#apply-connect-token找到
{
"code": "200000",
"data": {
"token": "2neAiuYvAU61ZD...",
"instanceServers": [
{
"endpoint": "wss://ws-api.kucoin.com/endpoint",
"encrypt": true,
"protocol": "websocket",
"pingInterval": 18000,
"pingTimeout": 10000
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
使用上面的响应数据连接到 Websocket :
websocket:endpoint + "?token=" + token
示例:wss://ws-api.kucoin.com/endpoint?token=2neAiu....
获取所有支持的交易
对发送http GET消息至https://api.kucoin.com/api/v1/symbols
{
"code": "200000",
"data": [
{
"symbol": "REQ-ETH",
"name": "REQ-ETH",
"baseCurrency": "REQ",
"quoteCurrency": "ETH",
...
},
{
"symbol": "BTC-USDC",
"name": "BTC-USDC",
"baseCurrency": "BTC",
"quoteCurrency": "USDC",
...
},
...
Run Code Online (Sandbox Code Playgroud)
{
"type": "subscribe", //subscribe or unsubscribe
"topic": "/market/ticker:BTC-USDT,BTC-USDC"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3735 次 |
| 最近记录: |