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:
85
datafeeds/udf/src/quotes-pulse-provider.ts
Normal file
85
datafeeds/udf/src/quotes-pulse-provider.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import {
|
||||
QuoteData,
|
||||
QuotesCallback,
|
||||
} from '../../../charting_library/datafeed-api';
|
||||
|
||||
import {
|
||||
getErrorMessage,
|
||||
logMessage,
|
||||
} from './helpers';
|
||||
|
||||
import { IQuotesProvider } from './iquotes-provider';
|
||||
|
||||
interface QuoteSubscriber {
|
||||
symbols: string[];
|
||||
fastSymbols: string[];
|
||||
listener: QuotesCallback;
|
||||
}
|
||||
|
||||
interface QuoteSubscribers {
|
||||
[listenerId: string]: QuoteSubscriber;
|
||||
}
|
||||
|
||||
const enum SymbolsType {
|
||||
General,
|
||||
Fast,
|
||||
}
|
||||
|
||||
const enum UpdateTimeouts {
|
||||
Fast = 10 * 1000,
|
||||
General = 60 * 1000,
|
||||
}
|
||||
|
||||
export class QuotesPulseProvider {
|
||||
private readonly _quotesProvider: IQuotesProvider;
|
||||
private readonly _subscribers: QuoteSubscribers = {};
|
||||
private _requestsPending: number = 0;
|
||||
|
||||
public constructor(quotesProvider: IQuotesProvider) {
|
||||
this._quotesProvider = quotesProvider;
|
||||
|
||||
setInterval(this._updateQuotes.bind(this, SymbolsType.Fast), UpdateTimeouts.Fast);
|
||||
setInterval(this._updateQuotes.bind(this, SymbolsType.General), UpdateTimeouts.General);
|
||||
}
|
||||
|
||||
public subscribeQuotes(symbols: string[], fastSymbols: string[], onRealtimeCallback: QuotesCallback, listenerGuid: string): void {
|
||||
this._subscribers[listenerGuid] = {
|
||||
symbols: symbols,
|
||||
fastSymbols: fastSymbols,
|
||||
listener: onRealtimeCallback,
|
||||
};
|
||||
|
||||
logMessage(`QuotesPulseProvider: subscribed quotes with #${listenerGuid}`);
|
||||
}
|
||||
|
||||
public unsubscribeQuotes(listenerGuid: string): void {
|
||||
delete this._subscribers[listenerGuid];
|
||||
logMessage(`QuotesPulseProvider: unsubscribed quotes with #${listenerGuid}`);
|
||||
}
|
||||
|
||||
private _updateQuotes(updateType: SymbolsType): void {
|
||||
if (this._requestsPending > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const listenerGuid in this._subscribers) { // tslint:disable-line:forin
|
||||
this._requestsPending++;
|
||||
|
||||
const subscriptionRecord = this._subscribers[listenerGuid];
|
||||
this._quotesProvider.getQuotes(updateType === SymbolsType.Fast ? subscriptionRecord.fastSymbols : subscriptionRecord.symbols)
|
||||
.then((data: QuoteData[]) => {
|
||||
this._requestsPending--;
|
||||
if (!this._subscribers.hasOwnProperty(listenerGuid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
subscriptionRecord.listener(data);
|
||||
logMessage(`QuotesPulseProvider: data for #${listenerGuid} (${updateType}) updated successfully, pending=${this._requestsPending}`);
|
||||
})
|
||||
.catch((reason?: string | Error) => {
|
||||
this._requestsPending--;
|
||||
logMessage(`QuotesPulseProvider: data for #${listenerGuid} (${updateType}) updated with error=${getErrorMessage(reason)}, pending=${this._requestsPending}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user