Commit 19cccd2b by zihan

bug fixed

parent f05f64a3
......@@ -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;
......
......@@ -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)}`);
// return true;
// }
}
return super._giveUpOrder(baseCurrency1, midCurrency, baseCurrency2, totalMarginRate, buyDepth, sellDepth);
}
// _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)}`);
// // return true;
// // }
// }
// return super._giveUpOrder(baseCurrency1, midCurrency, baseCurrency2, totalMarginRate, buyDepth, sellDepth);
// }
_logDelay() {
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment