Skip to content

Commit 96be9c4

Browse files
authored
Merge pull request #544 from JJ-Cro/wsapiTypeGuards
chore(): checked all ws public topics for type guards
2 parents 9677208 + 2348669 commit 96be9c4

File tree

2 files changed

+86
-9
lines changed

2 files changed

+86
-9
lines changed

examples/WebSockets/ws-public.ts

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
import {
33
DefaultLogger,
44
isWsAggTradeFormatted,
5+
isWsFormatted24hrTicker,
6+
isWsFormatted24hrTickerArray,
7+
isWsFormattedForceOrder,
58
isWsFormattedKline,
69
isWsFormattedMarkPriceUpdateArray,
710
isWsFormattedMarkPriceUpdateEvent,
11+
isWsFormattedRollingWindowTickerArray,
12+
isWsFormattedTrade,
13+
isWsPartialBookDepthEventFormatted,
814
WebsocketClient,
915
} from '../../src';
1016

@@ -72,6 +78,30 @@ import {
7278
return;
7379
}
7480

81+
if (isWsFormattedTrade(data)) {
82+
return console.log('log trade: ', data);
83+
}
84+
85+
if (isWsFormattedForceOrder(data)) {
86+
return console.log('log force order: ', data);
87+
}
88+
89+
if (isWsFormatted24hrTickerArray(data)) {
90+
return console.log('log 24hr ticker array: ', data);
91+
}
92+
93+
if (isWsFormattedRollingWindowTickerArray(data)) {
94+
return console.log('log rolling window ticker array: ', data);
95+
}
96+
97+
if (isWsFormatted24hrTicker(data)) {
98+
return console.log('log 24hr ticker: ', data);
99+
}
100+
101+
if (isWsPartialBookDepthEventFormatted(data)) {
102+
return console.log('log partial book depth event: ', data);
103+
}
104+
75105
console.log('log unhandled formattedMessage: ', data);
76106
});
77107

@@ -194,7 +224,54 @@ import {
194224
'!markPrice@arr',
195225
// Kline/Candlestick Streams
196226
// https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Kline-Candlestick-Streams
197-
'btcusdt@kline_1m',
227+
// 'btcusdt@kline_1m',
228+
// Continuous Contract Kline/Candlestick Streams
229+
// https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Continuous-Contract-Kline-Candlestick-Streams
230+
// 'btcusdt_perpetual@continuousKline_1m', // DOESNT EXIST AS TYPE GUARD, ONLY IN BEAUTIFIER
231+
// Individual Symbol Mini Ticker Stream
232+
// https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Individual-Symbol-Mini-Ticker-Stream
233+
// 'btcusdt@miniTicker', // DOESNT EXIST AS TYPE GUARD, ONLY FOR RAW MESSAGE
234+
// All Market Mini Tickers Stream
235+
// https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/All-Market-Mini-Tickers-Stream
236+
// '!miniTicker@arr', // DOESNT EXIST AS TYPE GUARD
237+
// Individual Symbol Ticker Streams
238+
// https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Individual-Symbol-Ticker-Streams
239+
//'btcusdt@ticker',
240+
// All Market Tickers Stream
241+
// https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/All-Market-Tickers-Stream
242+
// '!ticker@arr', // DOESNT EXIST AS TYPE GUARD
243+
// Individual Symbol Book Ticker Streams
244+
// https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Individual-Symbol-Book-Ticker-Streams
245+
//'btcusdt@bookTicker', // DOESNT EXIST AS TYPE GUARD
246+
// All Book Tickers Stream
247+
// https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/All-Book-Tickers-Stream
248+
// '!bookTicker', // DOESNT EXIST AS TYPE GUARD
249+
// Liquidation Order Stream
250+
// https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Liquidation-Order-Streams
251+
// 'btcusdt@forceOrder',
252+
// Liquidation Order Stream for All market
253+
// https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/All-Market-Liquidation-Order-Streams
254+
//'!forceOrder@arr',
255+
// Partial Book Depth Streams
256+
// https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Partial-Book-Depth-Streams
257+
//'btcusdt@depth5',
258+
// 'btcusdt@depth10@100ms'
259+
// Diff. Book Depth Stream
260+
// https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Diff-Book-Depth-Streams
261+
// 'btcusdt@depth',
262+
// 'btcusdt@depth@100ms',
263+
// 'btcusdt@depth@500ms',
264+
// 'btcusdt@depth@1000ms'
265+
// Composite Index Symbol Information Streams
266+
// https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Composite-Index-Symbol-Information-Streams
267+
// 'btcusdt@compositeIndex' // DOESNT EXIST AS TYPE GUARD
268+
// Contract Info Stream
269+
// https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Contract-Info-Stream
270+
// '!contractInfo' // DOESNT EXIST AS TYPE GUARD
271+
// Multi-Assets Mode Asset Index Stream
272+
// https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Multi-Assets-Mode-Asset-Index
273+
// '!assetIndex@arr' // DOESNT EXIST AS TYPE GUARD
274+
// 'btcusdt@assetIndex'
198275
],
199276
'usdm',
200277
);

