Commit 254ef7bc by ken

试试看吧

parent aafa00f6
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
"description": "", "description": "",
"main": "zb.js", "main": "zb.js",
"scripts": { "scripts": {
"zb": "node $NODE_DEBUG_OPTION zb.js" "zb": "node $NODE_DEBUG_OPTION zb.js",
"testSpeed": "node $NODE_DEBUG_OPTION testSpeed.js"
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",
......
const depthByRest = require('./zb');
let total = 0;
let total2 = 0;
let time = 0;
setInterval(()=>{
run();
}, 100 );
function run() {
const before = Date.now();
depthByRest((err, data) => {
if (err) {
console.error(err);
return;
}
const after = Date.now();
total += after - before;
time ++;
total2 += ((after - before) - total / time) * ((after - before) - total / time);
console.log('平均值:' + (total / time) + ' 标准差:' + Math.sqrt(total2 / time));
});
}
run();
\ No newline at end of file
const stream = 'wss://api.zb.com:9999/websocket'; const stream = 'wss://api.zb.com:9999/websocket';
const WebSocket = require('ws'); const WebSocket = require('ws');
const request = require('request');
const crypto = require('crypto'); const crypto = require('crypto');
const options = {}; const options = {};
const observerSymbol = ["btcusdt", 'ethusdt', 'ethbtc', 'eosbtc']; const observerSymbol = ["btcusdt", 'ethusdt', 'ethbtc', 'eosbtc'];
...@@ -80,4 +81,24 @@ function subscribe() { ...@@ -80,4 +81,24 @@ function subscribe() {
}); });
} }
function depthByRest(callback) {
let opt = {
url: "http://api.zb.com/data/v1/depth?market=btc_usdt&size=10",
method: "GET",
};
request(opt, (error, response, body) => {
if ( !callback ) return;
if ( error )
return callback( error, {} );
if ( response && response.statusCode !== 200 )
return callback( response, {} );
return callback( null, JSON.parse(body) );
});
}
subscribe(); subscribe();
module.exports = depthByRest
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment