-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v3.8.1: feat() add type guard and type for ws orderbook events
- Loading branch information
tiagosiebler
committed
Jan 17, 2024
1 parent
1ac1aa5
commit 9cb22d1
Showing
5 changed files
with
76 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './BaseRestClient'; | ||
export * from './requestUtils'; | ||
export * from './WsStore'; | ||
export * from './logger'; | ||
export * from './requestUtils'; | ||
export * from './typeGuards'; | ||
export * from './websocket-util'; | ||
export * from './WsStore'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Use type guards to narrow down types with minimal efforts. | ||
*/ | ||
|
||
import { WSOrderbookEventV5 } from '../types/websocket.events'; | ||
|
||
/** | ||
* Type guard to detect a V5 orderbook event (delta & snapshots) | ||
* | ||
* @param event | ||
* @returns | ||
*/ | ||
export function isWsOrderbookEventV5( | ||
event: unknown, | ||
): event is WSOrderbookEventV5 { | ||
if ( | ||
typeof event !== 'object' || | ||
!event || | ||
typeof event['topic'] !== 'string' || | ||
typeof event['type'] !== 'string' | ||
) { | ||
return false; | ||
} | ||
|
||
return ( | ||
['delta', 'snapshot'].includes(event['type']) && | ||
event['topic'].startsWith('orderbook') | ||
); | ||
} |