Skip to content

Commit f9fb1ce

Browse files
committed
remove async dep
1 parent ea557c3 commit f9fb1ce

1 file changed

Lines changed: 38 additions & 9 deletions

File tree

src/node-binance-api.ts

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import nodeFetch from 'node-fetch';
1515
// @ts-ignore
1616
import zip from 'lodash.zipobject';
1717
import stringHash from 'string-hash';
18-
import async from 'async';
1918
// eslint-disable-next-line
2019
import { Interval, PositionRisk, Order, FuturesOrder, PositionSide, WorkingType, OrderType, OrderStatus, TimeInForce, Callback, IConstructorArgs, OrderSide, FundingRate, CancelOrder, AggregatedTrade, Trade, MyTrade, WithdrawHistoryResponse, DepositHistoryResponse, DepositAddress, WithdrawResponse, Candle, FuturesCancelAllOpenOrder, OrderBook, Ticker, FuturesUserTrade, Account, FuturesAccountInfo, FuturesBalance, QueryOrder, HttpMethod, BookTicker, DailyStats, PremiumIndex, OpenInterest, IWebsocketsMethods } from './types';
2120
// export { Interval, PositionRisk, Order, FuturesOrder, PositionSide, WorkingType, OrderType, OrderStatus, TimeInForce, Callback, IConstructorArgs, OrderSide, FundingRate, CancelOrder, AggregatedTrade, Trade, MyTrade, WithdrawHistoryResponse, DepositHistoryResponse, DepositAddress, WithdrawResponse, Candle, FuturesCancelAllOpenOrder, OrderBook, Ticker, FuturesUserTrade, FuturesAccountInfo, FuturesBalance, QueryOrder } from './types';
@@ -5682,6 +5681,21 @@ export default class Binance {
56825681
return (subscription as any).url;
56835682
}
56845683

5684+
async mapLimit(array, limit, asyncFn) {
5685+
const results = [];
5686+
let i = 0;
5687+
5688+
const workers = new Array(limit).fill(0).map(async () => {
5689+
while (i < array.length) {
5690+
const currentIndex = i++;
5691+
const result = await asyncFn(array[currentIndex]);
5692+
results[currentIndex] = result;
5693+
}
5694+
});
5695+
await Promise.all(workers);
5696+
return results;
5697+
}
5698+
56855699
/**
56865700
* Websocket depth cache
56875701
* @param {array/string} symbols - an array or string of symbols to query
@@ -5765,20 +5779,35 @@ export default class Binance {
57655779
return symbol.toLowerCase() + `@depth@100ms`;
57665780
});
57675781
subscription = this.subscribeCombined(streams, handleDepthStreamData, reconnect, function () {
5768-
async.mapLimit(symbols, 50, getSymbolDepthSnapshot, (err, results) => {
5769-
if (err) throw err;
5770-
results.forEach(updateSymbolDepthCache);
5771-
});
5782+
// async.mapLimit(symbols, 50, getSymbolDepthSnapshot, (err, results) => {
5783+
// if (err) throw err;
5784+
// results.forEach(updateSymbolDepthCache);
5785+
// });
5786+
this.mapLimit(symbols, 50, getSymbolDepthSnapshot)
5787+
.then(results => {
5788+
results.forEach(updateSymbolDepthCache);
5789+
})
5790+
.catch(err => {
5791+
throw err;
5792+
});
57725793
});
57735794
symbols.forEach(s => assignEndpointIdToContext(s, subscription.endpoint));
57745795
} else {
57755796
const symbol = symbols;
57765797
symbolDepthInit(symbol);
57775798
subscription = this.subscribe(symbol.toLowerCase() + `@depth@100ms`, handleDepthStreamData, reconnect, function () {
5778-
async.mapLimit([symbol], 1, getSymbolDepthSnapshot, (err, results) => {
5779-
if (err) throw err;
5780-
results.forEach(updateSymbolDepthCache);
5781-
});
5799+
// async.mapLimit([symbol], 1, getSymbolDepthSnapshot, (err, results) => {
5800+
// if (err) throw err;
5801+
// results.forEach(updateSymbolDepthCache);
5802+
// });
5803+
this.mapLimit([symbol], 1, getSymbolDepthSnapshot)
5804+
.then(results => {
5805+
results.forEach(updateSymbolDepthCache);
5806+
})
5807+
.catch(err => {
5808+
throw err;
5809+
});
5810+
57825811
});
57835812
assignEndpointIdToContext(symbol, subscription.endpoint);
57845813
}

0 commit comments

Comments
 (0)