Skip to content

Commit 581dacf

Browse files
Fix message format bug in finage (#4396)
Co-authored-by: app-token-issuer-data-feeds[bot] <134377064+app-token-issuer-data-feeds[bot]@users.noreply.github.com>
1 parent 8ff178e commit 581dacf

File tree

5 files changed

+50
-8
lines changed

5 files changed

+50
-8
lines changed

.changeset/real-tigers-hammer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/finage-adapter': minor
3+
---
4+
5+
Fix a message format bug

packages/sources/finage/src/transport/stock-quotes.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ const logger = makeLogger('StockQuotes')
66

77
export interface StockQuoteMessage {
88
s: string // Symbol
9-
a: string // ask_price
10-
ap: string // ask_price fallback
11-
as: string // ask_volume
12-
b: string // bid_price
13-
bp: string // bid_price fallback
14-
bs: string // bid_volume
9+
a: string | number // ask_price
10+
ap: string | number // ask_price fallback
11+
as: string | number // ask_volume
12+
b: string | number // bid_price
13+
bp: string | number // bid_price fallback
14+
bs: string | number // bid_volume
1515
t: number // providerIndicatedTime
1616
status_code: number
1717
message: string
@@ -23,7 +23,7 @@ type WsTransportTypes = BaseEndpointTypes & {
2323
}
2424
}
2525

26-
const isValidNumber = (field: string) => field && field.length > 0 && !isNaN(Number(field))
26+
const isValidNumber = (field: string | number) => field != null && !isNaN(Number(field))
2727

2828
export const transport = new WebSocketTransport<WsTransportTypes>({
2929
url: (context) => {

packages/sources/finage/test/integration/__snapshots__/adapter-stock-quote.test.ts.snap

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,22 @@ exports[`stock quotes websocket stock quotes endpoint should return success 1`]
7575
},
7676
}
7777
`;
78+
79+
exports[`stock quotes websocket stock quotes endpoint should return success for number messages 1`] = `
80+
{
81+
"data": {
82+
"ask_price": 5,
83+
"ask_volume": 6,
84+
"bid_price": 7,
85+
"bid_volume": 8,
86+
"mid_price": 6,
87+
},
88+
"result": null,
89+
"statusCode": 200,
90+
"timestamps": {
91+
"providerDataReceivedUnixMs": 1018,
92+
"providerDataStreamEstablishedUnixMs": 1010,
93+
"providerIndicatedTimeUnixMs": 9,
94+
},
95+
}
96+
`;

packages/sources/finage/test/integration/adapter-stock-quote.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ describe('stock quotes websocket', () => {
1717
endpoint: 'stock_quotes',
1818
base: 'AAPL',
1919
}
20+
const dataNumber = {
21+
endpoint: 'stock_quotes',
22+
base: 'AAPL_NUMBER',
23+
}
2024
const fallBackData = {
2125
endpoint: 'stock_quotes',
2226
base: 'FALLBACK',
@@ -40,8 +44,9 @@ describe('stock quotes websocket', () => {
4044

4145
// Send initial request to start background execute and wait for cache to be filled with results
4246
await testAdapter.request(data)
47+
await testAdapter.request(dataNumber)
4348
await testAdapter.request(fallBackData)
44-
await testAdapter.waitForCache(4)
49+
await testAdapter.waitForCache(5)
4550
})
4651

4752
afterAll(async () => {
@@ -57,6 +62,11 @@ describe('stock quotes websocket', () => {
5762
expect(response.json()).toMatchSnapshot()
5863
})
5964

65+
it('should return success for number messages', async () => {
66+
const response = await testAdapter.request(dataNumber)
67+
expect(response.json()).toMatchSnapshot()
68+
})
69+
6070
it('missing a and b fields should fallback', async () => {
6171
const response = await testAdapter.request(fallBackData)
6272
expect(response.json()).toMatchSnapshot()

packages/sources/finage/test/integration/fixtures.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ export const mockStockQuotesWebSocketServer = (URL: string): MockWebsocketServer
248248
bs: '8',
249249
t: 9,
250250
},
251+
{
252+
s: 'AAPL_NUMBER',
253+
a: 5,
254+
as: 6,
255+
b: 7,
256+
bs: 8,
257+
t: 9,
258+
},
251259
{
252260
s: 'FALLBACK',
253261
ap: '10',

0 commit comments

Comments
 (0)