repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | /** |
| #2 | * Imperial WebSocket Client |
| #3 | * |
| #4 | * Two persistent connections: |
| #5 | * /ws — wallet-scoped invalidation (positions_updated, orders_updated) |
| #6 | * /ws/market — public market data stream (funding, marks, depth) |
| #7 | * |
| #8 | * Typed event emitter with automatic ping/pong keepalive and exponential-backoff |
| #9 | * reconnect. Works in both Node (ws package) and browser (native WebSocket). |
| #10 | */ |
| #11 | type Listener<T> = (data: T) => void; |
| #12 | export interface FundingUpdateEvent { |
| #13 | type: "funding_rate_update"; |
| #14 | symbol: string; |
| #15 | venue: string; |
| #16 | source: string; |
| #17 | longFundingRatePerHourPercent: number | null; |
| #18 | shortFundingRatePerHourPercent: number | null; |
| #19 | longBorrowRatePerHourPercent: number | null; |
| #20 | shortBorrowRatePerHourPercent: number | null; |
| #21 | } |
| #22 | export interface MarkPriceUpdateEvent { |
| #23 | type: "mark_price_update"; |
| #24 | symbol: string; |
| #25 | venue: string; |
| #26 | source: string; |
| #27 | price: number; |
| #28 | fetchedAtUnixMs: number; |
| #29 | } |
| #30 | export interface DepthUpdateEvent { |
| #31 | type: "phoenix_depth_update"; |
| #32 | symbol: string; |
| #33 | snapshot: { |
| #34 | bids: [number, number][]; |
| #35 | asks: [number, number][]; |
| #36 | }; |
| #37 | } |
| #38 | export interface WalletEvent { |
| #39 | type: "positions_updated" | "orders_updated"; |
| #40 | } |
| #41 | export type MarketEvent = FundingUpdateEvent | MarkPriceUpdateEvent | DepthUpdateEvent; |
| #42 | export interface MarketCache { |
| #43 | funding: Map<string, FundingUpdateEvent>; |
| #44 | markPrices: Map<string, MarkPriceUpdateEvent>; |
| #45 | depth: Map<string, DepthUpdateEvent["snapshot"]>; |
| #46 | lastUpdated: number; |
| #47 | } |
| #48 | export declare function createMarketCache(): MarketCache; |
| #49 | declare class TypedEmitter<Events extends object> { |
| #50 | private listeners; |
| #51 | on<K extends keyof Events>(event: K, listener: Listener<Events[K]>): this; |
| #52 | off<K extends keyof Events>(event: K, listener: Listener<Events[K]>): this; |
| #53 | emit<K extends keyof Events>(event: K, data: Events[K]): void; |
| #54 | } |
| #55 | interface MarketWsEventMap { |
| #56 | funding: FundingUpdateEvent; |
| #57 | mark: MarkPriceUpdateEvent; |
| #58 | depth: DepthUpdateEvent; |
| #59 | connected: void; |
| #60 | disconnected: { |
| #61 | code: number; |
| #62 | reason: string; |
| #63 | }; |
| #64 | error: Error; |
| #65 | } |
| #66 | export declare class ImperialMarketWs extends TypedEmitter<MarketWsEventMap> { |
| #67 | private readonly wsUrl; |
| #68 | private readonly subscribeSymbols?; |
| #69 | private ws; |
| #70 | private stopped; |
| #71 | private reconnectDelay; |
| #72 | private pingTimer; |
| #73 | readonly cache: MarketCache; |
| #74 | constructor(wsUrl: string, subscribeSymbols?: string[] | undefined); |
| #75 | connect(): Promise<void>; |
| #76 | private subscribe; |
| #77 | private handleMessage; |
| #78 | private startPing; |
| #79 | private stopPing; |
| #80 | private scheduleReconnect; |
| #81 | /** Get latest mark price for a symbol from cache. */ |
| #82 | getMarkPrice(symbol: string, venue?: string): number | null; |
| #83 | /** Get latest funding for a symbol+venue from cache. */ |
| #84 | getFunding(symbol: string, venue?: string): FundingUpdateEvent | null; |
| #85 | /** Get latest depth snapshot for a symbol. */ |
| #86 | getDepth(symbol: string): DepthUpdateEvent["snapshot"] | null; |
| #87 | /** Best mid price from depth cache. */ |
| #88 | getMid(symbol: string): number | null; |
| #89 | disconnect(): void; |
| #90 | } |
| #91 | interface WalletWsEventMap { |
| #92 | positions_updated: void; |
| #93 | orders_updated: void; |
| #94 | connected: void; |
| #95 | disconnected: { |
| #96 | code: number; |
| #97 | reason: string; |
| #98 | }; |
| #99 | error: Error; |
| #100 | } |
| #101 | export declare class ImperialWalletWs extends TypedEmitter<WalletWsEventMap> { |
| #102 | private readonly wsUrl; |
| #103 | private readonly wallet; |
| #104 | private ws; |
| #105 | private stopped; |
| #106 | private reconnectDelay; |
| #107 | private pingTimer; |
| #108 | constructor(wsUrl: string, wallet: string); |
| #109 | connect(): Promise<void>; |
| #110 | private scheduleReconnect; |
| #111 | disconnect(): void; |
| #112 | } |
| #113 | export declare function createImperialMarketWs(base: string, symbols?: string[]): ImperialMarketWs; |
| #114 | export declare function createImperialWalletWs(base: string, wallet: string): ImperialWalletWs; |
| #115 | export {}; |
| #116 |