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)

76 lines (75 loc) 2.93 kB
import MetaApiWebsocketClient from '../clients/metaApi/metaApiWebsocket.client'; import SynchronizationListener from '../clients/metaApi/synchronizationListener'; import { Logger } from '../logger'; import MetatraderAccount from './metatraderAccount'; /** * Exposes MetaApi MetaTrader API connection to consumers */ export default class MetaApiConnection extends SynchronizationListener { protected _options: any; protected _websocketClient: MetaApiWebsocketClient; protected _latencyService: any; protected _account: MetatraderAccount; protected _logger: Logger; protected _application: any; protected _refreshTasks: {}; protected _connectionRegistry: any; protected _closed: any; protected _stateByInstanceIndex: any; protected _opened: any; /** * @typedef Config MetaApi options for connections * @property {Options} [connections] MetaApi connections options. Only for tests. Will be ignored when set in SDK */ /** * @typedef Options MetaApiConnection options * @property {number} [refreshReplicasMaxDelayInMs = 6 * 60 * 60 * 1000] max delay before refreshing replicas delay */ /** * Constructs MetaApi MetaTrader Api connection * @param {MetaApiOpts & Config} options MetaApi options * @param {MetaApiWebsocketClient} websocketClient MetaApi websocket client * @param {MetatraderAccount} account MetaTrader account id to connect to * @param {String} [application] application to use */ constructor(options: any, websocketClient: any, account: any, application?: any); /** * Opens the connection. Can only be called the first time, next calls will be ignored. * @param {string} instanceId connection instance id * @return {Promise} promise resolving when the connection is opened */ connect(instanceId: any): Promise<void>; /** * Closes the connection. The instance of the class should no longer be used after this method is invoked. * @param {string} instanceId connection instance id */ close(instanceId: any): Promise<void>; /** * Returns MetaApi account * @return {MetatraderAccount} MetaApi account */ get account(): MetatraderAccount; /** * Returns connection application * @return {String} connection application */ get application(): any; /** * Schedules the refresh task * @param {string} region replica region */ scheduleRefresh(region: any): void; /** * Cancels the scheduled refresh task * @param {string} region replica region */ cancelRefresh(region: any): void; /** * Refreshes account replicas */ _refreshReplicas(): Promise<void>; _ensureSynchronized(instanceIndex: any, key: any): Promise<void>; synchronize(instanceIndex: any): any; _getState(instanceIndex: any): any; _checkIsConnectionActive(): void; }