Skip to content

Commit 32cf41f

Browse files
committed
improvement: include best ask & bid size for coinbase book ticker when available
1 parent 2f9b907 commit 32cf41f

File tree

3 files changed

+68
-11
lines changed

3 files changed

+68
-11
lines changed

src/mappers/coinbase.ts

+33-11
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ export const coinbaseBookTickerMapper: Mapper<'coinbase', BookTicker> = {
155155
type: 'book_ticker',
156156
symbol: message.product_id,
157157
exchange: 'coinbase',
158-
askAmount: undefined,
158+
askAmount: message.best_ask_size !== undefined ? Number(message.best_ask_size) : undefined,
159159
askPrice: message.best_ask !== undefined ? Number(message.best_ask) : undefined,
160160
bidPrice: message.best_bid !== undefined ? Number(message.best_bid) : undefined,
161-
bidAmount: undefined,
161+
bidAmount: message.best_bid_size !== undefined ? Number(message.best_bid_size) : undefined,
162162
timestamp,
163163
localTimestamp: localTimestamp
164164
}
@@ -193,12 +193,34 @@ type CoinbaseLevel2Update = {
193193
changes: CoinbaseUpdateBookLevel[]
194194
}
195195

196-
type CoinbaseTicker = {
197-
type: 'ticker'
198-
sequence: 2349290585
199-
product_id: 'CGLD-USD'
200-
price: '5.415'
201-
best_bid: '5.4149'
202-
best_ask: '5.4150'
203-
time: '2021-10-13T07:05:00.028961Z'
204-
}
196+
type CoinbaseTicker =
197+
| {
198+
type: 'ticker'
199+
sequence: 2349290585
200+
product_id: 'CGLD-USD'
201+
price: '5.415'
202+
best_bid: '5.4149'
203+
best_ask: '5.4150'
204+
time: '2021-10-13T07:05:00.028961Z'
205+
best_bid_size: undefined
206+
best_ask_size: undefined
207+
}
208+
| {
209+
type: 'ticker'
210+
sequence: 50978628538
211+
product_id: 'BTC-USD'
212+
price: '17165.16'
213+
open_24h: '16437.94'
214+
volume_24h: '42492.05081975'
215+
low_24h: '16423.37'
216+
high_24h: '17259.37'
217+
volume_30d: '1093827.95195495'
218+
best_bid: '17165.15'
219+
best_bid_size: '0.61540890'
220+
best_ask: '17167.76'
221+
best_ask_size: '0.18528568'
222+
side: 'sell'
223+
time: '2022-12-01T00:00:00.122581Z'
224+
trade_id: 463751434
225+
last_size: '0.05'
226+
}

test/__snapshots__/mappers.test.ts.snap

+16
Original file line numberDiff line numberDiff line change
@@ -3463,6 +3463,22 @@ Array [
34633463
]
34643464
`;
34653465

3466+
exports[`mappers map coinbase messages 9`] = `
3467+
Array [
3468+
Object {
3469+
"askAmount": 0.18528568,
3470+
"askPrice": 17167.76,
3471+
"bidAmount": 0.6154089,
3472+
"bidPrice": 17165.15,
3473+
"exchange": "coinbase",
3474+
"localTimestamp": 2019-09-01T00:00:01.275Z,
3475+
"symbol": "BTC-USD",
3476+
"timestamp": 2022-12-01T00:00:00.122581Z,
3477+
"type": "book_ticker",
3478+
},
3479+
]
3480+
`;
3481+
34663482
exports[`mappers map coinflex messages 1`] = `Array []`;
34673483

34683484
exports[`mappers map coinflex messages 2`] = `Array []`;

test/mappers.test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -3945,6 +3945,25 @@ describe('mappers', () => {
39453945
time: '2021-04-01T00:00:01.618503Z',
39463946
trade_id: 151521557,
39473947
last_size: '0.05'
3948+
},
3949+
{
3950+
type: 'ticker',
3951+
sequence: 50978628538,
3952+
product_id: 'BTC-USD',
3953+
price: '17165.16',
3954+
open_24h: '16437.94',
3955+
volume_24h: '42492.05081975',
3956+
low_24h: '16423.37',
3957+
high_24h: '17259.37',
3958+
volume_30d: '1093827.95195495',
3959+
best_bid: '17165.15',
3960+
best_bid_size: '0.61540890',
3961+
best_ask: '17167.76',
3962+
best_ask_size: '0.18528568',
3963+
side: 'sell',
3964+
time: '2022-12-01T00:00:00.122581Z',
3965+
trade_id: 463751434,
3966+
last_size: '0.05'
39483967
}
39493968
]
39503969

0 commit comments

Comments
 (0)