From 510eb35fea5b88675a45bc553530bdfeba9db6d3 Mon Sep 17 00:00:00 2001 From: William Date: Tue, 30 Apr 2024 22:16:27 +0200 Subject: [PATCH] Introduce `WSPublicTopicEventV5` and `WSPrivateTopicEventV5` --- src/types/websocket.events.ts | 71 ++++++++++++++++------------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/src/types/websocket.events.ts b/src/types/websocket.events.ts index c9da412..cb11da5 100644 --- a/src/types/websocket.events.ts +++ b/src/types/websocket.events.ts @@ -20,25 +20,15 @@ import { } from './v5-shared'; import { WsKey } from './websockets'; -export interface WSOrderbookEventV5 { - topic: string; +export interface WSPublicTopicEventV5 { + id?: string; + topic: TTopic; + type: TType; + /** Cross sequence */ + cs?: number; /** Event timestamp */ ts: number; - type: 'delta' | 'snapshot'; - data: { - /** Symbol */ - s: string; - /** [price, qty][] */ - b: [string, string][]; - /** [price, qty][] */ - a: [string, string][]; - /** Update ID */ - u: number; - /** - * Cross sequence - */ - seq: number; - }; + data: TData; /** * matching engine timestamp (correlated with T from public trade channel) */ @@ -49,6 +39,29 @@ export interface WSOrderbookEventV5 { wsKey: WsKey; } +export interface WSPrivateTopicEventV5 { + id?: string; + topic: TTopic; + creationTime: number; + data: TData; + wsKey: WsKey; +} + +export interface WSOrderbookV5 { + /** Symbol */ + s: string; + /** [price, qty][] */ + b: [string, string][]; + /** [price, qty][] */ + a: [string, string][]; + /** Update ID */ + u: number; + /** Cross sequence */ + seq: number; +} + +export type WSOrderbookEventV5 = WSPublicTopicEventV5; + export interface WSPositionV5 { category: string; symbol: string; @@ -90,13 +103,7 @@ export interface WSPositionV5 { seq: number; } -export interface WSPositionEventV5 { - id: string; - topic: 'position'; - creationTime: number; - data: WSPositionV5[]; - wsKey: WsKey; -} +export type WSPositionEventV5 = WSPrivateTopicEventV5<'position', WSPositionV5[]>; export interface WSAccountOrderV5 { category: CategoryV5; @@ -147,13 +154,7 @@ export interface WSAccountOrderV5 { updatedTime: string; } -export interface WSAccountOrderEventV5 { - id: string; - topic: 'order'; - creationTime: number; - data: WSAccountOrderV5[]; - wsKey: WsKey; -} +export type WSAccountOrderEventV5 = WSPrivateTopicEventV5<'order', WSAccountOrderV5[]>; export interface WSExecutionV5 { category: CategoryV5; @@ -188,10 +189,4 @@ export interface WSExecutionV5 { marketUnit: string; } -export interface WSExecutionEventV5 { - id: string; - topic: 'execution'; - creationTime: number; - data: WSExecutionV5[]; - wsKey: WsKey; -} \ No newline at end of file +export type WSExecutionEventV5 = WSPrivateTopicEventV5<'execution', WSExecutionV5[]>; \ No newline at end of file