UNPKG

binance

Version:

Professional Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & end-to-end tests.

74 lines (73 loc) 3.43 kB
import { AxiosRequestConfig, Method } from 'axios'; import { BinanceBaseUrlKey } from '../types/shared'; import { GenericAPIResponse, RestClientOptions } from './requestUtils'; type ApiLimitHeader = 'x-mbx-used-weight' | 'x-mbx-used-weight-1m' | 'x-sapi-used-ip-weight-1m' | 'x-mbx-order-count-1s' | 'x-mbx-order-count-10s' | 'x-mbx-order-count-1m' | 'x-mbx-order-count-1h' | 'x-mbx-order-count-1d'; export default abstract class BaseRestClient { private timeOffset; private syncTimePromise; private options; private baseUrl; private globalRequestOptions; private key; private secret; private baseUrlKey; private beautifier; apiLimitTrackers: Record<ApiLimitHeader, number>; apiLimitLastUpdated: number; constructor(baseUrlKey: BinanceBaseUrlKey, options?: RestClientOptions, requestOptions?: AxiosRequestConfig); abstract getServerTime(baseUrlKeyOverride?: BinanceBaseUrlKey): Promise<number>; getBaseUrlKey(): BinanceBaseUrlKey; /** * Get the correct prefix for this product group (e.g. spot, margin, futures) to be used when generating a custom order ID (e.g. `newClientOrderId`). * * @returns The prefix that should be used when any custom order ID is included with an order (e.g. `newClientOrderId`). The prefix will always be 10 characters long. */ getOrderIdPrefix(): string; /** * @returns A randomly generated custom order ID that can be used when sending an order to the API. Typically used with the custom order ID parameter, such as `newClientOrderId`. */ generateNewOrderId(): string; getRateLimitStates(): { lastUpdated: number; "x-mbx-used-weight": number; "x-mbx-used-weight-1m": number; "x-sapi-used-ip-weight-1m": number; "x-mbx-order-count-1s": number; "x-mbx-order-count-10s": number; "x-mbx-order-count-1m": number; "x-mbx-order-count-1h": number; "x-mbx-order-count-1d": number; }; /** * Return time sync offset, automatically set if time sync is enabled. A higher offset means system clock is behind server time. */ getTimeOffset(): number; setTimeOffset(value: number): void; get(endpoint: string, params?: any): GenericAPIResponse; getForBaseUrl(endpoint: string, baseUrlKey: BinanceBaseUrlKey, params?: any): GenericAPIResponse; getPrivate(endpoint: string, params?: any): GenericAPIResponse; post(endpoint: string, params?: any): GenericAPIResponse; postPrivate(endpoint: string, params?: any): GenericAPIResponse; put(endpoint: string, params?: any): GenericAPIResponse; putPrivate(endpoint: string, params?: any): GenericAPIResponse; delete(endpoint: string, params?: any): GenericAPIResponse; deletePrivate(endpoint: string, params?: any): GenericAPIResponse; /** * @private Make a HTTP request to a specific endpoint. Private endpoints are automatically signed. */ _call(method: Method, endpoint: string, params?: any, isPrivate?: boolean, baseUrlOverride?: string): GenericAPIResponse; /** * @private generic handler to parse request exceptions */ private parseException; private updateApiLimitState; /** * Trigger time sync and store promise */ syncTime(): Promise<void>; /** * Estimate drift based on client<->server latency */ fetchTimeOffset(): Promise<number>; } export {};