Release v20.028 (from a477abd4)

This commit is contained in:
jenkins@tradingview.com
2021-09-10 14:56:00 +00:00
parent 017382d7b8
commit a0f6900107
623 changed files with 2115 additions and 2145 deletions

View File

@@ -4,17 +4,15 @@ import { DataPulseProvider } from './data-pulse-provider';
import { QuotesPulseProvider } from './quotes-pulse-provider';
import { SymbolsStorage } from './symbols-storage';
function extractField(data, field, arrayIndex) {
var value = data[field];
const value = data[field];
return Array.isArray(value) ? value[arrayIndex] : value;
}
/**
* This class implements interaction with UDF-compatible datafeed.
* See UDF protocol reference at https://github.com/tradingview/charting_library/wiki/UDF
*/
var UDFCompatibleDatafeedBase = /** @class */ (function () {
function UDFCompatibleDatafeedBase(datafeedURL, quotesProvider, requester, updateFrequency) {
var _this = this;
if (updateFrequency === void 0) { updateFrequency = 10 * 1000; }
export class UDFCompatibleDatafeedBase {
constructor(datafeedURL, quotesProvider, requester, updateFrequency = 10 * 1000) {
this._configuration = defaultConfiguration();
this._symbolsStorage = null;
this._datafeedURL = datafeedURL;
@@ -24,43 +22,42 @@ var UDFCompatibleDatafeedBase = /** @class */ (function () {
this._dataPulseProvider = new DataPulseProvider(this._historyProvider, updateFrequency);
this._quotesPulseProvider = new QuotesPulseProvider(this._quotesProvider);
this._configurationReadyPromise = this._requestConfiguration()
.then(function (configuration) {
.then((configuration) => {
if (configuration === null) {
configuration = defaultConfiguration();
}
_this._setupWithConfiguration(configuration);
this._setupWithConfiguration(configuration);
});
}
UDFCompatibleDatafeedBase.prototype.onReady = function (callback) {
var _this = this;
this._configurationReadyPromise.then(function () {
callback(_this._configuration);
onReady(callback) {
this._configurationReadyPromise.then(() => {
callback(this._configuration);
});
};
UDFCompatibleDatafeedBase.prototype.getQuotes = function (symbols, onDataCallback, onErrorCallback) {
}
getQuotes(symbols, onDataCallback, onErrorCallback) {
this._quotesProvider.getQuotes(symbols).then(onDataCallback).catch(onErrorCallback);
};
UDFCompatibleDatafeedBase.prototype.subscribeQuotes = function (symbols, fastSymbols, onRealtimeCallback, listenerGuid) {
}
subscribeQuotes(symbols, fastSymbols, onRealtimeCallback, listenerGuid) {
this._quotesPulseProvider.subscribeQuotes(symbols, fastSymbols, onRealtimeCallback, listenerGuid);
};
UDFCompatibleDatafeedBase.prototype.unsubscribeQuotes = function (listenerGuid) {
}
unsubscribeQuotes(listenerGuid) {
this._quotesPulseProvider.unsubscribeQuotes(listenerGuid);
};
UDFCompatibleDatafeedBase.prototype.getMarks = function (symbolInfo, from, to, onDataCallback, resolution) {
}
getMarks(symbolInfo, from, to, onDataCallback, resolution) {
if (!this._configuration.supports_marks) {
return;
}
var requestParams = {
const requestParams = {
symbol: symbolInfo.ticker || '',
from: from,
to: to,
resolution: resolution,
};
this._send('marks', requestParams)
.then(function (response) {
.then((response) => {
if (!Array.isArray(response)) {
var result = [];
for (var i = 0; i < response.id.length; ++i) {
const result = [];
for (let i = 0; i < response.id.length; ++i) {
result.push({
id: extractField(response, 'id', i),
time: extractField(response, 'time', i),
@@ -75,26 +72,26 @@ var UDFCompatibleDatafeedBase = /** @class */ (function () {
}
onDataCallback(response);
})
.catch(function (error) {
logMessage("UdfCompatibleDatafeed: Request marks failed: " + getErrorMessage(error));
.catch((error) => {
logMessage(`UdfCompatibleDatafeed: Request marks failed: ${getErrorMessage(error)}`);
onDataCallback([]);
});
};
UDFCompatibleDatafeedBase.prototype.getTimescaleMarks = function (symbolInfo, from, to, onDataCallback, resolution) {
}
getTimescaleMarks(symbolInfo, from, to, onDataCallback, resolution) {
if (!this._configuration.supports_timescale_marks) {
return;
}
var requestParams = {
const requestParams = {
symbol: symbolInfo.ticker || '',
from: from,
to: to,
resolution: resolution,
};
this._send('timescale_marks', requestParams)
.then(function (response) {
.then((response) => {
if (!Array.isArray(response)) {
var result = [];
for (var i = 0; i < response.id.length; ++i) {
const result = [];
for (let i = 0; i < response.id.length; ++i) {
result.push({
id: extractField(response, 'id', i),
time: extractField(response, 'time', i),
@@ -107,45 +104,45 @@ var UDFCompatibleDatafeedBase = /** @class */ (function () {
}
onDataCallback(response);
})
.catch(function (error) {
logMessage("UdfCompatibleDatafeed: Request timescale marks failed: " + getErrorMessage(error));
.catch((error) => {
logMessage(`UdfCompatibleDatafeed: Request timescale marks failed: ${getErrorMessage(error)}`);
onDataCallback([]);
});
};
UDFCompatibleDatafeedBase.prototype.getServerTime = function (callback) {
}
getServerTime(callback) {
if (!this._configuration.supports_time) {
return;
}
this._send('time')
.then(function (response) {
var time = parseInt(response);
.then((response) => {
const time = parseInt(response);
if (!isNaN(time)) {
callback(time);
}
})
.catch(function (error) {
logMessage("UdfCompatibleDatafeed: Fail to load server time, error=" + getErrorMessage(error));
.catch((error) => {
logMessage(`UdfCompatibleDatafeed: Fail to load server time, error=${getErrorMessage(error)}`);
});
};
UDFCompatibleDatafeedBase.prototype.searchSymbols = function (userInput, exchange, symbolType, onResult) {
}
searchSymbols(userInput, exchange, symbolType, onResult) {
if (this._configuration.supports_search) {
var params = {
const params = {
limit: 30 /* SearchItemsLimit */,
query: userInput.toUpperCase(),
type: symbolType,
exchange: exchange,
};
this._send('search', params)
.then(function (response) {
.then((response) => {
if (response.s !== undefined) {
logMessage("UdfCompatibleDatafeed: search symbols error=" + response.errmsg);
logMessage(`UdfCompatibleDatafeed: search symbols error=${response.errmsg}`);
onResult([]);
return;
}
onResult(response);
})
.catch(function (reason) {
logMessage("UdfCompatibleDatafeed: Search symbols for '" + userInput + "' failed. Error=" + getErrorMessage(reason));
.catch((reason) => {
logMessage(`UdfCompatibleDatafeed: Search symbols for '${userInput}' failed. Error=${getErrorMessage(reason)}`);
onResult([]);
});
}
@@ -157,24 +154,28 @@ var UDFCompatibleDatafeedBase = /** @class */ (function () {
.then(onResult)
.catch(onResult.bind(null, []));
}
};
UDFCompatibleDatafeedBase.prototype.resolveSymbol = function (symbolName, onResolve, onError, extension) {
}
resolveSymbol(symbolName, onResolve, onError, extension) {
logMessage('Resolve requested');
var currencyCode = extension && extension.currencyCode;
var resolveRequestStartTime = Date.now();
const currencyCode = extension && extension.currencyCode;
const unitId = extension && extension.unitId;
const resolveRequestStartTime = Date.now();
function onResultReady(symbolInfo) {
logMessage("Symbol resolved: " + (Date.now() - resolveRequestStartTime) + "ms");
logMessage(`Symbol resolved: ${Date.now() - resolveRequestStartTime}ms`);
onResolve(symbolInfo);
}
if (!this._configuration.supports_group_request) {
var params = {
const params = {
symbol: symbolName,
};
if (currencyCode !== undefined) {
params.currencyCode = currencyCode;
}
if (unitId !== undefined) {
params.unitId = unitId;
}
this._send('symbols', params)
.then(function (response) {
.then((response) => {
if (response.s !== undefined) {
onError('unknown_symbol');
}
@@ -182,8 +183,8 @@ var UDFCompatibleDatafeedBase = /** @class */ (function () {
onResultReady(response);
}
})
.catch(function (reason) {
logMessage("UdfCompatibleDatafeed: Error resolving symbol: " + getErrorMessage(reason));
.catch((reason) => {
logMessage(`UdfCompatibleDatafeed: Error resolving symbol: ${getErrorMessage(reason)}`);
onError('unknown_symbol');
});
}
@@ -191,33 +192,33 @@ var UDFCompatibleDatafeedBase = /** @class */ (function () {
if (this._symbolsStorage === null) {
throw new Error('UdfCompatibleDatafeed: inconsistent configuration (symbols storage)');
}
this._symbolsStorage.resolveSymbol(symbolName, currencyCode).then(onResultReady).catch(onError);
this._symbolsStorage.resolveSymbol(symbolName, currencyCode, unitId).then(onResultReady).catch(onError);
}
};
UDFCompatibleDatafeedBase.prototype.getBars = function (symbolInfo, resolution, periodParams, onResult, onError) {
}
getBars(symbolInfo, resolution, periodParams, onResult, onError) {
this._historyProvider.getBars(symbolInfo, resolution, periodParams)
.then(function (result) {
.then((result) => {
onResult(result.bars, result.meta);
})
.catch(onError);
};
UDFCompatibleDatafeedBase.prototype.subscribeBars = function (symbolInfo, resolution, onTick, listenerGuid, onResetCacheNeededCallback) {
}
subscribeBars(symbolInfo, resolution, onTick, listenerGuid, onResetCacheNeededCallback) {
this._dataPulseProvider.subscribeBars(symbolInfo, resolution, onTick, listenerGuid);
};
UDFCompatibleDatafeedBase.prototype.unsubscribeBars = function (listenerGuid) {
}
unsubscribeBars(listenerGuid) {
this._dataPulseProvider.unsubscribeBars(listenerGuid);
};
UDFCompatibleDatafeedBase.prototype._requestConfiguration = function () {
}
_requestConfiguration() {
return this._send('config')
.catch(function (reason) {
logMessage("UdfCompatibleDatafeed: Cannot get datafeed configuration - use default, error=" + getErrorMessage(reason));
.catch((reason) => {
logMessage(`UdfCompatibleDatafeed: Cannot get datafeed configuration - use default, error=${getErrorMessage(reason)}`);
return null;
});
};
UDFCompatibleDatafeedBase.prototype._send = function (urlPath, params) {
}
_send(urlPath, params) {
return this._requester.sendRequest(this._datafeedURL, urlPath, params);
};
UDFCompatibleDatafeedBase.prototype._setupWithConfiguration = function (configurationData) {
}
_setupWithConfiguration(configurationData) {
this._configuration = configurationData;
if (configurationData.exchanges === undefined) {
configurationData.exchanges = [];
@@ -228,11 +229,9 @@ var UDFCompatibleDatafeedBase = /** @class */ (function () {
if (configurationData.supports_group_request || !configurationData.supports_search) {
this._symbolsStorage = new SymbolsStorage(this._datafeedURL, configurationData.supported_resolutions || [], this._requester);
}
logMessage("UdfCompatibleDatafeed: Initialized with " + JSON.stringify(configurationData));
};
return UDFCompatibleDatafeedBase;
}());
export { UDFCompatibleDatafeedBase };
logMessage(`UdfCompatibleDatafeed: Initialized with ${JSON.stringify(configurationData)}`);
}
}
function defaultConfiguration() {
return {
supports_search: false,