Commit 700f259b by ken

balance

parent d407e1cf
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 crypto = require('crypto');
const options = {}; const options = {};
const observerSymbol = ["btcusdt", 'ethusdt', 'ltcusdt', 'bccusdt',]; const observerSymbol = ["btcusdt", 'ethusdt', 'ltcusdt', 'bccusdt',];
const redis = require('redis'); const redis = require('redis');
const redisClient = redis.createClient(); const redisClient = redis.createClient();
const publishKey = "ZB@2"; const publishKey = "ZB@2";
const accountInfoChannel = "getaccountinfo"; const accountInfoChannel = "getaccountinfo";
const APIKEY = "c2e5bd19-6ac3-489e-8e3a-b6e40b4d5b6d";
const APISECRET = "15f974c4-fc64-462e-a815-cd0469156300";
const _handleSocketError = function(error) { const _handleSocketError = function(error) {
// Errors ultimately result in a `close` event. // Errors ultimately result in a `close` event.
...@@ -23,7 +26,10 @@ const _handleSocketOpen = function(opened_callback) { ...@@ -23,7 +26,10 @@ 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));
} }
this.send(JSON.stringify({event: 'addChannel', channel: accountInfoChannel})); let accountReq = `{'accesskey':'${APIKEY}','channel':'${accountInfoChannel}','event':'addChannel'`;
const sign = crypto.createHmac('sha1', APISECRET).update(accountReq).digest().toString('base64');
accountReq += `,'sign':${sign}`;
this.send(accountReq);
}; };
const _handleSocketClose = function(code, reason) { const _handleSocketClose = function(code, reason) {
...@@ -53,8 +59,7 @@ const _subscribe = function(callback, opened_callback = false) { ...@@ -53,8 +59,7 @@ const _subscribe = function(callback, opened_callback = false) {
function subscribe() { function subscribe() {
_subscribe((data) => { _subscribe((data) => {
if (data.channel === accountInfoChannel) { if (data.channel === accountInfoChannel && data.success) {
console.log(data);
const coins = data.data.coins; const coins = data.data.coins;
const balances = {}; const balances = {};
for (const coin of coins) { for (const coin of coins) {
......
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