Add type guards for ws position events

This commit is contained in:
William
2024-04-25 17:28:28 +02:00
parent ccaae1be1b
commit 12b5b0a418

View File

@@ -2,7 +2,7 @@
* Use type guards to narrow down types with minimal efforts.
*/
import { WSAccountOrderEventV5, WSExecutionEventV5, WSOrderbookEventV5 } from '../types/websocket.events';
import { WSAccountOrderEventV5, WSExecutionEventV5, WSOrderbookEventV5, WSPositionEventV5 } from '../types/websocket.events';
/**
* Type guard to detect a V5 orderbook event (delta & snapshots)
@@ -28,6 +28,26 @@ export function isWsOrderbookEventV5(
);
}
/**
* Type guard to detect a V5 position event.
*
* @param event
* @returns
*/
export function isWsPositionEventV5(
event: unknown,
): event is WSPositionEventV5 {
if (
typeof event !== 'object' ||
!event ||
typeof event['topic'] !== 'string'
) {
return false;
}
return event['topic'] === 'position';
}
/**
* Type guard to detect a V5 order event.
*