* 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)
| 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 |
no test coverage detected