Commit 166d7a62 by zihan

使用多ip获取深度

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