setVisibleRange additional argument - right margin % #4512 Indicators are slided when zooming chart #4456 save_load_adapter after removing chart #4454 Overriding timezone definitions #4449 Error while applying study template #4407 Wrong range of overlay after switching timeframe #4372 Intraday Data is Requesting from the server since 1970 #4366 Display price in thousands, millions, billions #4360 setBodyFont of position line tool doesn't work correctly #4353 Realtime updates shifts indicator's data for realtime bars count back #4283 Adaptive indicators dialogs #4247 Click instead of mouseDown for positionLine onClose. #4245 Add applyRightMargin flag to setVisibleRange #4233 Open volume on new pane if volume_force_overlay is enabled #4198 Keep the first visible point when a new bar comes #4188 getVisibleRange should return 00:00 for DWM #4187 21 more indicators #4170 Main series API #4169 Can not set Text property of the Note Shape #4144 Unable to hide legend #4126 setVisibleRange or getVisibleRange adds one more bar to the left #4110 Cannot set tooltip for order line #4079 Dialog is closed immediately if it is invoked from mouse_down event #4077 setVisibleRange doesn't work for multiple charts at once #4068 how to disable mp3 files being loaded? #4052 Increase spacing between bars to display short time periods #4043 Event Marker Placement always uses high #4042 Number cannot be passed as symbol into widget constructor #4039 custom_css_url not working in unstable branch #4017 ConfirmDialog does not close after YES is clicked #3981 Side DOM chart does not render in certain conditions #3975 `getAllShapes` does not return drawings loaded from state #3966 Text inside order/position lines is too small #3962 Removing the last saved chart #3954 get current chart timezone #3943 Text shape throws error setValue #3930 Wrong Symbol and Price values in context menu for secondary instrument. #3926 text override in Horizontal Line does not work #3918 Sticky magnet mode #3902 Add thin bars #3900 Event that study has been removed from the chart #3899 High-Low bars #3898 Multiple Y-axis #3897 Issue with Renko with volume and vwap indicators #3893 Layout rename doesn't send request to server #3878 Cannot create copy of copy of a chart layout #3872 Chart scrolls when tap on a trend line Safari/iphone7 #3871 Chart border overlap scale values #3826 IDatafeedChartApi.subscribeDepth parameters #3821 Error in console when restore defaults #3755 Timeframe is not precise #3722 Wrong year Ticker displayed on X axis if resolution < 2H #3678 New chart layouts #3629 Drawings disappear at certain resolutions #3594 Remove jQuery from loading custom indicator #3563 Align symbol labels #3513 createOrderLine().onMove broken in 1.13 #3480 When changing theme on the fly - chart type changing too #3459 Pivot Points Standard - path to some style params #3441 createMultipointShape overrides with dot don't work #3419 Add inverting price scale #3376 Transparent chart background color #3288 Previous timescale tooltips stay when switching currency #3165 disableSelection still shown the selections on hover #2864 Override symbol from saved_data #2493 Forecast balloon too short #2289 Context menu submenus cover up other options #2007 Add setVisiblePriceRange method #1408 Modify panes height/order #1232 Add custom Interval #1191
175 lines
8.6 KiB
JavaScript
175 lines
8.6 KiB
JavaScript
import { getErrorMessage, logMessage, } from './helpers';
|
|
function extractField(data, field, arrayIndex, valueIsArray) {
|
|
var value = data[field];
|
|
if (Array.isArray(value) && (!valueIsArray || Array.isArray(value[0]))) {
|
|
return value[arrayIndex];
|
|
}
|
|
return value;
|
|
}
|
|
var SymbolsStorage = /** @class */ (function () {
|
|
function SymbolsStorage(datafeedUrl, datafeedSupportedResolutions, requester) {
|
|
this._exchangesList = ['NYSE', 'FOREX', 'AMEX'];
|
|
this._symbolsInfo = {};
|
|
this._symbolsList = [];
|
|
this._datafeedUrl = datafeedUrl;
|
|
this._datafeedSupportedResolutions = datafeedSupportedResolutions;
|
|
this._requester = requester;
|
|
this._readyPromise = this._init();
|
|
this._readyPromise.catch(function (error) {
|
|
// seems it is impossible
|
|
// tslint:disable-next-line:no-console
|
|
console.error("SymbolsStorage: Cannot init, error=" + error.toString());
|
|
});
|
|
}
|
|
// BEWARE: this function does not consider symbol's exchange
|
|
SymbolsStorage.prototype.resolveSymbol = function (symbolName) {
|
|
var _this = this;
|
|
return this._readyPromise.then(function () {
|
|
var symbolInfo = _this._symbolsInfo[symbolName];
|
|
if (symbolInfo === undefined) {
|
|
return Promise.reject('invalid symbol');
|
|
}
|
|
return Promise.resolve(symbolInfo);
|
|
});
|
|
};
|
|
SymbolsStorage.prototype.searchSymbols = function (searchString, exchange, symbolType, maxSearchResults) {
|
|
var _this = this;
|
|
return this._readyPromise.then(function () {
|
|
var weightedResult = [];
|
|
var queryIsEmpty = searchString.length === 0;
|
|
searchString = searchString.toUpperCase();
|
|
var _loop_1 = function (symbolName) {
|
|
var symbolInfo = _this._symbolsInfo[symbolName];
|
|
if (symbolInfo === undefined) {
|
|
return "continue";
|
|
}
|
|
if (symbolType.length > 0 && symbolInfo.type !== symbolType) {
|
|
return "continue";
|
|
}
|
|
if (exchange && exchange.length > 0 && symbolInfo.exchange !== exchange) {
|
|
return "continue";
|
|
}
|
|
var positionInName = symbolInfo.name.toUpperCase().indexOf(searchString);
|
|
var positionInDescription = symbolInfo.description.toUpperCase().indexOf(searchString);
|
|
if (queryIsEmpty || positionInName >= 0 || positionInDescription >= 0) {
|
|
var alreadyExists = weightedResult.some(function (item) { return item.symbolInfo === symbolInfo; });
|
|
if (!alreadyExists) {
|
|
var weight = positionInName >= 0 ? positionInName : 8000 + positionInDescription;
|
|
weightedResult.push({ symbolInfo: symbolInfo, weight: weight });
|
|
}
|
|
}
|
|
};
|
|
for (var _i = 0, _a = _this._symbolsList; _i < _a.length; _i++) {
|
|
var symbolName = _a[_i];
|
|
_loop_1(symbolName);
|
|
}
|
|
var result = weightedResult
|
|
.sort(function (item1, item2) { return item1.weight - item2.weight; })
|
|
.slice(0, maxSearchResults)
|
|
.map(function (item) {
|
|
var symbolInfo = item.symbolInfo;
|
|
return {
|
|
symbol: symbolInfo.name,
|
|
full_name: symbolInfo.full_name,
|
|
description: symbolInfo.description,
|
|
exchange: symbolInfo.exchange,
|
|
params: [],
|
|
type: symbolInfo.type,
|
|
ticker: symbolInfo.name,
|
|
};
|
|
});
|
|
return Promise.resolve(result);
|
|
});
|
|
};
|
|
SymbolsStorage.prototype._init = function () {
|
|
var _this = this;
|
|
var promises = [];
|
|
var alreadyRequestedExchanges = {};
|
|
for (var _i = 0, _a = this._exchangesList; _i < _a.length; _i++) {
|
|
var exchange = _a[_i];
|
|
if (alreadyRequestedExchanges[exchange]) {
|
|
continue;
|
|
}
|
|
alreadyRequestedExchanges[exchange] = true;
|
|
promises.push(this._requestExchangeData(exchange));
|
|
}
|
|
return Promise.all(promises)
|
|
.then(function () {
|
|
_this._symbolsList.sort();
|
|
logMessage('SymbolsStorage: All exchanges data loaded');
|
|
});
|
|
};
|
|
SymbolsStorage.prototype._requestExchangeData = function (exchange) {
|
|
var _this = this;
|
|
return new Promise(function (resolve, reject) {
|
|
_this._requester.sendRequest(_this._datafeedUrl, 'symbol_info', { group: exchange })
|
|
.then(function (response) {
|
|
try {
|
|
_this._onExchangeDataReceived(exchange, response);
|
|
}
|
|
catch (error) {
|
|
reject(error);
|
|
return;
|
|
}
|
|
resolve();
|
|
})
|
|
.catch(function (reason) {
|
|
logMessage("SymbolsStorage: Request data for exchange '" + exchange + "' failed, reason=" + getErrorMessage(reason));
|
|
resolve();
|
|
});
|
|
});
|
|
};
|
|
SymbolsStorage.prototype._onExchangeDataReceived = function (exchange, data) {
|
|
var symbolIndex = 0;
|
|
try {
|
|
var symbolsCount = data.symbol.length;
|
|
var tickerPresent = data.ticker !== undefined;
|
|
for (; symbolIndex < symbolsCount; ++symbolIndex) {
|
|
var symbolName = data.symbol[symbolIndex];
|
|
var listedExchange = extractField(data, 'exchange-listed', symbolIndex);
|
|
var tradedExchange = extractField(data, 'exchange-traded', symbolIndex);
|
|
var fullName = tradedExchange + ':' + symbolName;
|
|
var ticker = tickerPresent ? extractField(data, 'ticker', symbolIndex) : symbolName;
|
|
var symbolInfo = {
|
|
ticker: ticker,
|
|
name: symbolName,
|
|
base_name: [listedExchange + ':' + symbolName],
|
|
full_name: fullName,
|
|
listed_exchange: listedExchange,
|
|
exchange: tradedExchange,
|
|
description: extractField(data, 'description', symbolIndex),
|
|
has_intraday: definedValueOrDefault(extractField(data, 'has-intraday', symbolIndex), false),
|
|
has_no_volume: definedValueOrDefault(extractField(data, 'has-no-volume', symbolIndex), false),
|
|
minmov: extractField(data, 'minmovement', symbolIndex) || extractField(data, 'minmov', symbolIndex) || 0,
|
|
minmove2: extractField(data, 'minmove2', symbolIndex) || extractField(data, 'minmov2', symbolIndex),
|
|
fractional: extractField(data, 'fractional', symbolIndex),
|
|
pricescale: extractField(data, 'pricescale', symbolIndex),
|
|
type: extractField(data, 'type', symbolIndex),
|
|
session: extractField(data, 'session-regular', symbolIndex),
|
|
timezone: extractField(data, 'timezone', symbolIndex),
|
|
supported_resolutions: definedValueOrDefault(extractField(data, 'supported-resolutions', symbolIndex, true), this._datafeedSupportedResolutions),
|
|
force_session_rebuild: extractField(data, 'force-session-rebuild', symbolIndex),
|
|
has_daily: definedValueOrDefault(extractField(data, 'has-daily', symbolIndex), true),
|
|
intraday_multipliers: definedValueOrDefault(extractField(data, 'intraday-multipliers', symbolIndex, true), ['1', '5', '15', '30', '60']),
|
|
has_weekly_and_monthly: extractField(data, 'has-weekly-and-monthly', symbolIndex),
|
|
has_empty_bars: extractField(data, 'has-empty-bars', symbolIndex),
|
|
volume_precision: definedValueOrDefault(extractField(data, 'volume-precision', symbolIndex), 0),
|
|
format: 'price',
|
|
};
|
|
this._symbolsInfo[ticker] = symbolInfo;
|
|
this._symbolsInfo[symbolName] = symbolInfo;
|
|
this._symbolsInfo[fullName] = symbolInfo;
|
|
this._symbolsList.push(symbolName);
|
|
}
|
|
}
|
|
catch (error) {
|
|
throw new Error("SymbolsStorage: API error when processing exchange " + exchange + " symbol #" + symbolIndex + " (" + data.symbol[symbolIndex] + "): " + error.message);
|
|
}
|
|
};
|
|
return SymbolsStorage;
|
|
}());
|
|
export { SymbolsStorage };
|
|
function definedValueOrDefault(value, defaultValue) {
|
|
return value !== undefined ? value : defaultValue;
|
|
}
|