Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kucoin
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
rongjun
kucoin
Commits
52a3cc3a
Commit
52a3cc3a
authored
May 08, 2019
by
zihan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kucoin更改
parent
ad7e5447
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
102 additions
and
17 deletions
+102
-17
api_kucoin.js
api_kucoin.js
+0
-0
baseCollector.js
baseCollector.js
+11
-1
kucoinCollector.js
kucoinCollector.js
+28
-13
kucoinStrategy3.js
kucoinStrategy3.js
+1
-0
test_kucoin.js
test_kucoin.js
+2
-2
util.js
util.js
+60
-1
No files found.
api_kucoin.js
View file @
52a3cc3a
This diff is collapsed.
Click to expand it.
baseCollector.js
View file @
52a3cc3a
...
@@ -234,7 +234,17 @@ class BaseCollector {
...
@@ -234,7 +234,17 @@ class BaseCollector {
this
.
currencySymbolMap
[
midCurrency
]
=
[
symbol
];
this
.
currencySymbolMap
[
midCurrency
]
=
[
symbol
];
}
}
}
}
this
.
_subscribeSymbols
(
symbolNames
,
this
.
_publishDataForStrategy3
.
bind
(
this
),
5
);
const
filteredSymbols
=
symbolNames
.
filter
((
item
)
=>
{
const
keySymbol
=
this
.
_convertSymbolName
(
item
);
const
mid
=
this
.
getMidCurrency
(
keySymbol
);
if
(
this
.
baseCurrencies
.
includes
(
mid
)){
return
true
;
}
const
array
=
this
.
getSymbols
(
mid
);
return
array
.
length
>
1
});
this
.
_subscribeSymbols
(
filteredSymbols
,
this
.
_publishDataForStrategy3
.
bind
(
this
),
5
);
}
}
runStrategy3
(){
runStrategy3
(){
...
...
kucoinCollector.js
View file @
52a3cc3a
...
@@ -13,7 +13,7 @@ const Strategy3MaxAmountMap = {
...
@@ -13,7 +13,7 @@ const Strategy3MaxAmountMap = {
KCS
:
600
,
KCS
:
600
,
}
}
class
Bibox
Collector
extends
BaseCollector
{
class
Kucoin
Collector
extends
BaseCollector
{
constructor
(
wantedSymbols
){
constructor
(
wantedSymbols
){
super
(
"KUCOIN"
,
baseCurrencies
,
machine
,
wantedSymbols
);
super
(
"KUCOIN"
,
baseCurrencies
,
machine
,
wantedSymbols
);
this
.
api
=
new
biboxApi
(
''
,
''
);
this
.
api
=
new
biboxApi
(
''
,
''
);
...
@@ -31,7 +31,7 @@ class BiboxCollector extends BaseCollector{
...
@@ -31,7 +31,7 @@ class BiboxCollector extends BaseCollector{
const
symbolDetails
=
data
.
data
;
const
symbolDetails
=
data
.
data
;
const
symbolMap
=
{};
const
symbolMap
=
{};
for
(
let
detail
of
symbolDetails
){
for
(
let
detail
of
symbolDetails
){
if
(
baseCurrencies
.
includes
(
detail
.
coinTypePair
)
){
if
(
baseCurrencies
.
includes
(
detail
.
quoteCurrency
)
&&
detail
.
enableTrading
){
symbolMap
[
detail
.
symbol
]
=
detail
;
symbolMap
[
detail
.
symbol
]
=
detail
;
}
}
}
}
...
@@ -45,7 +45,7 @@ class BiboxCollector extends BaseCollector{
...
@@ -45,7 +45,7 @@ class BiboxCollector extends BaseCollector{
}
}
_subscribeSymbols
(
symbols
,
callback
,
subscribeDepth
){
_subscribeSymbols
(
symbols
,
callback
,
subscribeDepth
){
this
.
_fetchDepthByWebsocket
(
symbols
,
subscribeDepth
,
callback
)
this
.
_fetchDepthByWebsocket
(
symbols
.
slice
(
0
,
50
)
,
subscribeDepth
,
callback
)
// setTimeout(()=>{
// setTimeout(()=>{
// this._fetchDepthByRest(symbols,subscribeDepth,callback);
// this._fetchDepthByRest(symbols,subscribeDepth,callback);
// },20000);
// },20000);
...
@@ -80,17 +80,29 @@ class BiboxCollector extends BaseCollector{
...
@@ -80,17 +80,29 @@ class BiboxCollector extends BaseCollector{
_fetchDepthByWebsocket
(
symbols
,
depth
,
callback
){
_fetchDepthByWebsocket
(
symbols
,
depth
,
callback
){
this
.
api
.
subscribeSymbols
(
symbols
,
depth
,
(
error
,
result
)
=>
{
function
subsCallback
(
error
,
result
)
{
if
(
error
){
if
(
error
){
console
.
error
(
"subscribe error"
);
console
.
error
(
"subscribe error"
);
console
.
error
(
error
);
console
.
error
(
error
);
}
else
{
}
else
{
const
data
=
result
.
data
;
callback
(
result
.
asks
.
slice
(
0
,
depth
),
result
.
bids
.
slice
(
0
,
depth
),
result
.
symbol
,
result
.
timestamp
);
const
timeStamp
=
result
.
timestamp
;
}
const
symbol
=
result
.
symbol
;
}
callback
(
data
.
SELL
.
slice
(
0
,
depth
),
data
.
BUY
.
slice
(
0
,
depth
),
symbol
,
timeStamp
,
result
.
seq
);
let
buffer
=
[];
for
(
let
i
=
0
;
i
<
symbols
.
length
;
i
++
)
{
buffer
.
push
(
symbols
[
i
]);
if
(
buffer
.
length
===
95
)
{
const
subsBuffer
=
buffer
;
setTimeout
(()
=>
{
this
.
api
.
subscribeSymbols
(
subsBuffer
,
depth
,
subsCallback
)
},
((
i
+
1
)
/
10
-
1
)
*
50
);
buffer
=
[];
}
else
if
(
i
===
symbols
.
length
-
1
){
setTimeout
(()
=>
{
this
.
api
.
subscribeSymbols
(
buffer
,
depth
,
subsCallback
)
},
((
i
+
1
)
/
10
-
1
)
*
50
);
}
}
}
})
}
}
_getCoinsInfo
(){
_getCoinsInfo
(){
...
@@ -111,11 +123,14 @@ class BiboxCollector extends BaseCollector{
...
@@ -111,11 +123,14 @@ class BiboxCollector extends BaseCollector{
});
});
}
}
_runMonitor
(
callback
){
_runMonitor
(
callback
){
callback
({});
return
;
//todo 接口也改了
let
balanceMap
=
{};
let
balanceMap
=
{};
let
need
=
1
;
let
need
=
1
;
if
(
!
coinInfoMap
){
//
if(!coinInfoMap){
this
.
_getCoinsInfo
()
//
this._getCoinsInfo()
}
//
}
this
.
api
.
balance
(
20
,
1
,
(
error
,
result
)
=>
{
this
.
api
.
balance
(
20
,
1
,
(
error
,
result
)
=>
{
if
(
error
){
if
(
error
){
console
.
error
(
"get balance by rest error:"
);
console
.
error
(
"get balance by rest error:"
);
...
@@ -206,5 +221,5 @@ class BiboxCollector extends BaseCollector{
...
@@ -206,5 +221,5 @@ class BiboxCollector extends BaseCollector{
}
}
module
.
exports
=
Bibox
Collector
;
module
.
exports
=
Kucoin
Collector
;
kucoinStrategy3.js
View file @
52a3cc3a
...
@@ -20,6 +20,7 @@ class BiboxStrategy3 extends Strategy3 {
...
@@ -20,6 +20,7 @@ class BiboxStrategy3 extends Strategy3 {
}
}
_doTrade
(
baseCurrency1
,
midCurrency
,
baseCurrency2
,
buyPrice
,
sellPrice
,
returnPrice
,
amount
,
returnAmount
,
doSaveOrder
)
{
_doTrade
(
baseCurrency1
,
midCurrency
,
baseCurrency2
,
buyPrice
,
sellPrice
,
returnPrice
,
amount
,
returnAmount
,
doSaveOrder
)
{
return
;
const
buySymbol
=
this
.
collector
.
getSymbol
(
baseCurrency1
,
midCurrency
);
const
buySymbol
=
this
.
collector
.
getSymbol
(
baseCurrency1
,
midCurrency
);
const
buyStartTime
=
Date
.
now
();
const
buyStartTime
=
Date
.
now
();
const
collector
=
this
.
collector
;
const
collector
=
this
.
collector
;
...
...
test_kucoin.js
View file @
52a3cc3a
...
@@ -43,7 +43,7 @@ function testCollector(){
...
@@ -43,7 +43,7 @@ function testCollector(){
// const strategy3 = new BiboxStrategy3(collector);
// const strategy3 = new BiboxStrategy3(collector);
// strategy3.run();
// strategy3.run();
}
}
//
testCollector();
testCollector
();
function
printCurrency
(){
function
printCurrency
(){
const
currentArray
=
[,
'ETH'
,
'BTC'
,
'LTC'
,
'BCH'
,
'USDT'
,
'USD'
,
'RMB'
,
"RCN"
,
"WINGS"
,
"TRX"
,
"LEND"
,
"CMT"
,
"POWR"
,
"HSR"
,
"GAS"
,
"RDN"
,
"TNT"
,
"OAX"
const
currentArray
=
[,
'ETH'
,
'BTC'
,
'LTC'
,
'BCH'
,
'USDT'
,
'USD'
,
'RMB'
,
"RCN"
,
"WINGS"
,
"TRX"
,
"LEND"
,
"CMT"
,
"POWR"
,
"HSR"
,
"GAS"
,
"RDN"
,
"TNT"
,
"OAX"
...
@@ -121,7 +121,7 @@ function printCurrency(){
...
@@ -121,7 +121,7 @@ function printCurrency(){
}
}
})
})
}
}
printCurrency
()
//
printCurrency()
function
testOrder
(){
function
testOrder
(){
const
order
=
new
Order
();
const
order
=
new
Order
();
...
...
util.js
View file @
52a3cc3a
...
@@ -39,8 +39,66 @@ function mergeDepth(oldDepth, updateDepth, isAsk) {
...
@@ -39,8 +39,66 @@ function mergeDepth(oldDepth, updateDepth, isAsk) {
return
i
return
i
}
}
function
mergeDepthAsk
(
oldDepth
,
updateDepth
,
oldVersion
)
{
const
results
=
[];
const
cal
=
{
old
:
0
,
updated
:
0
};
for
(;
cal
.
old
<
oldDepth
.
length
||
cal
.
updated
<
updateDepth
.
length
;)
{
if
(
oldDepth
[
cal
.
old
]
===
undefined
)
{
updateDepth
[
cal
.
updated
].
size
>
1
e
-
8
&&
results
.
push
(
updateDepth
[
cal
.
updated
]);
cal
.
updated
++
;
}
else
if
(
updateDepth
[
cal
.
updated
]
===
undefined
)
{
results
.
push
(
oldDepth
[
cal
.
old
]);
cal
.
old
++
;
}
else
if
(
parseFloat
(
oldDepth
[
cal
.
old
].
price
)
>
parseFloat
(
updateDepth
[
cal
.
updated
].
price
))
{
updateDepth
[
cal
.
updated
].
size
>
1
e
-
8
&&
results
.
push
(
updateDepth
[
cal
.
updated
]);
cal
.
updated
++
;
}
else
if
(
parseFloat
(
oldDepth
[
cal
.
old
].
price
)
===
parseFloat
(
updateDepth
[
cal
.
updated
].
price
))
{
if
(
parseFloat
(
updateDepth
[
cal
.
updated
].
size
)
>
1
e
-
8
)
{
results
.
push
(
updateDepth
[
cal
.
updated
]);
}
cal
.
updated
++
;
cal
.
old
++
;
}
else
{
results
.
push
(
oldDepth
[
cal
.
old
]);
cal
.
old
++
;
}
}
return
results
}
function
mergeDepthBids
(
oldDepth
,
updateDepth
,
oldVersion
)
{
const
result
=
[];
const
cal
=
{
old
:
0
,
updated
:
0
};
for
(;
cal
.
old
<
oldDepth
.
length
||
cal
.
updated
<
updateDepth
.
length
;)
{
if
(
oldDepth
[
cal
.
old
]
===
undefined
)
{
updateDepth
[
cal
.
updated
].
size
>
1
e
-
8
&&
result
.
push
(
updateDepth
[
cal
.
updated
]);
cal
.
updated
++
;
}
else
if
(
updateDepth
[
cal
.
updated
]
===
undefined
)
{
result
.
push
(
oldDepth
[
cal
.
old
]);
cal
.
old
++
;
}
else
if
(
parseFloat
(
oldDepth
[
cal
.
old
].
price
)
<
parseFloat
(
updateDepth
[
cal
.
updated
].
price
))
{
updateDepth
[
cal
.
updated
].
size
>
1
e
-
8
&&
result
.
push
(
updateDepth
[
cal
.
updated
]);
cal
.
updated
++
;
}
else
if
(
parseFloat
(
oldDepth
[
cal
.
old
].
price
)
===
parseFloat
(
updateDepth
[
cal
.
updated
].
price
))
{
if
(
parseFloat
(
updateDepth
[
cal
.
updated
].
size
)
>
1
e
-
8
)
{
result
.
push
(
updateDepth
[
cal
.
updated
++
]);
cal
.
old
++
;
}
else
{
cal
.
updated
++
;
cal
.
old
++
;
}
}
else
{
result
.
push
(
oldDepth
[
cal
.
old
++
])
}
}
return
result
;
}
module
.
exports
=
{
module
.
exports
=
{
IPs
:
ips
,
IPs
:
ips
,
mergeDepth
:
mergeDepth
mergeDepthBids
:
mergeDepthBids
,
mergeDepthAsk
:
mergeDepthAsk
,
mergeDepth
:
mergeDepth
}
}
\ No newline at end of file
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