Skip to content

Commit 30d4b84

Browse files
committed
Add MEXC machine support
1 parent fe428e2 commit 30d4b84

4 files changed

Lines changed: 95 additions & 5 deletions

File tree

package-lock.json

Lines changed: 23 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"debug": "^4.4.1",
7979
"find-my-way": "^9.3.0",
8080
"is-docker": "^2.2.1",
81-
"tardis-dev": "^16.5.0",
81+
"tardis-dev": "^16.6.0",
8282
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.59.0",
8383
"yargs": "^17.5.1"
8484
},

src/ws/subscriptionsmappers.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,49 @@ const bitgetMapper: SubscriptionMapper = {
635635
})
636636
}
637637
}
638+
639+
const mexcMapper: SubscriptionMapper = {
640+
canHandle: (message: any) => {
641+
return message.method === 'SUBSCRIPTION' && Array.isArray(message.params)
642+
},
643+
644+
map: (message: any) => {
645+
return message.params.map((param: string) => {
646+
const separator = param.lastIndexOf('@')
647+
648+
return {
649+
channel: separator === -1 ? param : param.slice(0, separator),
650+
symbols: separator === -1 ? [] : [param.slice(separator + 1)]
651+
}
652+
})
653+
}
654+
}
655+
656+
const mexcFuturesChannelMappings: Record<string, string> = {
657+
'sub.deal': 'push.deal',
658+
'sub.depth': 'push.depth',
659+
'sub.ticker': 'push.ticker',
660+
'sub.index.price': 'push.index.price',
661+
'sub.fair.price': 'push.fair.price',
662+
'sub.funding.rate': 'push.funding.rate',
663+
'sub.contract': 'push.contract'
664+
}
665+
666+
const mexcFuturesMapper: SubscriptionMapper = {
667+
canHandle: (message: any) => {
668+
return mexcFuturesChannelMappings[message.method] !== undefined
669+
},
670+
671+
map: (message: any) => {
672+
return [
673+
{
674+
channel: mexcFuturesChannelMappings[message.method],
675+
symbols: message.param?.symbol !== undefined ? [message.param.symbol] : []
676+
}
677+
]
678+
}
679+
}
680+
638681
const coinbaseInternationalMapper: SubscriptionMapper = {
639682
canHandle: (message: any) => {
640683
return message.type === 'SUBSCRIBE'
@@ -786,6 +829,8 @@ export const subscriptionsMappers: Record<Exchange, SubscriptionMapper> = {
786829
'kucoin-futures': kucoinMapper,
787830
bitget: bitgetMapper,
788831
'bitget-futures': bitgetMapper,
832+
mexc: mexcMapper,
833+
'mexc-futures': mexcFuturesMapper,
789834
'coinbase-international': coinbaseInternationalMapper,
790835
hyperliquid: hyperliquidMapper,
791836
lighter: lighterMapper,

test/subscriptionsmappers.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,32 @@ describe('subscriptions mappers', () => {
1313
])
1414
})
1515

16+
test('maps MEXC spot subscriptions', () => {
17+
const mapper = subscriptionsMappers.mexc
18+
const date = new Date()
19+
const message = {
20+
method: 'SUBSCRIPTION',
21+
params: ['spot@public.aggre.deals.v3.api.pb@10ms@BTCUSDT', 'spot@public.aggre.depth.v3.api.pb@10ms@ETHUSDT']
22+
}
23+
24+
expect(mapper.canHandle(message, date)).toBe(true)
25+
expect(mapper.map(message, date)).toEqual([
26+
{ channel: 'spot@public.aggre.deals.v3.api.pb@10ms', symbols: ['BTCUSDT'] },
27+
{ channel: 'spot@public.aggre.depth.v3.api.pb@10ms', symbols: ['ETHUSDT'] }
28+
])
29+
})
30+
31+
test('maps MEXC futures subscriptions', () => {
32+
const mapper = subscriptionsMappers['mexc-futures']
33+
const date = new Date()
34+
35+
expect(mapper.canHandle({ method: 'sub.depth', param: { symbol: 'BTC_USDT' }, gzip: false }, date)).toBe(true)
36+
expect(mapper.map({ method: 'sub.depth', param: { symbol: 'BTC_USDT' }, gzip: false }, date)).toEqual([
37+
{ channel: 'push.depth', symbols: ['BTC_USDT'] }
38+
])
39+
expect(mapper.map({ method: 'sub.contract' }, date)).toEqual([{ channel: 'push.contract', symbols: [] }])
40+
})
41+
1642
test('maps lighter symbol-scoped subscriptions', () => {
1743
const mapper = subscriptionsMappers.lighter
1844

0 commit comments

Comments
 (0)