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

Method deliveryChart

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

* Websocket delivery klines * @param {array/string} symbols - an array or string of symbols to query * @param {string} interval - the time interval * @param {function} callback - callback function * @param {int} limit - maximum results, no more than 1000 * @return {string} t

(symbols: string[] | string, interval: Interval, callback: Callback, limit = 500)

Source from the content-addressed store, hash-verified

6031 * @return {string} the websocket endpoint
6032 */
6033 deliveryChart(symbols: string[] | string, interval: Interval, callback: Callback, limit = 500) {
6034 const reconnect = () => {
6035 if (this.Options.reconnect) this.deliveryChart(symbols, interval, callback, limit);
6036 };
6037
6038 const deliveryChartInit = symbol => {
6039 if (typeof this.deliveryMeta[symbol] === 'undefined') this.deliveryMeta[symbol] = {};
6040 if (typeof this.deliveryMeta[symbol][interval] === 'undefined') this.deliveryMeta[symbol][interval] = {};
6041 if (typeof this.deliveryTicks[symbol] === 'undefined') this.deliveryTicks[symbol] = {};
6042 if (typeof this.deliveryTicks[symbol][interval] === 'undefined') this.deliveryTicks[symbol][interval] = {};
6043 if (typeof this.deliveryRealtime[symbol] === 'undefined') this.deliveryRealtime[symbol] = {};
6044 if (typeof this.deliveryRealtime[symbol][interval] === 'undefined') this.deliveryRealtime[symbol][interval] = {};
6045 if (typeof this.deliveryKlineQueue[symbol] === 'undefined') this.deliveryKlineQueue[symbol] = {};
6046 if (typeof this.deliveryKlineQueue[symbol][interval] === 'undefined') this.deliveryKlineQueue[symbol][interval] = [];
6047 this.deliveryMeta[symbol][interval].timestamp = 0;
6048 };
6049
6050 const handleDeliveryKlineStream = kline => {
6051 const symbol = kline.s, interval: Interval = kline.k.i;
6052 if (!this.deliveryMeta[symbol][interval].timestamp) {
6053 if (typeof (this.deliveryKlineQueue[symbol][interval]) !== 'undefined' && kline !== null) {
6054 this.deliveryKlineQueue[symbol][interval].push(kline);
6055 }
6056 } else {
6057 //this.options.log('futures klines at ' + kline.k.t);
6058 this.deliveryKlineHandler(symbol, kline);
6059 if (callback) callback(symbol, interval, this.deliveryKlineConcat(symbol, interval));
6060 }
6061 };
6062
6063 const getDeliveryKlineSnapshot = async (symbol: string, limit = 500) => {
6064 const data = await this.publicDeliveryRequest('v1/klines', { symbol, interval, limit });
6065 this.deliveryKlineData(symbol, interval, data);
6066 //this.options.log('/delivery klines at ' + this.deliveryMeta[symbol][interval].timestamp);
6067 if (typeof this.deliveryKlineQueue[symbol][interval] !== 'undefined') {
6068 for (const kline of this.deliveryKlineQueue[symbol][interval]) this.deliveryKlineHandler(symbol, kline, this.deliveryMeta[symbol][interval].timestamp);
6069 delete this.deliveryKlineQueue[symbol][interval];
6070 }
6071 if (callback) callback(symbol, interval, this.deliveryKlineConcat(symbol, interval));
6072 };
6073
6074 let subscription;
6075 if (Array.isArray(symbols)) {
6076 if (!this.isArrayUnique(symbols)) throw Error('deliveryChart: "symbols" array cannot contain duplicate elements.');
6077 symbols.forEach(deliveryChartInit);
6078 const streams = symbols.map(symbol => `${symbol.toLowerCase()}@kline_${interval}`);
6079 subscription = this.deliverySubscribe(streams, handleDeliveryKlineStream, reconnect);
6080 symbols.forEach(element => getDeliveryKlineSnapshot(element, limit));
6081 } else {
6082 const symbol = symbols;
6083 deliveryChartInit(symbol);
6084 subscription = this.deliverySubscribeSingle(symbol.toLowerCase() + '@kline_' + interval, handleDeliveryKlineStream, reconnect);
6085 getDeliveryKlineSnapshot(symbol, limit);
6086 }
6087 return (subscription as any).url;
6088 }
6089
6090 /**

Callers 1

reconnectMethod · 0.95

Calls 5

isArrayUniqueMethod · 0.95
deliverySubscribeMethod · 0.95
getDeliveryKlineSnapshotFunction · 0.85
deliveryChartInitFunction · 0.85

Tested by

no test coverage detected