* Websocket candle sticks * @param {array/string} symbols - an array or string of symbols to query * @param {string} interval - the time interval * @param {function} callback - callback function * @return {string} the websocket endpoint
(symbols: string[] | string, interval: Interval, callback: Callback)
| 6723 | * @return {string} the websocket endpoint |
| 6724 | */ |
| 6725 | candlesticksStream(symbols: string[] | string, interval: Interval, callback: Callback) { |
| 6726 | const reconnect = () => { |
| 6727 | if (this.Options.reconnect) this.candlesticksStream(symbols, interval, callback); |
| 6728 | }; |
| 6729 | |
| 6730 | /* If an array of symbols are sent we use a combined stream connection rather. |
| 6731 | This is transparent to the developer, and results in a single socket connection. |
| 6732 | This essentially eliminates "unexpected response" errors when subscribing to a lot of data. */ |
| 6733 | let subscription; |
| 6734 | if (Array.isArray(symbols)) { |
| 6735 | if (!this.isArrayUnique(symbols)) throw Error('candlesticks: "symbols" cannot contain duplicate elements.'); |
| 6736 | const streams = symbols.map(function (symbol) { |
| 6737 | return symbol.toLowerCase() + '@kline_' + interval; |
| 6738 | }); |
| 6739 | subscription = this.subscribeCombined(streams, callback, reconnect); |
| 6740 | } else { |
| 6741 | const symbol = symbols.toLowerCase(); |
| 6742 | subscription = this.subscribe(symbol + '@kline_' + interval, callback, reconnect); |
| 6743 | } |
| 6744 | return (subscription as any).url; |
| 6745 | } |
| 6746 | |
| 6747 | /** |
| 6748 | * Websocket mini ticker |
no test coverage detected