Skip to content

Commit c4d811e

Browse files
committed
fix phemex sol spot normalization
1 parent 30cc04f commit c4d811e

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

src/mappers/phemex.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ function getQtyScale(symbol: string) {
2727
return 1
2828
}
2929

30+
function isExcludedFromNormalizedOutput(symbol: string) {
31+
// Matches tardis-api metadata: Phemex spot OL/USDT uses sOLUSDT, which collides with SOLUSDT when normalized.
32+
return symbol === 'sOLUSDT'
33+
}
34+
3035
const COINS_STARTING_WITH_S = [
3136
'SOLUSD',
3237
'SUSHIUSD',
@@ -163,10 +168,13 @@ export const phemexTradesMapper: Mapper<'phemex', Trade> = {
163168
},
164169

165170
*map(message: PhemexTradeMessage, localTimestamp: Date): IterableIterator<Trade> {
171+
const symbol = message.symbol
172+
if (isExcludedFromNormalizedOutput(symbol)) {
173+
return
174+
}
175+
166176
if ('trades' in message) {
167177
for (const [timestamp, side, priceEp, qty] of message.trades) {
168-
const symbol = message.symbol
169-
170178
yield {
171179
type: 'trade',
172180
symbol: symbol.toUpperCase(),
@@ -181,8 +189,6 @@ export const phemexTradesMapper: Mapper<'phemex', Trade> = {
181189
}
182190
} else if ('trades_p' in message) {
183191
for (const [timestamp, side, price, qty] of message.trades_p) {
184-
const symbol = message.symbol
185-
186192
yield {
187193
type: 'trade',
188194
symbol: symbol.toUpperCase(),
@@ -253,6 +259,10 @@ export const phemexBookChangeMapper: Mapper<'phemex', BookChange> = {
253259

254260
*map(message: PhemexBookMessage, localTimestamp: Date): IterableIterator<BookChange> {
255261
const symbol = message.symbol
262+
if (isExcludedFromNormalizedOutput(symbol)) {
263+
return
264+
}
265+
256266
if ('book' in message) {
257267
const mapBookLevel = mapBookLevelForSymbol(symbol)
258268
yield {

test/__snapshots__/mappers.test.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12118,6 +12118,10 @@ exports[`mappers map phemex messages 15`] = `
1211812118
]
1211912119
`;
1212012120

12121+
exports[`mappers map phemex messages 16`] = `[]`;
12122+
12123+
exports[`mappers map phemex messages 17`] = `[]`;
12124+
1212112125
exports[`mappers map poloniex messages 1`] = `
1212212126
[
1212312127
{

test/mappers.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6675,7 +6675,19 @@ describe('mappers', () => {
66756675
timestamp: 1669198855202180601,
66766676
type: 'incremental'
66776677
},
6678-
{ sequence: 80321106, symbol: 'XRPUSDT', trades_p: [[1669198857616162039, 'Buy', '0.3758', '244.65']], type: 'incremental' }
6678+
{ sequence: 80321106, symbol: 'XRPUSDT', trades_p: [[1669198857616162039, 'Buy', '0.3758', '244.65']], type: 'incremental' },
6679+
{
6680+
book: {
6681+
asks: [[1238100, 11840000000]],
6682+
bids: [[1238000, 10000000000]]
6683+
},
6684+
depth: 30,
6685+
sequence: 23906375249,
6686+
symbol: 'sOLUSDT',
6687+
timestamp: 1772323195423084785,
6688+
type: 'incremental'
6689+
},
6690+
{ sequence: 23912236867, symbol: 'sOLUSDT', trades: [[1772323222771984119, 'Sell', 1228700, 41250000000]], type: 'incremental' }
66796691
]
66806692
const phemex = createMapper('phemex')
66816693

0 commit comments

Comments
 (0)