Commit 700f259b by ken

balance

parent d407e1cf
const stream = 'wss://api.zb.com:9999/websocket';
const WebSocket = require('ws');
const crypto = require('crypto');
const options = {};
const observerSymbol = ["btcusdt", 'ethusdt', 'ltcusdt', 'bccusdt',];
const redis = require('redis');
const redisClient = redis.createClient();
const publishKey = "ZB@2";
const accountInfoChannel = "getaccountinfo";
const APIKEY = "c2e5bd19-6ac3-489e-8e3a-b6e40b4d5b6d";
const APISECRET = "15f974c4-fc64-462e-a815-cd0469156300";
const _handleSocketError = function(error) {
// Errors ultimately result in a `close` event.
......@@ -23,7 +26,10 @@ const _handleSocketOpen = function(opened_callback) {
const req = {event: 'addChannel', channel: symbol + '_depth'};
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) {
......@@ -53,8 +59,7 @@ const _subscribe = function(callback, opened_callback = false) {
function subscribe() {
_subscribe((data) => {
if (data.channel === accountInfoChannel) {
console.log(data);
if (data.channel === accountInfoChannel && data.success) {
const coins = data.data.coins;
const balances = {};
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