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)

69 lines (68 loc) 2.21 kB
import { ApiError } from './errorHandler'; /** * HTTP client library based on axios */ export default class HttpClient { private _timeout; private _retries; private _minRetryDelay; private _maxRetryDelay; private _longRunningRequestTimeout; private _logger; /** * Constructs HttpClient class instance * @param {Number} timeout request timeout in seconds * @param {RetryOptions} [retryOpts] retry options */ constructor(timeout?: number, retryOpts?: RetryOptions); /** * Performs a request. Response errors are returned as ApiError or subclasses. * @param {Object} options request options * @returns {Object|String|any} request result */ request<T = any>(options: any, type?: string, retryCounter?: number, endTime?: number, isLongRunning?: boolean): Promise<T>; _makeRequest(options: any, type: any): any; _wait(pause: any): Promise<void>; _handleRetry(endTime: any, retryAfter: any): Promise<void>; _handleError(err: any, type: any, retryCounter: any, endTime: any): Promise<any>; _convertError(err: any): ApiError; } /** * HTTP client service mock for tests */ export declare class HttpClientMock extends HttpClient { _requestFn: any; /** * Constructs HTTP client mock * @param {Function(options:Object):Promise} requestFn mocked request function * @param {Number} timeout request timeout in seconds * @param {RetryOptions} retryOpts retry options */ constructor(requestFn: any, timeout: any, retryOpts: any); _makeRequest(...args: any[]): any; } /** * retry options */ export declare type RetryOptions = { /** * the number of attempts to retry failed request, default 5 */ retries?: number; /** * minimum delay in seconds before retrying, default 1 */ minDelayInSeconds?: number; /** * maximum delay in seconds before retrying, default 30 */ maxDelayInSeconds?: number; /** * timeout in minutes for long running requests, default 10 */ longRunningRequestTimeoutInMinutes?: number; /** * time to disable new subscriptions for */ subscribeCooldownInSeconds?: number; };