VERSION 1.12 @ 2018-02-14 07:05:47.033501

Cannot read property 'contains' of null #2442
Terminal: custom sorting for account manager tables #2344
Datafeed not closed after removing chart #2270
order.setPrice() has stopped working #2267
Volume in DOM rounded to 0 #2255
Error on bars request and update order lines #2237
Console error: Uncaught (in promise) formatter not received #2228
DOME doesn't work in new version #2211
Add featureset to hide toolbars by default #2209
Add possibility to move studies through z-order #2187
Unexpected resolution values in getBars #2179
Session breaks line is stuck to the left on reload #2153
Typescript declaration has mistakes #2144
Terminal: cannot specify step less than 1 #2141
Namespace the types in charting_library.d.ts #2137
Widget logo showing momentarily on paid account #2132
Add API to apply overrides for created studies #2098
Baseline chart style #2097
How to hide legend "Data Provided by ICE Data services" #2046
Stoch RSI Calculation #2038
Customize loading screen #2012
Supertrend indicator #1950
Translations in market details widget #1946
"Track time" chart setting #1918
Add tabs for positions #1906
Trading Terminal: Notifications Log #1896
Previous Close Price Line #1843
Set Overlay/Compare styles using createStudy/overrides and applyStudiesOverrides #1812
Session under Symbol info is displaying wrong trading interval(s)? #1787
Add "Go to" specific date #1753
Add session breaks #1752
Allow users to specify a volume for the Long/Short Position drawing tools #1691
Add API to use own charts save/load adapter #1679
Drawing toolbar not available in mobile #1673
Typescript definitions #1591
Support for symbols containing lowercase letters #1581
createMultipointShape long_position stop&profit setting #1459
Cannot change awesome oscillator width #1213
New adaptive drawings panel #1145
Edit shapes, studies and series #1101
Hide an indicator with API #1025
VWAP INDICATOR #106
This commit is contained in:
Jenkins
2018-02-14 01:10:34 -06:00
parent 7feb3edc93
commit d15c5cfb60
98 changed files with 4647 additions and 2034 deletions

View File

