MCPcopy Create free account
hub / github.com/ccxt/node-binance-api / sortBids

Method sortBids

src/node-binance-api.ts:3644–3660  ·  view source on GitHub ↗

* Sorts bids * @param {string} symbol - the object * @param {int} max - the max number of bids * @param {string} baseValue - the object * @return {object} - the object

(symbol: string, max = Infinity, baseValue?: string)

Source from the content-addressed store, hash-verified

3642 * @return {object} - the object
3643 */
3644 sortBids(symbol: string, max = Infinity, baseValue?: string) {
3645 const object = {};
3646 let count = 0, cache;
3647 if (typeof symbol === 'object') cache = symbol;
3648 else cache = this.getDepthCache(symbol).bids;
3649 const sorted = Object.keys(cache).sort((a, b) => parseFloat(b) - parseFloat(a));
3650 let cumulative = 0;
3651 for (const price of sorted) {
3652 if (!baseValue) object[price] = cache[price];
3653 else if (baseValue === 'cumulative') {
3654 cumulative += cache[price];
3655 object[price] = cumulative;
3656 } else object[price] = parseFloat((cache[price] * parseFloat(price)).toFixed(8));
3657 if (++count >= max) break;
3658 }
3659 return object;
3660 }
3661
3662 /**
3663 * Sorts asks

Callers 2

example.jsFile · 0.80

Calls 1

getDepthCacheMethod · 0.95

Tested by

no test coverage detected