MCPcopy
hub / github.com/Mathieu2301/TradingView-API / setMarket

Method setMarket

src/chart/session.js:341–397  ·  view source on GitHub ↗

* Set the chart market * @param {string} symbol Market symbol * @param {Object} [options] Chart options * @param {import('../types').TimeFrame} [options.timeframe] Chart period timeframe * @param {number} [options.range] Number of loaded periods/candles (Default: 100) * @param {number

(symbol, options = {})

Source from the content-addressed store, hash-verified

339 * @param {number} [options.replay] Replay mode starting point (Timestamp)
340 */
341 setMarket(symbol, options = {}) {
342 this.#periods = {};
343
344 if (this.#replayMode) {
345 this.#replayMode = false;
346 this.#client.send('replay_delete_session', [this.#replaySessionID]);
347 }
348
349 const symbolInit = {
350 symbol: symbol || 'BTCEUR',
351 adjustment: options.adjustment || 'splits',
352 };
353
354 if (options.backadjustment) symbolInit.backadjustment = 'default';
355 if (options.session) symbolInit.session = options.session;
356 if (options.currency) symbolInit['currency-id'] = options.currency;
357
358 if (options.replay) {
359 if (!this.#replayMode) {
360 this.#replayMode = true;
361 this.#client.send('replay_create_session', [this.#replaySessionID]);
362 }
363
364 this.#client.send('replay_add_series', [
365 this.#replaySessionID,
366 'req_replay_addseries',
367 `=${JSON.stringify(symbolInit)}`,
368 options.timeframe,
369 ]);
370
371 this.#client.send('replay_reset', [
372 this.#replaySessionID,
373 'req_replay_reset',
374 options.replay,
375 ]);
376 }
377
378 const complex = options.type || options.replay;
379 const chartInit = complex ? {} : symbolInit;
380
381 if (complex) {
382 if (options.replay) chartInit.replay = this.#replaySessionID;
383 chartInit.symbol = symbolInit;
384 chartInit.type = ChartTypes[options.type];
385 if (options.type) chartInit.inputs = { ...options.inputs };
386 }
387
388 this.#currentSeries += 1;
389
390 this.#client.send('resolve_symbol', [
391 this.#chartSessionID,
392 `ser_${this.#currentSeries}`,
393 `=${JSON.stringify(chartInit)}`,
394 ]);
395
396 this.setSeries(options.timeframe, options.range, options.to);
397 }
398

Calls 2

setSeriesMethod · 0.95
sendMethod · 0.80

Tested by

no test coverage detected