jenkins@nwork.local
2020-10-09 07:53:47 +00:00
parent e8a9aa3153
commit 1e14cf90ea
531 changed files with 1942 additions and 1801 deletions

View File

@@ -1 +1,2 @@
package-lock=false
audit=false

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -12,6 +12,9 @@ var HistoryProvider = /** @class */ (function () {
from: rangeStartDate,
to: rangeEndDate,
};
if (symbolInfo.currency_code !== undefined) {
requestParams.currencyCode = symbolInfo.currency_code;
}
return new Promise(function (resolve, reject) {
_this._requester.sendRequest(_this._datafeedUrl, 'history', requestParams)
.then(function (response) {
@@ -33,18 +36,18 @@ var HistoryProvider = /** @class */ (function () {
for (var i = 0; i < response.t.length; ++i) {
var barValue = {
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.o[i]);
barValue.high = Number(response.h[i]);
barValue.low = Number(response.l[i]);
barValue.open = parseFloat(response.o[i]);
barValue.high = parseFloat(response.h[i]);
barValue.low = parseFloat(response.l[i]);
}
if (volumePresent) {
barValue.volume = Number(response.v[i]);
barValue.volume = parseFloat(response.v[i]);
}
bars.push(barValue);
}

View File

@@ -6,6 +6,10 @@ function extractField(data, field, arrayIndex, valueIsArray) {
}
return value;
}
function symbolWithCurrencyKey(symbol, currency) {
// here we're using a separator that quite possible shouldn't be in a real symbol name
return symbol + (currency !== undefined ? '_%|#|%_' + currency : '');
}
var SymbolsStorage = /** @class */ (function () {
function SymbolsStorage(datafeedUrl, datafeedSupportedResolutions, requester) {
this._exchangesList = ['NYSE', 'FOREX', 'AMEX'];
@@ -22,10 +26,10 @@ var SymbolsStorage = /** @class */ (function () {
});
}
// BEWARE: this function does not consider symbol's exchange
SymbolsStorage.prototype.resolveSymbol = function (symbolName) {
SymbolsStorage.prototype.resolveSymbol = function (symbolName, currencyCode) {
var _this = this;
return this._readyPromise.then(function () {
var symbolInfo = _this._symbolsInfo[symbolName];
var symbolInfo = _this._symbolsInfo[symbolWithCurrencyKey(symbolName, currencyCode)];
if (symbolInfo === undefined) {
return Promise.reject('invalid symbol');
}
@@ -129,6 +133,7 @@ var SymbolsStorage = /** @class */ (function () {
var listedExchange = extractField(data, 'exchange-listed', symbolIndex);
var tradedExchange = extractField(data, 'exchange-traded', symbolIndex);
var fullName = tradedExchange + ':' + symbolName;
var currencyCode = extractField(data, 'currency-code', symbolIndex);
var ticker = tickerPresent ? extractField(data, 'ticker', symbolIndex) : symbolName;
var symbolInfo = {
ticker: ticker,
@@ -137,6 +142,8 @@ var SymbolsStorage = /** @class */ (function () {
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),
@@ -159,6 +166,11 @@ var SymbolsStorage = /** @class */ (function () {
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);
}
}

View File

@@ -161,8 +161,9 @@ var UDFCompatibleDatafeedBase = /** @class */ (function () {
.catch(onResult.bind(null, []));
}
};
UDFCompatibleDatafeedBase.prototype.resolveSymbol = function (symbolName, onResolve, onError) {
UDFCompatibleDatafeedBase.prototype.resolveSymbol = function (symbolName, onResolve, onError, extension) {
logMessage('Resolve requested');
var currencyCode = extension && extension.currencyCode;
var resolveRequestStartTime = Date.now();
function onResultReady(symbolInfo) {
logMessage("Symbol resolved: " + (Date.now() - resolveRequestStartTime) + "ms");
@@ -172,6 +173,9 @@ var UDFCompatibleDatafeedBase = /** @class */ (function () {
var params = {
symbol: symbolName,
};
if (currencyCode !== undefined) {
params.currencyCode = currencyCode;
}
this._send('symbols', params)
.then(function (response) {
if (response.s !== undefined) {
@@ -190,7 +194,7 @@ var UDFCompatibleDatafeedBase = /** @class */ (function () {
if (this._symbolsStorage === null) {
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);
}
};
UDFCompatibleDatafeedBase.prototype.getBars = function (symbolInfo, resolution, rangeStartDate, rangeEndDate, onResult, onError) {

View File

@@ -2,7 +2,7 @@
"private": true,
"dependencies": {
"promise-polyfill": "6.0.2",
"tslib": "1.7.1",
"tslib": "1.11.1",
"whatwg-fetch": "2.0.3"
},
"devDependencies": {
@@ -10,7 +10,7 @@
"rollup-plugin-buble": "0.15.0",
"rollup-plugin-node-resolve": "3.0.0",
"rollup-plugin-uglify": "2.0.1",
"typescript": "3.7.2"
"typescript": "3.8.3"
},
"scripts": {
"compile": "tsc",

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);
}
}