Commit 0644be84 by ken

改key

parent 664e0558
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"ezcrypto": "0.0.3",
"redis": "^2.8.0", "redis": "^2.8.0",
"request": "^2.85.0", "request": "^2.85.0",
"ws": "^5.1.0" "ws": "^5.1.0"
......
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 request = require('request');
const crypto = require('crypto'); const crypto = require('ezcrypto').Crypto;
const options = {}; const options = {};
const observerSymbol = ["btcusdt", 'ethusdt', 'ethbtc', 'eosbtc']; const observerSymbol = ["btcusdt", 'ethusdt', 'ethbtc', 'eosbtc'];
const redis = require('redis'); const redis = require('redis');
...@@ -13,6 +13,27 @@ const APISECRET = "30577876-ddd0-4969-92f9-f6a1dfb85703"; ...@@ -13,6 +13,27 @@ const APISECRET = "30577876-ddd0-4969-92f9-f6a1dfb85703";
const lastEventTimeMap = {}; const lastEventTimeMap = {};
function signParams2Str(params) {
// const accountReq = {accesskey: APIKEY,channel: accountInfoChannel,event: "addChannel", sign: "a5f785d4627ae21f4b4baf9c1baf1a60"};
let paramsSort = sortDict(params);
const paramsSortString = JSON.stringify(paramsSort);
let digest = crypto.SHA1(APISECRET);
let sign = crypto.HMAC(crypto.MD5, paramsSortString, digest);
paramsSort['sign'] = sign;
return JSON.stringify(paramsSort);
}
function sortDict(dict) {
let dict2 = {},
keys = Object.keys(dict).sort();
for (let key of keys) {
dict2[key] = dict[key]
}
return dict2
}
const _handleSocketError = function(error) { const _handleSocketError = function(error) {
// Errors ultimately result in a `close` event. // Errors ultimately result in a `close` event.
// see: https://github.com/websockets/ws/blob/828194044bf247af852b31c49e2800d557fedeff/lib/websocket.js#L126 // see: https://github.com/websockets/ws/blob/828194044bf247af852b31c49e2800d557fedeff/lib/websocket.js#L126
...@@ -29,7 +50,13 @@ const _handleSocketOpen = function(opened_callback) { ...@@ -29,7 +50,13 @@ const _handleSocketOpen = function(opened_callback) {
const req = {event: 'addChannel', channel: symbol + '_depth'}; const req = {event: 'addChannel', channel: symbol + '_depth'};
this.send(JSON.stringify(req)); this.send(JSON.stringify(req));
} }
const accountReq = {accesskey: APIKEY,channel: accountInfoChannel,event: "addChannel", sign: "9719e6907ee292b8eee9ec93c8db4145"}; const accountReq = {
accesskey: APIKEY,
channel: accountInfoChannel,
event: "addChannel",
};
const sign = signParams2Str(accountReq);
accountReq.sign = sign;
console.log(JSON.stringify(accountReq)); console.log(JSON.stringify(accountReq));
setInterval(() => { setInterval(() => {
this.send(JSON.stringify(accountReq)); this.send(JSON.stringify(accountReq));
......
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