Add type guards for ws position events
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user