@@ -262,6 +262,8 @@ const huobiMapper: SubscriptionMapper = {
262262}
263263
264264// https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/websocket.md
265+ const BYBIT_V5_API_SWITCH_DATE = new Date ( '2023-04-05T00:00:00.000Z' )
266+
265267const bybitMapper : SubscriptionMapper = {
266268 canHandle : ( message : any ) => {
267269 return message . op === 'subscribe'
@@ -280,11 +282,24 @@ const bybitMapper: SubscriptionMapper = {
280282}
281283
282284const bybitSpotMapper : SubscriptionMapper = {
283- canHandle : ( message : any ) => {
285+ canHandle : ( message : any , date : Date ) => {
286+ if ( date . valueOf ( ) > BYBIT_V5_API_SWITCH_DATE . valueOf ( ) ) {
287+ return message . op === 'subscribe'
288+ }
284289 return message . event === 'sub'
285290 } ,
286291
287- map : ( message : any ) => {
292+ map : ( message : any , date : Date ) => {
293+ if ( date . valueOf ( ) > BYBIT_V5_API_SWITCH_DATE . valueOf ( ) ) {
294+ return ( message . args as string [ ] ) . map ( ( arg ) => {
295+ const pieces = arg . split ( '.' )
296+ return {
297+ channel : pieces [ 0 ] ,
298+ symbols : [ pieces [ pieces . length - 1 ] ]
299+ }
300+ } )
301+ }
302+
288303 return [
289304 {
290305 channel : message . topic ,
@@ -713,6 +728,6 @@ export const subscriptionsMappers: { [key in Exchange]: SubscriptionMapper } = {
713728}
714729
715730export type SubscriptionMapper = {
716- canHandle : ( message : object ) => boolean
717- map : ( message : object ) => Filter < string > [ ]
731+ canHandle : ( message : object , date : Date ) => boolean
732+ map : ( message : object , date : Date ) => Filter < string > [ ]
718733}
0 commit comments