Skip to content

Commit

Permalink
improvement: update bitget integrations to use books15
Browse files Browse the repository at this point in the history
  • Loading branch information
thaaddeus committed Nov 7, 2024
1 parent e264edd commit 972892b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 126 deletions.
4 changes: 2 additions & 2 deletions src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ const KUCOIN_FUTURES_CHANNELS = [
'contractMarket/snapshot'
]

const BITGET_CHANNELS = ['trade', 'books1', 'books']
const BITGET_FUTURES_CHANNELS = ['trade', 'books1', 'books', 'ticker']
const BITGET_CHANNELS = ['trade', 'books1', 'books15']
const BITGET_FUTURES_CHANNELS = ['trade', 'books1', 'books15', 'ticker']

export const EXCHANGE_CHANNELS_INFO = {
bitmex: BITMEX_CHANNELS,
Expand Down
42 changes: 14 additions & 28 deletions src/mappers/bitget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ export class BitgetBookChangeMapper implements Mapper<'bitget' | 'bitget-futures
constructor(private readonly _exchange: Exchange) {}

canHandle(message: BitgetOrderbookMessage) {
return message.arg.channel === 'books' && (message.action === 'update' || message.action === 'snapshot')
return message.arg.channel === 'books15' && message.action === 'snapshot'
}

getFilters(symbols?: string[]) {
symbols = upperCaseSymbols(symbols)

return [
{
channel: 'books',
channel: 'books15',
symbols
} as const
]
Expand Down Expand Up @@ -162,33 +162,19 @@ type BitgetTradeMessage = {
ts: 1730332800989
}

type BitgetOrderbookMessage =
| {
action: 'snapshot'
arg: { instType: 'SPOT'; channel: 'books'; instId: 'SYLOUSDT' }
data: [
{
asks: [string, string][]
bids: [string, string][]
checksum: 0
ts: '1730331046984'
}
]
ts: 1730332800437
}
| {
action: 'update'
arg: { instType: 'SPOT'; channel: 'books'; instId: 'BANDUSDT' }
data: [
{
asks: [string, string][]
bids: [string, string][]
checksum: 79466786
ts: '1730332859977'
}
]
ts: 1730332859979
type BitgetOrderbookMessage = {
action: 'snapshot'
arg: { instType: 'SPOT'; channel: 'books15'; instId: 'GEMSUSDT' }
data: [
{
asks: [['0.22816', '155.25']]
bids: [['0.22785', '73.41']]
checksum: 0
ts: '1730963759993'
}
]
ts: 1730963759997
}

type BitgetBBoMessage = {
action: 'snapshot'
Expand Down
155 changes: 59 additions & 96 deletions test/__snapshots__/mappers.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -173,54 +173,9 @@ Array [

exports[`map bitget messages 5`] = `Array []`;

exports[`map bitget messages 6`] = `
Array [
Object {
"asks": Array [
Object {
"amount": 1600,
"price": 0.09707,
},
Object {
"amount": 511.87,
"price": 0.09711,
},
],
"bids": Array [
Object {
"amount": 1213.91,
"price": 0.09694,
},
],
"exchange": "bitget",
"isSnapshot": true,
"localTimestamp": 2024-08-23T00:00:00.498Z,
"symbol": "BRETTUSDT",
"timestamp": 2024-10-31T00:00:00.391Z,
"type": "book_change",
},
]
`;
exports[`map bitget messages 6`] = `Array []`;

exports[`map bitget messages 7`] = `
Array [
Object {
"asks": Array [],
"bids": Array [
Object {
"amount": 3326.85,
"price": 0.12306,
},
],
"exchange": "bitget",
"isSnapshot": false,
"localTimestamp": 2024-08-23T00:00:00.498Z,
"symbol": "LMWRUSDT",
"timestamp": 2024-10-31T00:00:59.981Z,
"type": "book_change",
},
]
`;
exports[`map bitget messages 7`] = `Array []`;

exports[`map bitget messages 8`] = `
Array [
Expand All @@ -238,80 +193,55 @@ Array [
]
`;

exports[`map bitget-futures messages 1`] = `Array []`;

exports[`map bitget-futures messages 2`] = `Array []`;

exports[`map bitget-futures messages 3`] = `
Array [
Object {
"amount": 447,
"exchange": "bitget-futures",
"id": "1235671063871070209",
"localTimestamp": 2024-08-23T00:00:00.498Z,
"price": 0.168385,
"side": "buy",
"symbol": "DOGEUSD",
"timestamp": 2024-10-31T00:00:59.962Z,
"type": "trade",
},
]
`;

exports[`map bitget-futures messages 4`] = `
exports[`map bitget messages 9`] = `
Array [
Object {
"asks": Array [
Object {
"amount": 51,
"price": 0.5426,
"amount": 7.03,
"price": 0.7146,
},
],
"bids": Array [
Object {
"amount": 468,
"price": 0.542,
},
Object {
"amount": 1576,
"price": 0.5419,
"amount": 20.98,
"price": 0.7139,
},
],
"exchange": "bitget-futures",
"exchange": "bitget",
"isSnapshot": true,
"localTimestamp": 2024-08-23T00:00:00.498Z,
"symbol": "BELUSDT",
"timestamp": 2024-10-31T00:00:00.303Z,
"symbol": "MANTAUSDT",
"timestamp": 2024-11-07T07:15:59.993Z,
"type": "book_change",
},
]
`;

exports[`map bitget-futures messages 5`] = `
exports[`map bitget-futures messages 1`] = `Array []`;

exports[`map bitget-futures messages 2`] = `Array []`;

exports[`map bitget-futures messages 3`] = `
Array [
Object {
"asks": Array [
Object {
"amount": 144.6,
"price": 5.085,
},
],
"bids": Array [
Object {
"amount": 536.2,
"price": 5.081,
},
],
"amount": 447,
"exchange": "bitget-futures",
"isSnapshot": false,
"id": "1235671063871070209",
"localTimestamp": 2024-08-23T00:00:00.498Z,
"symbol": "AXSUSDT",
"timestamp": 2024-10-31T00:00:59.988Z,
"type": "book_change",
"price": 0.168385,
"side": "buy",
"symbol": "DOGEUSD",
"timestamp": 2024-10-31T00:00:59.962Z,
"type": "trade",
},
]
`;

exports[`map bitget-futures messages 4`] = `Array []`;

exports[`map bitget-futures messages 5`] = `Array []`;

exports[`map bitget-futures messages 6`] = `
Array [
Object {
Expand Down Expand Up @@ -384,6 +314,39 @@ Array [
]
`;

exports[`map bitget-futures messages 11`] = `
Array [
Object {
"asks": Array [
Object {
"amount": 641.4443,
"price": 0.47256,
},
Object {
"amount": 3074.3765,
"price": 0.47257,
},
Object {
"amount": 2677.56,
"price": 0.47377,
},
],
"bids": Array [
Object {
"amount": 18.7835,
"price": 0.47242,
},
],
"exchange": "bitget-futures",
"isSnapshot": true,
"localTimestamp": 2024-08-23T00:00:00.498Z,
"symbol": "YGGUSDT",
"timestamp": 2024-11-07T07:15:59.972Z,
"type": "book_change",
},
]
`;

exports[`map bitnomial messages 1`] = `
Array [
Object {
Expand Down

0 comments on commit 972892b

Please sign in to comment.