src/util/typeGuards.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function isWsFormattedMarkPriceUpdateEvent( // ok
5555
return !Array.isArray(data) && data.eventType === 'markPriceUpdate';
5656
}
5757

58-
export function isWsFormattedMarkPriceUpdateArray(
58+
export function isWsFormattedMarkPriceUpdateArray( // ok
5959
data: WsFormattedMessage,
6060
): data is WsMessageMarkPriceUpdateEventFormatted[] {
6161
return (
@@ -72,31 +72,31 @@ export function isWsFormattedMarkPriceUpdate(
7272
return isWsFormattedMarkPriceUpdateArray(data);
7373
}
7474

75-
export function isWsFormattedTrade(
75+
export function isWsFormattedTrade( // ok
7676
data: WsFormattedMessage,
7777
): data is WsMessageTradeFormatted {
7878
return !Array.isArray(data) && data.eventType === 'trade';
7979
}
8080

81-
export function isWsFormattedKline(
81+
export function isWsFormattedKline( // ok
8282
data: WsFormattedMessage,
8383
): data is WsMessageKlineFormatted {
8484
return !Array.isArray(data) && data.eventType === 'kline';
8585
}
8686

87-
export function isWsFormatted24hrTicker(
87+
export function isWsFormatted24hrTicker( // ok
8888
data: WsFormattedMessage,
8989
): data is WsMessage24hrTickerFormatted {
9090
return !Array.isArray(data) && data.eventType === '24hrTicker';
9191
}
9292

93-
export function isWsFormattedForceOrder(
93+
export function isWsFormattedForceOrder( // ok
9494
data: WsFormattedMessage,
9595
): data is WsMessageForceOrderFormatted {
9696
return !Array.isArray(data) && data.eventType === 'forceOrder';
9797
}
9898

99-
export function isWsFormatted24hrTickerArray(
99+
export function isWsFormatted24hrTickerArray( // BROKEN
100100
data: WsFormattedMessage,
101101
): data is WsMessage24hrTickerFormatted[] {
102102
return (
@@ -106,7 +106,7 @@ export function isWsFormatted24hrTickerArray(
106106
);
107107
}
108108

109-
export function isWsFormattedRollingWindowTickerArray(
109+
export function isWsFormattedRollingWindowTickerArray( // dont exist anymore ??
110110
data: WsFormattedMessage,
111111
): data is WsMessageRollingWindowTickerFormatted[] {
112112
return (
@@ -136,7 +136,7 @@ const partialBookDepthEventTypeMap = new Map()
136136
.set('depth10@1000ms', true)
137137
.set('depth20@1000ms', true);
138138

139-
export function isWsPartialBookDepthEventFormatted(
139+
export function isWsPartialBookDepthEventFormatted( // BROKEN
140140
data: WsFormattedMessage,
141141
): data is WsMessagePartialBookDepthEventFormatted {
142142
return (

0 commit comments

Comments
 (0)