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
f36c3822
Commit
f36c3822
authored
Apr 27, 2018
by
ken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
试试看吧
parent
f39fbdc5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
8 deletions
+46
-8
testSpeed.js
testSpeed.js
+1
-1
zb.js
zb.js
+45
-7
No files found.
testSpeed.js
View file @
f36c3822
...
@@ -12,7 +12,7 @@ setInterval(()=>{
...
@@ -12,7 +12,7 @@ setInterval(()=>{
function
run
()
{
function
run
()
{
const
before
=
Date
.
now
();
const
before
=
Date
.
now
();
depthByRest
((
err
,
data
)
=>
{
depthByRest
(
"btcusdt"
,
(
err
,
data
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
err
);
console
.
error
(
err
);
return
;
return
;
...
...
zb.js
View file @
f36c3822
...
@@ -10,6 +10,8 @@ const publishKey = "ZB@2";
...
@@ -10,6 +10,8 @@ const publishKey = "ZB@2";
const
accountInfoChannel
=
"getaccountinfo"
;
const
accountInfoChannel
=
"getaccountinfo"
;
const
APIKEY
=
"c2e5bd19-6ac3-489e-8e3a-b6e40b4d5b6d"
;
const
APIKEY
=
"c2e5bd19-6ac3-489e-8e3a-b6e40b4d5b6d"
;
const
APISECRET
=
"15f974c4-fc64-462e-a815-cd0469156300"
;
const
APISECRET
=
"15f974c4-fc64-462e-a815-cd0469156300"
;
const
lastEventTimeMap
=
{};
const
_handleSocketError
=
function
(
error
)
{
const
_handleSocketError
=
function
(
error
)
{
// Errors ultimately result in a `close` event.
// Errors ultimately result in a `close` event.
...
@@ -72,19 +74,23 @@ function subscribe() {
...
@@ -72,19 +74,23 @@ function subscribe() {
const
depth
=
data
;
const
depth
=
data
;
const
key
=
depth
.
channel
.
replace
(
'_'
,
''
).
toUpperCase
()
+
'@zb'
;
const
key
=
depth
.
channel
.
replace
(
'_'
,
''
).
toUpperCase
()
+
'@zb'
;
const
symbol
=
depth
.
channel
.
replace
(
'_depth'
,
''
).
toUpperCase
();
const
symbol
=
depth
.
channel
.
replace
(
'_depth'
,
''
).
toUpperCase
();
console
.
log
(
symbol
+
'@'
+
depth
.
timestamp
*
1000
+
' latency='
+
(
Date
.
now
()
-
depth
.
timestamp
*
1000
)
+
'ms'
);
const
lastEventTime
=
lastEventTimeMap
[
symbol
]
||
0
;
const
publishContent
=
JSON
.
stringify
({
symbol
,
time
:
depth
.
timestamp
*
1000
})
if
(
depth
.
timestamp
>
lastEventTime
)
{
const
depthJson
=
JSON
.
stringify
({
asks
:
depth
.
asks
.
reverse
(),
bids
:
depth
.
bids
,
symbol
})
lastEventTimeMap
[
symbol
]
=
depth
.
timeStamp
;
console
.
log
(
symbol
+
'@'
+
depth
.
timestamp
*
1000
+
' from websocket'
);
const
publishContent
=
JSON
.
stringify
({
symbol
,
time
:
depth
.
timestamp
*
1000
});
const
depthJson
=
JSON
.
stringify
({
asks
:
depth
.
asks
.
reverse
(),
bids
:
depth
.
bids
,
symbol
});
redisClient
.
set
(
key
,
depthJson
,
'EX'
,
1
);
redisClient
.
set
(
key
,
depthJson
,
'EX'
,
1
);
redisClient
.
publish
(
publishKey
,
publishContent
);
redisClient
.
publish
(
publishKey
,
publishContent
);
}
}
}
});
});
}
}
function
depthByRest
(
callback
)
{
function
_request
(
method
,
url
,
callback
)
{
let
opt
=
{
let
opt
=
{
url
:
"http://api.zb.com/data/v1/depth?market=btc_usdt&size=10"
,
url
,
method
:
"GET"
,
method
,
headers
:
{
headers
:
{
Connection
:
"Keep-Alive"
Connection
:
"Keep-Alive"
}
}
...
@@ -102,6 +108,38 @@ function depthByRest(callback) {
...
@@ -102,6 +108,38 @@ function depthByRest(callback) {
});
});
}
}
subscribe
();
function
depthByRest
(
symbol
,
callback
)
{
const
url
=
`http://api.zb.com/data/v1/depth?market=
${
symbol
}
&size=10`
;
_request
(
"GET"
,
url
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
err
);
}
else
{
const
key
=
symbol
.
replace
(
'_'
,
''
).
toUpperCase
()
+
'@zb'
;
const
lastEventTime
=
lastEventTimeMap
[
symbol
]
||
0
;
if
(
data
.
timestamp
>
lastEventTime
)
{
lastEventTimeMap
[
symbol
]
=
data
.
timeStamp
;
console
.
log
(
symbol
+
'@'
+
data
.
timestamp
*
1000
+
' from rest'
);
const
publishContent
=
JSON
.
stringify
({
symbol
,
time
:
data
.
timestamp
*
1000
});
const
depthJson
=
JSON
.
stringify
({
asks
:
data
.
asks
.
reverse
(),
bids
:
data
.
bids
,
symbol
});
redisClient
.
set
(
key
,
depthJson
,
'EX'
,
1
);
redisClient
.
publish
(
publishKey
,
publishContent
);
}
}
if
(
callback
)
{
callback
(
err
,
data
);
}
});
}
function
run
()
{
subscribe
();
setInterval
(()
=>
{
for
(
const
symbol
of
observerSymbol
)
{
depthByRest
(
symbol
);
}
},
500
);
}
run
();
module
.
exports
=
depthByRest
module
.
exports
=
depthByRest
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