UNPKG

metaapi.cloud-sdk

Version:

SDK for MetaApi, a professional cloud forex API which includes MetaTrader REST API and MetaTrader websocket API. Supports both MetaTrader 5 (MT5) and MetaTrader 4 (MT4). CopyFactory copy trading API included. (https://metaapi.cloud)

114 lines (113 loc) 4.36 kB
/** * Options for synchronization throttler * @typedef {Object} SynchronizationThrottlerOpts * @property {Number} [maxConcurrentSynchronizations] amount of maximum allowed concurrent synchronizations * @property {Number} [queueTimeoutInSeconds] allowed time for a synchronization in queue * @property {Number} [synchronizationTimeoutInSeconds] time after which a synchronization slot * is freed to be used by another synchronization */ /** * Synchronization throttler used to limit the amount of concurrent synchronizations to prevent application * from being overloaded due to excessive number of synchronisation responses being sent. */ export default class SynchronizationThrottler { private _maxConcurrentSynchronizations; private _queueTimeoutInSeconds; private _synchronizationTimeoutInSeconds; private _client; private _region; private _socketInstanceIndex; private _synchronizationIds; private _accountsBySynchronizationIds; private _synchronizationQueue; private _removeOldSyncIdsInterval; private _processQueueInterval; private _instanceNumber; private _logger; /** * Constructs the synchronization throttler * @param {MetaApiWebsocketClient} client MetaApi websocket client * @param {Number} socketInstanceIndex index of socket instance that uses the throttler * @param {Number} instanceNumber instance index number * @param {String} region server region * @param {SynchronizationThrottlerOpts} opts synchronization throttler options */ constructor(client: any, socketInstanceIndex: any, instanceNumber: any, region: any, opts: SynchronizationThrottlerOpts); /** * Initializes the synchronization throttler */ start(): void; /** * Deinitializes the throttler */ stop(): void; _removeOldSyncIdsJob(): Promise<void>; /** * Fills a synchronization slot with synchronization id * @param {String} synchronizationId synchronization id */ updateSynchronizationId(synchronizationId: any): void; /** * Returns the list of currently synchronizing account ids */ get synchronizingAccounts(): any[]; /** * Returns the list of currenly active synchronization ids * @return {String[]} synchronization ids */ get activeSynchronizationIds(): string[]; /** * Returns the amount of maximum allowed concurrent synchronizations * @return {number} maximum allowed concurrent synchronizations */ get maxConcurrentSynchronizations(): number; /** * Returns flag whether there are free slots for synchronization requests * @return {Boolean} flag whether there are free slots for synchronization requests */ get isSynchronizationAvailable(): boolean; /** * Removes synchronizations from queue and from the list by parameters * @param {String} accountId account id * @param {Number} instanceIndex account instance index * @param {String} host account host name */ removeIdByParameters(accountId: any, instanceIndex: any, host: any): void; /** * Removes synchronization id from slots and removes ids for the same account from the queue * @param {String} synchronizationId synchronization id */ removeSynchronizationId(synchronizationId: any): void; /** * Clears synchronization ids on disconnect */ onDisconnect(): void; _advanceQueue(): void; _removeFromQueue(synchronizationId: any, result: any): void; _processQueueJob(): Promise<void>; /** * Schedules to send a synchronization request for account * @param {String} accountId account id * @param {Object} request request to send * @param {Object} hashes terminal state hashes */ scheduleSynchronize(accountId: any, request: any, hashes: any): Promise<boolean>; } /** * Options for synchronization throttler */ export type SynchronizationThrottlerOpts = { /** * amount of maximum allowed concurrent synchronizations */ maxConcurrentSynchronizations?: number; /** * allowed time for a synchronization in queue */ queueTimeoutInSeconds?: number; /** * time after which a synchronization slot * is freed to be used by another synchronization */ synchronizationTimeoutInSeconds?: number; };