UNPKG

@drift-labs/common

Version:

Common functions for Drift

58 lines (57 loc) 2.33 kB
import { MarketId } from '../../types/MarketId'; export type OrderbookGrouping = 1 | 10 | 100 | 500 | 1000; export type DlobServerChannel = 'trades' | 'orderbook' | 'orderbook_indicative' | 'heartbeat'; type BaseSubscriptionOutputProps<T extends DlobServerChannel> = { type: 'subscribe'; channel: T; }; interface OrderbookSubscriptionOutputProps extends BaseSubscriptionOutputProps<'orderbook' | 'orderbook_indicative'> { marketType: 'perp' | 'spot'; market: string; grouping?: OrderbookGrouping; } interface TradeSubscriptionOutputProps extends BaseSubscriptionOutputProps<'trades'> { marketType: 'perp' | 'spot'; market: string; } type WebsocketSubscriptionOutputProps = TradeSubscriptionOutputProps | OrderbookSubscriptionOutputProps; type BaseUnsubscriptionOutputProps<T extends DlobServerChannel> = { type: 'unsubscribe'; channel: T; }; interface OrderbookUnsubscriptionOutputProps extends BaseUnsubscriptionOutputProps<'orderbook' | 'orderbook_indicative'> { marketType: 'perp' | 'spot'; market: string; grouping?: OrderbookGrouping; } interface TradeUnsubscriptionOutputProps extends BaseUnsubscriptionOutputProps<'trades'> { marketType: 'perp' | 'spot'; market: string; } type WebsocketUnsubscriptionOutputProps = OrderbookUnsubscriptionOutputProps | TradeUnsubscriptionOutputProps; type BaseSubscriptionProps<T extends DlobServerChannel> = { type: T; }; type TargetMarketProps = { market: MarketId; }; interface OrderbookSubscriptionProps extends BaseSubscriptionProps<'orderbook' | 'orderbook_indicative'>, TargetMarketProps { grouping?: OrderbookGrouping; } interface TradesSubscriptionProps extends BaseSubscriptionProps<'trades'>, TargetMarketProps { } type WebsocketSubscriptionProps = TradesSubscriptionProps | OrderbookSubscriptionProps; export type WebsocketServerResponse = { channel: string; data: string; error?: any; }; export declare const DLOB_SERVER_WEBSOCKET_UTILS: { getSubscriptionProps: (props: WebsocketSubscriptionProps) => WebsocketSubscriptionOutputProps; getUnsubscriptionProps: (props: WebsocketSubscriptionProps) => WebsocketUnsubscriptionOutputProps; getMessageFilter: (props: WebsocketSubscriptionProps) => ((message: { channel: string; data: any; }) => boolean); }; export {};