@@ -0,0 +1,243 @@
import { getErrorMessage, logMessage, } from './helpers';
import { HistoryProvider, } from './history-provider';
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];
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) {
if (updateFrequency === void 0) { updateFrequency = 10 * 1000; }
var _this = this;
this._configuration = defaultConfiguration();
this._symbolsStorage = null;
this._datafeedURL = datafeedURL;
this._requester = requester;
this._historyProvider = new HistoryProvider(datafeedURL, this._requester);
this._quotesProvider = quotesProvider;
this._dataPulseProvider = new DataPulseProvider(this._historyProvider, updateFrequency);
this._quotesPulseProvider = new QuotesPulseProvider(this._quotesProvider);
this._configurationReadyPromise = this._requestConfiguration()
.then(function (configuration) {
if (configuration === null) {
configuration = defaultConfiguration();
}
_this._setupWithConfiguration(configuration);
});
}
UDFCompatibleDatafeedBase.prototype.onReady = function (callback) {
var _this = this;
this._configurationReadyPromise.then(function () {
callback(_this._configuration);
});
};
UDFCompatibleDatafeedBase.prototype.getQuotes = function (symbols, onDataCallback, onErrorCallback) {
this._quotesProvider.getQuotes(symbols).then(onDataCallback).catch(onErrorCallback);
};
UDFCompatibleDatafeedBase.prototype.subscribeQuotes = function (symbols, fastSymbols, onRealtimeCallback, listenerGuid) {
this._quotesPulseProvider.subscribeQuotes(symbols, fastSymbols, onRealtimeCallback, listenerGuid);
};
UDFCompatibleDatafeedBase.prototype.unsubscribeQuotes = function (listenerGuid) {
this._quotesPulseProvider.unsubscribeQuotes(listenerGuid);
};
UDFCompatibleDatafeedBase.prototype.calculateHistoryDepth = function (resolution, resolutionBack, intervalBack) {
return undefined;
};
UDFCompatibleDatafeedBase.prototype.getMarks = function (symbolInfo, startDate, endDate, onDataCallback, resolution) {
if (!this._configuration.supports_marks) {
return;
}
var requestParams = {
symbol: symbolInfo.ticker || '',
from: startDate,
to: endDate,
resolution: resolution,
};
this._send('marks', requestParams)
.then(function (response) {
if (!Array.isArray(response)) {
var result = [];
for (var i = 0; i < response.id.length; ++i) {
result.push({
id: extractField(response, 'id', i),
time: extractField(response, 'time', i),
color: extractField(response, 'color', i),
text: extractField(response, 'text', i),
label: extractField(response, 'label', i),
labelFontColor: extractField(response, 'labelFontColor', i),
minSize: extractField(response, 'minSize', i),
});
}
response = result;
}
onDataCallback(response);
})
.catch(function (error) {
logMessage("UdfCompatibleDatafeed: Request marks failed: " + getErrorMessage(error));
onDataCallback([]);
});
};
UDFCompatibleDatafeedBase.prototype.getTimescaleMarks = function (symbolInfo, startDate, endDate, onDataCallback, resolution) {
if (!this._configuration.supports_timescale_marks) {
return;
}
var requestParams = {
symbol: symbolInfo.ticker || '',
from: startDate,
to: endDate,
resolution: resolution,
};
this._send('timescale_marks', requestParams)
.then(function (response) {
if (!Array.isArray(response)) {
var result = [];
for (var i = 0; i < response.id.length; ++i) {
result.push({
id: extractField(response, 'id', i),
time: extractField(response, 'time', i),
color: extractField(response, 'color', i),
label: extractField(response, 'label', i),
tooltip: extractField(response, 'tooltip', i),
});
}
response = result;
}
onDataCallback(response);
})
.catch(function (error) {
logMessage("UdfCompatibleDatafeed: Request timescale marks failed: " + getErrorMessage(error));
onDataCallback([]);
});
};
UDFCompatibleDatafeedBase.prototype.getServerTime = function (callback) {
if (!this._configuration.supports_time) {
return;
}
this._send('time')
.then(function (response) {
var time = parseInt(response);
if (!isNaN(time)) {
callback(time);
}
})
.catch(function (error) {
logMessage("UdfCompatibleDatafeed: Fail to load server time, error=" + getErrorMessage(error));
});
};
UDFCompatibleDatafeedBase.prototype.searchSymbols = function (userInput, exchange, symbolType, onResult) {
if (this._configuration.supports_search) {
var params = {
limit: 30 /* SearchItemsLimit */,
query: userInput.toUpperCase(),
type: symbolType,
exchange: exchange,
};
this._send('search', params)
.then(function (response) {
if (response.s !== undefined) {
logMessage("UdfCompatibleDatafeed: search symbols error=" + response.errmsg);
onResult([]);
return;
}
onResult(response);
})
.catch(function (reason) {
logMessage("UdfCompatibleDatafeed: Search symbols for '" + userInput + "' failed. Error=" + getErrorMessage(reason));
onResult([]);
});
}
else {
if (this._symbolsStorage === null) {
throw new Error('UdfCompatibleDatafeed: inconsistent configuration (symbols storage)');
}
this._symbolsStorage.searchSymbols(userInput, exchange, symbolType, 30 /* SearchItemsLimit */)
.then(onResult)
.catch(onResult.bind(null, []));
}
};
UDFCompatibleDatafeedBase.prototype.resolveSymbol = function (symbolName, onResolve, onError) {
logMessage('Resolve requested');
var resolveRequestStartTime = Date.now();
function onResultReady(symbolInfo) {
logMessage("Symbol resolved: " + (Date.now() - resolveRequestStartTime) + "ms");
onResolve(symbolInfo);
}
if (!this._configuration.supports_group_request) {
var params = {
symbol: symbolName,
};
this._send('symbols', params)
.then(function (response) {
if (response.s !== undefined) {
onError('unknown_symbol');
}
else {
onResultReady(response);
}
})
.catch(function (reason) {
logMessage("UdfCompatibleDatafeed: Error resolving symbol: " + getErrorMessage(reason));
onError('unknown_symbol');
});
}
else {
if (this._symbolsStorage === null) {
throw new Error('UdfCompatibleDatafeed: inconsistent configuration (symbols storage)');
}
this._symbolsStorage.resolveSymbol(symbolName).then(onResultReady).catch(onError);
}
};
UDFCompatibleDatafeedBase.prototype.getBars = function (symbolInfo, resolution, rangeStartDate, rangeEndDate, onResult, onError) {
this._historyProvider.getBars(symbolInfo, resolution, rangeStartDate, rangeEndDate)
.then(function (result) {
onResult(result.bars, result.meta);
})
.catch(onError);
};
UDFCompatibleDatafeedBase.prototype.subscribeBars = function (symbolInfo, resolution, onTick, listenerGuid, onResetCacheNeededCallback) {
this._dataPulseProvider.subscribeBars(symbolInfo, resolution, onTick, listenerGuid);
};
UDFCompatibleDatafeedBase.prototype.unsubscribeBars = function (listenerGuid) {
this._dataPulseProvider.unsubscribeBars(listenerGuid);
};
UDFCompatibleDatafeedBase.prototype._requestConfiguration = function () {
return this._send('config')
.catch(function (reason) {
logMessage("UdfCompatibleDatafeed: Cannot get datafeed configuration - use default, error=" + getErrorMessage(reason));
return null;
});
};
UDFCompatibleDatafeedBase.prototype._send = function (urlPath, params) {
return this._requester.sendRequest(this._datafeedURL, urlPath, params);
};
UDFCompatibleDatafeedBase.prototype._setupWithConfiguration = function (configurationData) {
this._configuration = configurationData;
if (configurationData.exchanges === undefined) {
configurationData.exchanges = [];
}
if (!configurationData.supports_search && !configurationData.supports_group_request) {
throw new Error('Unsupported datafeed configuration. Must either support search, or support group request');
}
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 };
function defaultConfiguration() {
return {
supports_search: false,
supports_group_request: true,
supported_resolutions: ['1', '5', '15', '30', '60', '1D', '1W', '1M'],
supports_marks: false,
supports_timescale_marks: false,
};
}