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