UNPKG

okotoki

Version:
69 lines (68 loc) 2.94 kB
import 'isomorphic-fetch'; import WebSocket from 'isomorphic-ws'; import { CandlesSubscription, CandlesSubscriptionOptions, Exchange, IndexSubscription, InMessage, LeveledTradeVolumeSubscription, LeveledTradeVolumeSubscriptionOptions, Market, OrderBookSubscription, OrderBookSubscriptionOptions, PriceSubscription, Subscription, TradeSubscription, TradeSubscriptionOptions, TradeVolumeSubscription } from './types'; export * from './types'; export type WsOptions = Partial<{ connectionTimeout: number; WebSocket: WebSocket; debug: boolean; maxReconnectionDelay: number; minReconnectionDelay: number; maxRetries: number; }>; export type OkotokiApiOptions = { key: string; secret: string; wsUrl?: string; restUrl?: string; debug?: boolean; useBinary?: boolean; }; export declare const largeTrades: (exchange: Exchange, symbol: string, options: TradeSubscriptionOptions) => TradeSubscription; export declare const orderBook: (exchange: Exchange, symbol: string, options: OrderBookSubscriptionOptions) => OrderBookSubscription; export declare const price: (exchange: Exchange, symbol: string) => PriceSubscription; export declare const tradeVolume: (exchange: Exchange, symbol: string) => TradeVolumeSubscription; export declare const leveledTradeVolume: (exchange: Exchange, symbol: string, options: LeveledTradeVolumeSubscriptionOptions) => LeveledTradeVolumeSubscription; export declare const candle: (exchange: Exchange, symbol: string, options: CandlesSubscriptionOptions) => CandlesSubscription; export declare const coinIndex: (coin: string) => IndexSubscription; export type ConnectionState = 'disconnected' | 'connecting' | 'connected'; export default class Api { private options; private wsOptions?; private _rws?; private _wsUrl; private _restUrl; private pingInterval; private binarySchema; private _initiallyConnected; private debug; onMessage: (msg: InMessage) => void; onConnectionStateChange: (state: ConnectionState) => void; constructor(options: OkotokiApiOptions, wsOptions?: Partial<{ connectionTimeout: number; WebSocket: WebSocket; debug: boolean; maxReconnectionDelay: number; minReconnectionDelay: number; maxRetries: number; }> | undefined); getSupportedCoins: () => Promise<string[]>; getMarketsForCoin: (coin: string) => Promise<Market[]>; subscribe(subscriptions: Subscription[]): void; connect(): void; disconnect(): void; reconnect(): void; _preConnectSubscriptionsQueue: Subscription[][]; private _sendSubscriptionMessage; private _rawBinaryToNormalized; private _parseIncomingMessage; private _onMessage; private _send; private _updatePingInterval; private stopPingInterval; private _ping; private _auth; private _onError; private _onConnectionEstabilished; private _onConnectionClosed; }