Release v17.016 (from 000a21d8)
Fixes tradingview/charting_library#4599 Fixes tradingview/charting_library#4613 Fixes tradingview/charting_library#4764 Fixes tradingview/charting_library#4801 Fixes tradingview/charting_library#5112
This commit is contained in:
@@ -13,10 +13,10 @@ import {
|
||||
} from './helpers';
|
||||
|
||||
import { Requester } from './requester';
|
||||
|
||||
// tslint:disable: no-any
|
||||
interface HistoryPartialDataResponse extends UdfOkResponse {
|
||||
t: number[];
|
||||
c: number[];
|
||||
t: any;
|
||||
c: any;
|
||||
o?: never;
|
||||
h?: never;
|
||||
l?: never;
|
||||
@@ -24,14 +24,14 @@ interface HistoryPartialDataResponse extends UdfOkResponse {
|
||||
}
|
||||
|
||||
interface HistoryFullDataResponse extends UdfOkResponse {
|
||||
t: number[];
|
||||
c: number[];
|
||||
o: number[];
|
||||
h: number[];
|
||||
l: number[];
|
||||
v: number[];
|
||||
t: any;
|
||||
c: any;
|
||||
o: any;
|
||||
h: any;
|
||||
l: any;
|
||||
v: any;
|
||||
}
|
||||
|
||||
// tslint:enable: no-any
|
||||
interface HistoryNoDataResponse extends UdfResponse {
|
||||
s: 'no_data';
|
||||
nextTime?: number;
|
||||
@@ -61,6 +61,10 @@ export class HistoryProvider {
|
||||
to: rangeEndDate,
|
||||
};
|
||||
|
||||
if (symbolInfo.currency_code !== undefined) {
|
||||
requestParams.currencyCode = symbolInfo.currency_code;
|
||||
}
|
||||
|
||||
return new Promise((resolve: (result: GetBarsResult) => void, reject: (reason: string) => void) => {
|
||||
this._requester.sendRequest<HistoryResponse>(this._datafeedUrl, 'history', requestParams)
|
||||
.then((response: HistoryResponse | UdfErrorResponse) => {
|
||||
@@ -84,20 +88,20 @@ export class HistoryProvider {
|
||||
for (let i = 0; i < response.t.length; ++i) {
|
||||
const barValue: Bar = {
|
||||
time: response.t[i] * 1000,
|
||||
close: Number(response.c[i]),
|
||||
open: Number(response.c[i]),
|
||||
high: Number(response.c[i]),
|
||||
low: Number(response.c[i]),
|
||||
close: parseFloat(response.c[i]),
|
||||
open: parseFloat(response.c[i]),
|
||||
high: parseFloat(response.c[i]),
|
||||
low: parseFloat(response.c[i]),
|
||||
};
|
||||
|
||||
if (ohlPresent) {
|
||||
barValue.open = Number((response as HistoryFullDataResponse).o[i]);
|
||||
barValue.high = Number((response as HistoryFullDataResponse).h[i]);
|
||||
barValue.low = Number((response as HistoryFullDataResponse).l[i]);
|
||||
barValue.open = parseFloat((response as HistoryFullDataResponse).o[i]);
|
||||
barValue.high = parseFloat((response as HistoryFullDataResponse).h[i]);
|
||||
barValue.low = parseFloat((response as HistoryFullDataResponse).l[i]);
|
||||
}
|
||||
|
||||
if (volumePresent) {
|
||||
barValue.volume = Number((response as HistoryFullDataResponse).v[i]);
|
||||
barValue.volume = parseFloat((response as HistoryFullDataResponse).v[i]);
|
||||
}
|
||||
|
||||
bars.push(barValue);
|
||||
|
||||
@@ -47,6 +47,8 @@ interface ExchangeDataResponseSymbolData {
|
||||
'has-weekly-and-monthly'?: boolean;
|
||||
'has-empty-bars'?: boolean;
|
||||
'has-no-volume'?: boolean;
|
||||
'currency-code'?: string;
|
||||
'original-currency-code'?: string;
|
||||
|
||||
'volume-precision'?: number;
|
||||
}
|
||||
@@ -80,6 +82,11 @@ function extractField<Field extends keyof ExchangeDataResponseSymbolData>(data:
|
||||
return value as ExchangeDataResponseSymbolData[Field];
|
||||
}
|
||||
|
||||
function symbolWithCurrencyKey(symbol: string, currency?: string): string {
|
||||
// here we're using a separator that quite possible shouldn't be in a real symbol name
|
||||
return symbol + (currency !== undefined ? '_%|#|%_' + currency : '');
|
||||
}
|
||||
|
||||
export class SymbolsStorage {
|
||||
private readonly _exchangesList: string[] = ['NYSE', 'FOREX', 'AMEX'];
|
||||
private readonly _symbolsInfo: SymbolInfoMap = {};
|
||||
@@ -102,9 +109,9 @@ export class SymbolsStorage {
|
||||
}
|
||||
|
||||
// BEWARE: this function does not consider symbol's exchange
|
||||
public resolveSymbol(symbolName: string): Promise<LibrarySymbolInfo> {
|
||||
public resolveSymbol(symbolName: string, currencyCode?: string): Promise<LibrarySymbolInfo> {
|
||||
return this._readyPromise.then(() => {
|
||||
const symbolInfo = this._symbolsInfo[symbolName];
|
||||
const symbolInfo = this._symbolsInfo[symbolWithCurrencyKey(symbolName, currencyCode)];
|
||||
if (symbolInfo === undefined) {
|
||||
return Promise.reject('invalid symbol');
|
||||
}
|
||||
@@ -228,6 +235,7 @@ export class SymbolsStorage {
|
||||
const listedExchange = extractField(data, 'exchange-listed', symbolIndex);
|
||||
const tradedExchange = extractField(data, 'exchange-traded', symbolIndex);
|
||||
const fullName = tradedExchange + ':' + symbolName;
|
||||
const currencyCode = extractField(data, 'currency-code', symbolIndex);
|
||||
|
||||
const ticker = tickerPresent ? (extractField(data, 'ticker', symbolIndex) as string) : symbolName;
|
||||
|
||||
@@ -238,6 +246,8 @@ export class SymbolsStorage {
|
||||
full_name: fullName,
|
||||
listed_exchange: listedExchange,
|
||||
exchange: tradedExchange,
|
||||
currency_code: currencyCode,
|
||||
original_currency_code: extractField(data, 'original-currency-code', symbolIndex),
|
||||
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),
|
||||
@@ -261,6 +271,11 @@ export class SymbolsStorage {
|
||||
this._symbolsInfo[ticker] = symbolInfo;
|
||||
this._symbolsInfo[symbolName] = symbolInfo;
|
||||
this._symbolsInfo[fullName] = symbolInfo;
|
||||
if (currencyCode !== undefined) {
|
||||
this._symbolsInfo[symbolWithCurrencyKey(ticker, currencyCode)] = symbolInfo;
|
||||
this._symbolsInfo[symbolWithCurrencyKey(symbolName, currencyCode)] = symbolInfo;
|
||||
this._symbolsInfo[symbolWithCurrencyKey(fullName, currencyCode)] = symbolInfo;
|
||||
}
|
||||
|
||||
this._symbolsList.push(symbolName);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
ServerTimeCallback,
|
||||
SubscribeBarsCallback,
|
||||
TimescaleMark,
|
||||
SymbolResolveExtension,
|
||||
} from '../../../charting_library/datafeed-api';
|
||||
|
||||
import {
|
||||
@@ -262,9 +263,11 @@ export class UDFCompatibleDatafeedBase implements IExternalDatafeed, IDatafeedQu
|
||||
}
|
||||
}
|
||||
|
||||
public resolveSymbol(symbolName: string, onResolve: ResolveCallback, onError: ErrorCallback): void {
|
||||
public resolveSymbol(symbolName: string, onResolve: ResolveCallback, onError: ErrorCallback, extension?: SymbolResolveExtension): void {
|
||||
logMessage('Resolve requested');
|
||||
|
||||
const currencyCode = extension && extension.currencyCode;
|
||||
|
||||
const resolveRequestStartTime = Date.now();
|
||||
function onResultReady(symbolInfo: LibrarySymbolInfo): void {
|
||||
logMessage(`Symbol resolved: ${Date.now() - resolveRequestStartTime}ms`);
|
||||
@@ -275,6 +278,9 @@ export class UDFCompatibleDatafeedBase implements IExternalDatafeed, IDatafeedQu
|
||||
const params: RequestParams = {
|
||||
symbol: symbolName,
|
||||
};
|
||||
if (currencyCode !== undefined) {
|
||||
params.currencyCode = currencyCode;
|
||||
}
|
||||
|
||||
this._send<ResolveSymbolResponse | UdfErrorResponse>('symbols', params)
|
||||
.then((response: ResolveSymbolResponse | UdfErrorResponse) => {
|
||||
@@ -293,7 +299,7 @@ export class UDFCompatibleDatafeedBase implements IExternalDatafeed, IDatafeedQu
|
||||
throw new Error('UdfCompatibleDatafeed: inconsistent configuration (symbols storage)');
|
||||
}
|
||||
|
||||
this._symbolsStorage.resolveSymbol(symbolName).then(onResultReady).catch(onError);
|
||||
this._symbolsStorage.resolveSymbol(symbolName, currencyCode).then(onResultReady).catch(onError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user