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
026024e7
Commit
026024e7
authored
May 29, 2019
by
zihan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码基本改完了
parent
a669f277
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
40 deletions
+41
-40
api_kucoin.js
api_kucoin.js
+11
-19
kucoinStrategy3.js
kucoinStrategy3.js
+3
-3
order_kucoin.js
order_kucoin.js
+17
-17
test_kucoin.js
test_kucoin.js
+10
-1
No files found.
api_kucoin.js
View file @
026024e7
...
...
@@ -46,12 +46,9 @@ let getUpdatedData = function (currentData, response) {
class
biboxApi
{
constructor
()
{
this
.
apiKey
=
'5ce8b7ae134ab72e8c06b112'
;
this
.
apiSecret
=
'd355354d-eac5-46fb-a2cf-4342f5bc7055'
;
this
.
pass
=
'Kinming0123@#$%'
;
// this.apiKey = '5c2db93503aa674c74a31734';
// this.apiSecret = 'f03a5284-5c39-4aaa-9b20-dea10bdcf8e3';
// this.pass = 'Abc123456';
this
.
apiKey
=
process
.
env
[
'KEY'
];
this
.
apiSecret
=
process
.
env
[
'SECRET'
];
this
.
pass
=
process
.
env
[
'PASS'
];
this
.
allowRequest
=
true
;
this
.
index
=
0
;
}
...
...
@@ -196,16 +193,6 @@ class biboxApi {
return
str
.
join
(
"&"
);
}
objKeySort
(
obj
)
{
//排序的函数
var
newkey
=
Object
.
keys
(
obj
).
sort
();
//先用Object内置类的keys方法获取要排序对象的属性名,再利用Array原型上的sort方法对获取的属性名进行排序,newkey是一个数组
var
newObj
=
{};
//创建一个新的对象,用于存放排好序的键值对
for
(
var
i
=
0
;
i
<
newkey
.
length
;
i
++
)
{
//遍历newkey数组
newObj
[
newkey
[
i
]]
=
obj
[
newkey
[
i
]];
//向新创建的对象中按照排好的顺序依次增加键值对
}
return
newObj
;
//返回排好序的新对象
}
_publicRequest
(
path
,
params
,
callback
,
bindIP
,
method
=
'GET'
)
{
if
(
!
this
.
allowRequest
)
{
callback
({
code
:
"-2"
,
message
:
"出现超频情况,暂停提交请求"
});
...
...
@@ -255,7 +242,12 @@ class biboxApi {
}
_genSign
(
timestamp
,
method
,
path
,
params
){
const
signStr
=
timestamp
+
method
+
path
+
JSON
.
stringify
(
params
);
let
signStr
=
null
;
if
(
params
){
signStr
=
timestamp
+
method
+
path
+
JSON
.
stringify
(
params
);
}
else
{
signStr
=
timestamp
+
method
+
path
;
}
const
signed
=
crypto
.
createHmac
(
'sha256'
,
this
.
apiSecret
).
update
(
signStr
).
digest
(
'base64'
);
return
signed
}
...
...
@@ -277,8 +269,8 @@ class biboxApi {
}
const
requestParams
=
{};
if
(
method
===
'GET'
&&
params
)
{
url
+=
'?'
+
this
.
transform
(
params
);
}
else
{
url
+=
'?'
+
this
.
transform
(
params
);
}
else
if
(
method
===
'POST'
)
{
requestParams
[
"body"
]
=
JSON
.
stringify
(
params
);
}
requestParams
[
"url"
]
=
url
;
...
...
kucoinStrategy3.js
View file @
026024e7
...
...
@@ -36,7 +36,7 @@ class BiboxStrategy3 extends Strategy3 {
console
.
log
(
"sell@"
+
sellSymbol
+
" amount:"
+
amount
+
" price:"
+
sellPrice
);
const
sellStartTime
=
Date
.
now
();
orderService
.
order
(
sellSymbol
,
sellPrice
,
amount
,
constants
.
OrderSideSell
sellSymbol
,
sellPrice
,
amount
,
constants
.
OrderSideSell
,
constants
.
TimeInForceGTC
,
(
error
,
order
)
=>
{
if
(
error
)
{
if
(
error
.
code
===
"NO_BALANCE"
||
(
error
.
code
===
'ERROR'
&&
error
.
msg
===
'SYMBOL NOT FOUND'
)
||
error
.
statusCode
==
502
||
error
.
code
==
'ECONNRESET'
)
{
...
...
@@ -65,7 +65,7 @@ class BiboxStrategy3 extends Strategy3 {
function
returnOrder
()
{
console
.
log
(
"return@"
+
returnSymbol
+
" amount:"
+
returnAmount
+
" price:"
+
returnPrice
);
const
returnStartTime
=
Date
.
now
();
orderService
.
order
(
returnSymbol
,
returnPrice
,
returnAmount
,
collector
.
getTradeSide
(
baseCurrency2
,
baseCurrency1
)
orderService
.
order
(
returnSymbol
,
returnPrice
,
returnAmount
,
collector
.
getTradeSide
(
baseCurrency2
,
baseCurrency1
)
,
constants
.
TimeInForceGTC
,
(
error
,
order
)
=>
{
if
(
error
)
{
console
.
error
(
"return error:"
);
...
...
@@ -78,7 +78,7 @@ class BiboxStrategy3 extends Strategy3 {
}
console
.
log
(
"buy@"
+
buySymbol
+
" amount:"
+
amount
+
" price:"
+
buyPrice
);
orderService
.
FOKLikeOrder
(
buySymbol
,
buyPrice
,
amount
,
constants
.
OrderSideBuy
orderService
.
order
(
buySymbol
,
buyPrice
,
amount
,
constants
.
OrderSideBuy
,
constants
.
TimeInForceFOK
,
(
error
,
order
)
=>
{
if
(
error
)
{
console
.
error
(
"buy error:"
);
...
...
order_kucoin.js
View file @
026024e7
...
...
@@ -85,22 +85,22 @@ class Order {
}
}
FOKLikeOrder
(
symbol
,
price
,
amount
,
side
,
callback
)
{
if
(
!
constants
.
RealOrder
)
{
callback
(
null
,
returnFakeOrder
(
symbol
,
price
,
amount
));
return
;
}
this
.
api
.
order
(
price
,
amount
,
symbol
,
side
,
(
error
,
result
)
=>
{
if
(
error
)
{
callback
(
error
,
null
);
return
;
}
const
orderId
=
result
.
data
.
orderOid
;
setTimeout
(()
=>
{
this
.
api
.
searchOrder
(
orderId
,
symbol
,
side
,
this
.
_handleFOKSearchResult
.
bind
(
this
,
orderId
,
symbol
,
side
,
price
,
callback
));
},
100
);
})
}
//
FOKLikeOrder(symbol, price, amount, side, callback) {
//
if (!constants.RealOrder) {
//
callback(null, returnFakeOrder(symbol, price, amount));
//
return;
//
}
//
this.api.order(price, amount, symbol, side, (error, result) => {
//
if (error) {
//
callback(error, null);
//
return;
//
}
//
const orderId = result.data.orderOid;
//
setTimeout(()=>{
//
this.api.searchOrder(orderId, symbol, side, this._handleFOKSearchResult.bind(this, orderId, symbol, side, price, callback));
//
},100);
//
})
//
}
order
(
symbol
,
price
,
amount
,
side
,
timeInForce
,
callback
)
{
const
cliordId
=
Date
.
now
()
+
Math
.
floor
(
Math
.
random
()
*
100
)
+
''
;
...
...
@@ -135,7 +135,7 @@ class Order {
}
}
this
.
api
.
searchOrder
(
orderId
,
symbol
,
side
,
handleSearchResult
.
bind
(
this
));
this
.
api
.
searchOrder
(
orderId
,
handleSearchResult
.
bind
(
this
));
})
}
}
...
...
test_kucoin.js
View file @
026024e7
...
...
@@ -124,10 +124,19 @@ function printCurrency(){
// printCurrency()
function
testOrder
(){
// const order = new Order();
const
Order
=
require
(
'./order_kucoin'
);
const
order
=
new
Order
();
const
biboxApi
=
require
(
'./api_kucoin'
);
const
api
=
new
biboxApi
();
const
ordid
=
Date
.
now
()
+
''
;
// order.order('BTC-USDT', '0.1', '0.001', 'buy', constants.TimeInForceFOK, (error,result)=>{
// console.log(error);
// console.log(result);
// })
// api.searchOrder('5cee68a05137b96b7ebe32d9',(error,result)=>{
// console.log(error);
// console.log(result);
// })
// api.order(ordid, "1","1","BTC-USDT",'buy',constants.TimeInForceFOK,(error,result)=>{
// console.log(error);
// console.log(result);
...
...
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