来自nodejs的api请求

时间:2018-10-03 08:49:55

标签: javascript node.js api request

有必要使用API​​ https://forkdelta.iohttps://github.com/forkdelta/backend-replacement/tree/master/docs/api获取数据

代码如下:

var http = require("http");

http.createServer(function(request, response) {
   const io = require('socket.io-client');
   socket = io.connect('https://api.forkdelta.com', { transports: 
   ['websocket'] });

socket.on('connect', function() {
    console.log('socket connected');
    socket.emit('getMarket', {
        token: "0x6fff3806bbac52a20e0d79bc538d527f6a22c96b",
        user: "" });

});
socket.on('market', function(payload) {
    console.log(payload.orders.buys);
});

}).listen(3000);

console.log("Server has started.");

我将其保存在server.js中并执行命令节点server.js

我在本地服务器的链接http:// localhost:3000上运行代码-挂起

我从这里https://repl.it/repls/DeafeningBlushingAddons运行代码-成功

请帮助我找出如何从浏览器正确运行代码。接下来,我们打算解析数据数组并将其转换为表。

1 个答案:

答案 0 :(得分:2)

请从执行此代码的位置检查控制台,它实际上是在获取您需要的数据...

这就是数据的样子

{ id: '0xd7ff1f49ffde2380b1fd42877b8ce573bfb2c1cace509b1edcb07e757fa13889_buy',
user: '0x5b38d2298666c89efe5f1819347a6004b93bbbe2',
state: 'OPEN',
tokenGet: '0x6fff3806bbac52a20e0d79bc538d527f6a22c96b',
amountGet: '3.50e+22',
tokenGive: '0x0000000000000000000000000000000000000000',
amountGive: '3.500e+15',
expires: '104747875',
nonce: '1340442292',
v: 27,
r: '0xc929ec3f336b4641d84545d27764c43470946c3119221c856c8f72ac3f625edb',
s: '0x5a79fe5728fb47d22c837ae322bff8b43f3de638ddfa3ee5122bf344a0e507dc',
date: '2018-02-14T20:18:30.052233',
updated: '2018-10-02T10:06:53',
availableVolume: '3.15e+18',
ethAvailableVolume: '3.150000000',
availableVolumeBase: '3.150e+11',
ethAvailableVolumeBase: '3.150000000e-7',
amount: '-3.15e+18',
amountFilled: '0',
price: '1e-7' }