Commit 166d7a62 by zihan

使用多ip获取深度

parent 852d5481
...@@ -75,7 +75,7 @@ class biboxApi { ...@@ -75,7 +75,7 @@ class biboxApi {
return newObj;//返回排好序的新对象 return newObj;//返回排好序的新对象
} }
_publicRequest(path, params, callback) { _publicRequest(path, params,bindIP, callback) {
if(!this.allowRequest){ if(!this.allowRequest){
callback({code:"-2",message:"出现超频情况,暂停提交请求"}); callback({code:"-2",message:"出现超频情况,暂停提交请求"});
return; return;
...@@ -96,6 +96,8 @@ class biboxApi { ...@@ -96,6 +96,8 @@ class biboxApi {
method: 'GET', method: 'GET',
timeout: 8000, timeout: 8000,
forever: true, forever: true,
localAddress:bindIP,
}; };
request(options, (error, response, body) => { request(options, (error, response, body) => {
if (error) { if (error) {
...@@ -232,8 +234,8 @@ class biboxApi { ...@@ -232,8 +234,8 @@ class biboxApi {
}; };
this._request("POST","/v1/orderpending","orderpending/pendingHistoryList",params,callback); this._request("POST","/v1/orderpending","orderpending/pendingHistoryList",params,callback);
} }
getOrderbook(symbol,depth,callback){ getOrderbook(symbol,depth,bindIP,callback){
this._publicRequest("/v1/open/orders",{"symbol":symbol},callback); this._publicRequest("/v1/open/orders",{"symbol":symbol},bindIP,callback);
} }
} }
......
...@@ -4,6 +4,7 @@ const restCurrencies = ["PRA","AAC","AT","RED","BU","QTUM","EOSDAC","HPB","ORME" ...@@ -4,6 +4,7 @@ const restCurrencies = ["PRA","AAC","AT","RED","BU","QTUM","EOSDAC","HPB","ORME"
const machine = process.env['MACHINE']; const machine = process.env['MACHINE'];
const biboxApi = require('./api_kucoin'); const biboxApi = require('./api_kucoin');
const zlib = require('zlib'); const zlib = require('zlib');
const IPReader = require('./util');
let coinInfoMap = null let coinInfoMap = null
const Strategy3MaxAmountMap = { const Strategy3MaxAmountMap = {
USDT: 300, USDT: 300,
...@@ -69,14 +70,16 @@ class BiboxCollector extends BaseCollector{ ...@@ -69,14 +70,16 @@ class BiboxCollector extends BaseCollector{
// } // }
const perInterval = 8; const perInterval = 8;
const totalInterval = perInterval * restSymbols.length; const totalInterval = perInterval * restSymbols.length;
const IPs = IPReader.allIps;
setInterval(()=>{ setInterval(()=>{
const sortedSymbols = restSymbols.sort(()=>{ const sortedSymbols = restSymbols.sort(()=>{
return Math.random()>0.5 return Math.random()>0.5
}); });
for(let i=0;i<sortedSymbols.length;i++){ for(let i=0;i<sortedSymbols.length;i++){
const symbol = sortedSymbols[i]; const symbol = sortedSymbols[i];
const ipAddress = IPs[i%IPs.length];
setTimeout(()=>{ setTimeout(()=>{
this.api.getOrderbook(symbol,depth,(error,result)=>{ this.api.getOrderbook(symbol,depth,ipAddress,(error,result)=>{
if(error){ if(error){
console.error("get depth by rest error:"); console.error("get depth by rest error:");
console.error(error); console.error(error);
......
const os = require('os');
function getLocalIpv4s() {
var ifaces = os.networkInterfaces();
var ips = [];
var func = function(details) {
if (details.family === 'IPv6' || details.internal) {
return;
}
ips.push(details.address);
};
for (var dev in ifaces) {
ifaces[dev].forEach(func);
}
return ips;
};
const ips = getLocalIpv4s();
exports.allIps = ips;
\ 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