簡體   English   中英

如何連接到Websocket API?

[英]How to connect to Websocket API?

我嘗試從中查詢的API是: https//socket.etherdelta.com

API的文檔在這里: https : //github.com/etherdelta/etherdelta.github.io/blob/master/docs/API.md

當我嘗試執行簡單的獲取請求: https ://socket.etherdelta.com/getmarkets時,出現一條錯誤消息,提示“無法獲取/ getmarkets”

這是我試圖用來獲取市場信息的代碼:

var request = require('request');
var url = 'https://socket.etherdelta.com/getMarket';


request(url , (err, res, body) => {
try{
var json = JSON.parse(body);
console.log(json);


}catch(err){
console.log('parsing error');
console.log(body);
}
});

對此進行了編輯:

var WebSocket = require('ws')
var ws = new WebSocket('wss://socket.etherdelta.com')

ws.onopen = function(){
ws.send(JSON.stringify("getMarket"))

};

ws.onmessage = function(msg){
var response = JSON.parse(msg.data);
console.log(response);
};

似乎此API在WSS協議而不是HTTPS上運行。 您可以嘗試使用以下URL的ws這樣的Web套接字客戶端庫嗎

WSS://socket.etherdelta.com

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM