Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zbNode
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ken
zbNode
Commits
f22ca9a7
Commit
f22ca9a7
authored
Jul 12, 2018
by
ken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
减少延时
parent
ad26dcf5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
1 deletion
+35
-1
util.js
util.js
+22
-0
zb.js
zb.js
+13
-1
No files found.
util.js
0 → 100644
View file @
f22ca9a7
const
os
=
require
(
'os'
);
function
getLocalIpv4s
()
{
var
ifaces
=
os
.
networkInterfaces
();
var
ips
=
[];
var
func
=
function
(
details
)
{
if
(
details
.
family
===
'IPv6'
||
details
.
internal
)
{
return
;
}
ips
.
push
(
details
.
address
);
};
for
(
var
dev
in
ifaces
)
{
ifaces
[
dev
].
forEach
(
func
);
}
return
ips
;
};
const
ips
=
getLocalIpv4s
();
exports
.
allIps
=
ips
;
\ No newline at end of file
zb.js
View file @
f22ca9a7
...
...
@@ -3,6 +3,7 @@ const stream = 'wss://api.zb.com:9999/websocket';
const
WebSocket
=
require
(
'ws'
);
const
request
=
require
(
'request'
);
const
crypto
=
require
(
'ezcrypto'
).
Crypto
;
const
ips
=
require
(
"./util"
).
allIps
;
const
options
=
{};
const
observerSymbol
=
[
"btcusdt"
,
'ethusdt'
,
'ethbtc'
,
"eosbtc"
,
"eosusdt"
,
'bccusdt'
,
"bccbtc"
];
const
redis
=
require
(
'redis'
);
...
...
@@ -14,8 +15,14 @@ const APISECRET = "001d5649-65f7-4c88-9d31-c429da39989d";
const
lastEventTimeMap
=
{};
let
balanceByRestOk
=
true
;
let
balanceByWebsocketOk
=
true
;
let
currentIpIndex
=
0
;
function
selectIp
()
{
currentIpIndex
=
(
currentIpIndex
+
1
)
%
ips
.
length
;
return
ips
[
currentIpIndex
];
}
function
signParams2Str
(
params
)
{
// const accountReq = {accesskey: APIKEY,channel: accountInfoChannel,event: "addChannel", sign: "a5f785d4627ae21f4b4baf9c1baf1a60"};
let
paramsSort
=
sortDict
(
params
);
...
...
@@ -131,6 +138,7 @@ function subscribe() {
}
function
_request
(
method
,
url
,
callback
)
{
const
ip
=
selectIp
();
let
opt
=
{
url
,
method
,
...
...
@@ -138,6 +146,9 @@ function _request(method, url, callback) {
Connection
:
"Keep-Alive"
}
};
if
(
ip
)
{
opt
.
localAddress
=
ip
;
}
request
(
opt
,
(
error
,
response
,
body
)
=>
{
if
(
!
callback
)
return
;
...
...
@@ -207,11 +218,12 @@ function getBalanceByRest() {
function
run
()
{
subscribe
();
const
depthInterval
=
Math
.
max
(
60
*
1000
/
(
850
*
ips
.
length
/
observerSymbol
.
length
),
300
);
setInterval
(()
=>
{
for
(
const
symbol
of
observerSymbol
)
{
depthByRest
(
symbol
);
}
},
300
);
},
depthInterval
);
setInterval
(()
=>
{
getBalanceByRest
();
},
6000
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment