Commit 52a3cc3a by zihan

kucoin更改

parent ad7e5447
......@@ -234,7 +234,17 @@ class BaseCollector {
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(){
......
......@@ -13,7 +13,7 @@ const Strategy3MaxAmountMap = {
KCS: 600,
}
class BiboxCollector extends BaseCollector{
class KucoinCollector extends BaseCollector{
constructor(wantedSymbols){
super("KUCOIN",baseCurrencies,machine,wantedSymbols);
this.api = new biboxApi('','');
......@@ -31,7 +31,7 @@ class BiboxCollector extends BaseCollector{
const symbolDetails = data.data;
const symbolMap = {};
for(let detail of symbolDetails){
if(baseCurrencies.includes(detail.coinTypePair)){
if(baseCurrencies.includes(detail.quoteCurrency) && detail.enableTrading){
symbolMap[detail.symbol] = detail;
}
}
......@@ -45,7 +45,7 @@ class BiboxCollector extends BaseCollector{
}
_subscribeSymbols(symbols,callback,subscribeDepth){
this._fetchDepthByWebsocket(symbols,subscribeDepth,callback)
this._fetchDepthByWebsocket(symbols.slice(0,50),subscribeDepth,callback)
// setTimeout(()=>{
// this._fetchDepthByRest(symbols,subscribeDepth,callback);
// },20000);
......@@ -80,17 +80,29 @@ class BiboxCollector extends BaseCollector{
_fetchDepthByWebsocket(symbols, depth, callback){
this.api.subscribeSymbols(symbols, depth, (error, result)=>{
function subsCallback(error,result){
if(error){
console.error("subscribe error");
console.error(error);
}else{
const data = result.data;
const timeStamp = result.timestamp;
const symbol = result.symbol;
callback(data.SELL.slice(0, depth), data.BUY.slice(0, depth), symbol, timeStamp,result.seq);
callback(result.asks.slice(0,depth), result.bids.slice(0,depth), result.symbol, result.timestamp);
}
}
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(){
......@@ -111,11 +123,14 @@ class BiboxCollector extends BaseCollector{
});
}
_runMonitor(callback){
callback({});
return;
//todo 接口也改了
let balanceMap = {};
let need = 1;
if(!coinInfoMap){
this._getCoinsInfo()
}
// if(!coinInfoMap){
// this._getCoinsInfo()
// }
this.api.balance(20, 1, (error,result)=>{
if(error){
console.error("get balance by rest error:");
......@@ -206,5 +221,5 @@ class BiboxCollector extends BaseCollector{
}
module.exports = BiboxCollector;
module.exports = KucoinCollector;
......@@ -20,6 +20,7 @@ class BiboxStrategy3 extends Strategy3 {
}
_doTrade(baseCurrency1, midCurrency, baseCurrency2, buyPrice, sellPrice, returnPrice, amount, returnAmount, doSaveOrder) {
return;
const buySymbol = this.collector.getSymbol(baseCurrency1, midCurrency);
const buyStartTime = Date.now();
const collector = this.collector;
......
......@@ -43,7 +43,7 @@ function testCollector(){
// const strategy3 = new BiboxStrategy3(collector);
// strategy3.run();
}
// testCollector();
testCollector();
function printCurrency(){
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(){
}
})
}
printCurrency()
// printCurrency()
function testOrder(){
const order = new Order();
......
......@@ -39,8 +39,66 @@ function mergeDepth(oldDepth, updateDepth, isAsk) {
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 > 1e-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 > 1e-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) > 1e-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 > 1e-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 > 1e-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) > 1e-8) {
result.push(updateDepth[cal.updated++]);
cal.old++;
} else {
cal.updated++;
cal.old++;
}
} else {
result.push(oldDepth[cal.old++])
}
}
return result;
}
module.exports = {
IPs: ips,
mergeDepth: mergeDepth
mergeDepthBids:mergeDepthBids,
mergeDepthAsk:mergeDepthAsk,
mergeDepth:mergeDepth
}
\ No newline at end of file
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