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
19cccd2b
Commit
19cccd2b
authored
May 08, 2019
by
zihan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixed
parent
f05f64a3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
41 deletions
+60
-41
kucoinCollector.js
kucoinCollector.js
+38
-19
kucoinStrategy3.js
kucoinStrategy3.js
+22
-22
No files found.
kucoinCollector.js
View file @
19cccd2b
...
@@ -188,37 +188,56 @@ class KucoinCollector extends BaseCollector{
...
@@ -188,37 +188,56 @@ class KucoinCollector extends BaseCollector{
return
0.001
;
return
0.001
;
}
}
processAmount
(
fromCurrency
,
toCurrency
,
amount
){
processAmount
(
fromCurrency
,
toCurrency
,
amount
){
//有可能会由于数值过小,传进来的amount被表示为科学计数法法
const
detail
=
this
.
_getSymbolDetail
(
fromCurrency
,
toCurrency
);
const
symbolDetail
=
this
.
_getSymbolDetail
(
fromCurrency
,
toCurrency
);
const
currency
=
symbolDetail
.
coinType
;
if
(
detail
)
{
let
tradePrecision
=
4
;
const
quantityIncrement
=
detail
.
baseIncrement
;
const
coin
=
coinInfoMap
[
currency
];
const
minAmount
=
detail
.
baseMinSize
;
if
(
coin
){
if
(
amount
<
minAmount
){
tradePrecision
=
coin
[
'tradePrecision'
]
||
4
;
return
0
;
}
}
const
amountStr
=
parseFloat
(
amount
).
toFixed
(
10
);
const
ratio
=
amount
/
quantityIncrement
;
const
nums
=
amountStr
.
split
(
'.'
);
if
(
ratio
%
1
===
0
)
{
if
(
nums
.
length
===
2
&&
nums
[
1
].
length
>
tradePrecision
){
return
amount
;
return
nums
[
0
]
+
"."
+
nums
[
1
].
slice
(
0
,
tradePrecision
);
}
const
amountScale
=
Math
.
round
(
Math
.
log
(
quantityIncrement
)
/
Math
.
log
(
10
));
if
(
amountScale
<=
0
)
{
return
parseFloat
(
amount
).
toFixed
(
Math
.
abs
(
amountScale
));
}
else
{
return
`
${
Math
.
floor
(
ratio
)
*
quantityIncrement
}
`
;
}
}
}
return
amount
;
return
amount
;
}
}
processPrice
(
fromCurrency
,
toCurrency
,
price
){
processPrice
(
fromCurrency
,
toCurrency
,
price
){
// const amountStr = price+'';
const
detail
=
this
.
_getSymbolDetail
(
fromCurrency
,
toCurrency
);
// const nums = amountStr.split('.');
if
(
detail
)
{
// if(nums.length ===2 && nums[1].length>4){
const
tickSize
=
detail
.
priceIncrement
;
// return nums[0]+"."+nums[1].slice(0,4);
// console.log("tickSize是:"+tickSize);
// }
const
ratio
=
price
/
tickSize
;
if
(
ratio
%
1
===
0
)
{
return
price
;
}
const
priceScale
=
Math
.
round
(
Math
.
log
(
tickSize
)
/
Math
.
log
(
10
));
if
(
priceScale
<=
0
)
{
return
parseFloat
(
price
).
toFixed
(
Math
.
abs
(
priceScale
));
}
else
{
return
`
${
Math
.
round
(
ratio
)
*
tickSize
}
`
;
}
}
return
price
;
return
price
;
}
}
getCurrencyMaxReturnAmount
(
currency
){
getCurrencyMaxReturnAmount
(
currency
){
const
balance
=
this
.
getCurrencyBalance
(
currency
);
// const balance = this.getCurrencyBalance(currency);
return
Math
.
min
(
Strategy3MaxAmountMap
[
currency
],
balance
);
// return Math.min(Strategy3MaxAmountMap[currency],balance);
//todo
return
Strategy3MaxAmountMap
[
currency
]
||
1
;
}
}
getDepthPrintStr
(
fromCurrency
,
toCurrency
,
depth
=
1
){
getDepthPrintStr
(
fromCurrency
,
toCurrency
,
depth
=
1
){
return
super
.
getDepthPrintStr
(
fromCurrency
,
toCurrency
,
3
);
return
super
.
getDepthPrintStr
(
fromCurrency
,
toCurrency
,
3
);
}
}
}
}
module
.
exports
=
KucoinCollector
;
module
.
exports
=
KucoinCollector
;
...
...
kucoinStrategy3.js
View file @
19cccd2b
...
@@ -145,28 +145,28 @@ class BiboxStrategy3 extends Strategy3 {
...
@@ -145,28 +145,28 @@ class BiboxStrategy3 extends Strategy3 {
_getMinMargin
()
{
_getMinMargin
()
{
return
0.08
;
return
0.08
;
}
}
_giveUpOrder
(
baseCurrency1
,
midCurrency
,
baseCurrency2
,
totalMarginRate
,
buyDepth
,
sellDepth
)
{
//
_giveUpOrder(baseCurrency1, midCurrency, baseCurrency2, totalMarginRate, buyDepth, sellDepth) {
if
(
sellDepth
===
1
)
{
//
if (sellDepth === 1) {
const
sellPrices
=
this
.
collector
.
getDepth
(
midCurrency
,
baseCurrency2
,
2
);
//
const sellPrices = this.collector.getDepth(midCurrency, baseCurrency2, 2);
const
possibleLoss
=
(
sellPrices
[
0
][
0
]
-
sellPrices
[
1
][
0
])
/
sellPrices
[
0
][
0
];
//
const possibleLoss = (sellPrices[0][0] - sellPrices[1][0]) / sellPrices[0][0];
// if(sellPrices[0][0] === this.lastPrice){
//
// if(sellPrices[0][0] === this.lastPrice){
// this.samePriceCount ++;
//
// this.samePriceCount ++;
// }else{
//
// }else{
// this.lastPrice = sellPrices[0][0];
//
// this.lastPrice = sellPrices[0][0];
// this.samePriceCount = 0;
//
// this.samePriceCount = 0;
// }
//
// }
const
possibleLossMoney
=
(
possibleLoss
-
totalMarginRate
/
100
)
*
sellPrices
[
1
][
0
];
//
const possibleLossMoney = (possibleLoss - totalMarginRate / 100) * sellPrices[1][0];
if
(
possibleLossMoney
>
this
.
maxAllowLoss
)
{
//
if (possibleLossMoney > this.maxAllowLoss) {
console
.
log
(
`此单风险过高,放弃。可能损失:
${
possibleLossMoney
}
,
${
baseCurrency1
}
=>
${
midCurrency
}
=>
${
baseCurrency2
}
`
);
//
console.log(`此单风险过高,放弃。可能损失:${possibleLossMoney},${baseCurrency1}=>${midCurrency}=>${baseCurrency2}`);
return
true
;
//
return true;
}
//
}
// if(possibleLoss*100-totalMarginRate > 3){
//
// if(possibleLoss*100-totalMarginRate > 3){
// console.log(`此单风险过高,放弃。买一:${sellPrices[0][0]},买二:${sellPrices[1][0]},损失率${(possibleLoss * 100).toFixed(4)},利差:${totalMarginRate.toFixed(4)}`);
//
// console.log(`此单风险过高,放弃。买一:${sellPrices[0][0]},买二:${sellPrices[1][0]},损失率${(possibleLoss * 100).toFixed(4)},利差:${totalMarginRate.toFixed(4)}`);
// return true;
//
// return true;
// }
//
// }
}
//
}
return
super
.
_giveUpOrder
(
baseCurrency1
,
midCurrency
,
baseCurrency2
,
totalMarginRate
,
buyDepth
,
sellDepth
);
//
return super._giveUpOrder(baseCurrency1, midCurrency, baseCurrency2, totalMarginRate, buyDepth, sellDepth);
}
//
}
_logDelay
()
{
_logDelay
()
{
return
true
;
return
true
;
}
}
...
...
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