UNPKG

coinbase-pro-node-api

Version:
235 lines (234 loc) 5.33 kB
/// <reference types="node" /> import { EventEmitter } from "node:events"; import WebSocket from "ws"; import { ProductInfo, CurrencyDetails, Side } from "./public.js"; export declare const WsUri = "wss://ws-feed.exchange.coinbase.com"; export declare const SandboxWsUri = "wss://ws-feed-public.sandbox.exchange.coinbase.com"; export declare const DefaultChannels: { name: string; product_ids: string[]; }[]; export declare type Channel = | { name: "status"; } | { name: string; product_ids: string[]; }; export interface SubscribeParams { channels: Channel[]; } export interface Subscription extends SubscribeParams { type: "subscribe" | "unsubscribe"; } export interface SignedMessage extends Subscription { key?: string; signature?: string; timestamp?: string; passphrase?: string; } export interface WSMessageHeartbeat { type: "heartbeat"; sequence: number; last_trade_id: number; product_id: string; time: string; } export interface WSMessageSnapshot { type: "snapshot"; product_id: string; bids: [string, string][]; asks: [string, string][]; } export interface WSMessageL2Update { type: "l2update"; product_id: string; changes: [string, string, string][]; time: string; } export interface WSMessageReceived { type: "received"; side: Side; product_id: string; time: string; sequence: number; order_id: string; order_type: "limit" | "market"; client_oid?: string; size?: string; price?: string; funds?: string; profile_id?: string; user_id?: string; } export interface WSMessageOpen { type: "open"; side: Side; product_id: string; time: string; sequence: number; price: string; order_id: string; remaining_size: string; profile_id?: string; user_id?: string; } export interface WSMessageMatch { type: "match"; trade_id: number; maker_order_id: string; taker_order_id: string; side: Side; size: string; price: string; product_id: string; sequence: number; time: string; } export interface WSMessageChange { type: "change"; side: Side; product_id: string; time: string; sequence: number; price: string; order_id: string; new_size?: string; old_size?: string; new_funds?: string; old_funds?: string; profile_id?: string; user_id?: string; } export interface WSMessageDone { type: "done"; side: Side; product_id: string; time: string; sequence: number; order_id: string; reason: "filled" | "canceled"; price?: string; remaining_size?: string; profile_id?: string; user_id?: string; } export interface WSMessageActivate { type: "activate"; side: Side; product_id: string; time: string; sequence: number; order_id: string; client_oid?: string; stop_price: string; limit_price: string; size: string; taker_fee_rate?: string; stop_type: string; profile_id?: string; user_id?: string; } export interface WSMessageTicker { type: "ticker"; sequence: number; product_id: string; price: string; open_24h: string; volume_24h: string; low_24h: string; high_24h: string; volume_30d: string; best_bid: string; best_ask: string; side: Side; time: string; trade_id: number; last_size: string; } export interface WSMessageLastMatch { type: "last_match"; trade_id: number; maker_order_id: string; taker_order_id: string; side: Side; size: string; price: string; product_id: string; sequence: number; time: string; } export interface WSMessageSubscriptions { type: "subscriptions"; channels: { name: string; product_ids: string[]; }[]; } export interface WSMessageStatus { type: "status"; currencies: { id: string; name: string; min_size: string; status: string; funding_account_id: string; status_message: string; max_precision: string; convertible_to: string[]; details: CurrencyDetails; }[]; products: (ProductInfo & { type: string; })[]; } export declare type WSMessage = | WSMessageHeartbeat | WSMessageSnapshot | WSMessageL2Update | WSMessageReceived | WSMessageOpen | WSMessageMatch | WSMessageChange | WSMessageDone | WSMessageActivate | WSMessageTicker | WSMessageLastMatch | WSMessageSubscriptions | WSMessageStatus; export interface WebSocketClientOptions { wsUri?: string; channels?: Channel[]; key?: string; secret?: string; passphrase?: string; sandbox?: boolean; } export declare interface WebSocketClient { on(event: "open" | "close", eventListener: () => void): this; on(event: "message", eventListener: (data: WSMessage) => void): this; on(event: "error", eventListener: (error: unknown) => void): this; once(event: "open" | "close", eventListener: () => void): this; once(event: "message", eventListener: (data: WSMessage) => void): this; once(event: "error", eventListener: (error: unknown) => void): this; } export declare class WebSocketClient extends EventEmitter { #private; ws?: WebSocket; readonly wsUri: string; readonly channels: Channel[]; constructor({ channels, key, secret, passphrase, sandbox, wsUri, }?: WebSocketClientOptions); connect(): Promise<void>; disconnect(): Promise<void>; subscribe(params: SubscribeParams): Promise<void>; unsubscribe(params: SubscribeParams): Promise<void>; }