Skip to content

Commit 7230c63

Browse files
authored
Patch mobula state EA to work when only one exchange returns the funding rate (#3904)
* Ignore nil funding rate values * Changeset * Add test Trigger CI Trigger CI
1 parent 54ea54b commit 7230c63

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

.changeset/gentle-horses-applaud.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/mobula-state-adapter': patch
3+
---
4+
5+
When a specific exchange returns nil ignore its funding rate value

packages/sources/mobula-state/src/transport/funding-rate.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ export const wsTransport = new WebSocketTransport<WsTransportTypes>({
7575
return
7676
}
7777

78+
if (!value) {
79+
// Dont add results when the value is null - one of the exchanges could be unavailable
80+
return
81+
}
82+
7883
const exchange = key.slice(0, -'FundingRate'.length).toLowerCase()
7984
results.push(getFundingRateResult(exchange, queryDetails, value as FundingRateResponse))
8085
})

packages/sources/mobula-state/test/integration/__snapshots__/adapter.test.ts.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ exports[`websocket funding rate endpoint have data should return success 1`] = `
1616
}
1717
`;
1818

19+
exports[`websocket funding rate endpoint have partial data return success 1`] = `
20+
{
21+
"data": {
22+
"epochDuration": 14400,
23+
"fundingRate": -0.00059603,
24+
"fundingTimestamp": 1747368000,
25+
},
26+
"result": null,
27+
"statusCode": 200,
28+
"timestamps": {
29+
"providerDataReceivedUnixMs": 4048,
30+
"providerDataStreamEstablishedUnixMs": 4040,
31+
},
32+
}
33+
`;
34+
1935
exports[`websocket funding rate endpoint no data should return failure 1`] = `
2036
{
2137
"error": {

packages/sources/mobula-state/test/integration/adapter.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ describe('websocket', () => {
2828
endpoint: 'funding-rate',
2929
}
3030

31+
const dataFundingRateAergo = {
32+
base: 'AERGO',
33+
quote: '',
34+
exchange: 'binance',
35+
endpoint: 'funding-rate',
36+
}
37+
3138
beforeAll(async () => {
3239
oldEnv = JSON.parse(JSON.stringify(process.env))
3340
process.env['WS_API_ENDPOINT'] = wsEndpoint
@@ -77,6 +84,11 @@ describe('websocket', () => {
7784
expect(response.json()).toMatchSnapshot()
7885
})
7986

87+
it('have partial data return success', async () => {
88+
const response = await testAdapter.request(dataFundingRateAergo)
89+
expect(response.json()).toMatchSnapshot()
90+
})
91+
8092
it('no data should return failure', async () => {
8193
const response = await testAdapter.request({
8294
base: 'ETH',

packages/sources/mobula-state/test/integration/fixtures.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ export const mockWebsocketServer = (URL: string): MockWebsocketServer => {
3535
queryDetails: { base: 'BTC', quote: null },
3636
}),
3737
)
38+
39+
socket.send(
40+
JSON.stringify({
41+
binanceFundingRate: {
42+
symbol: 'AERGOUSDT',
43+
fundingTime: 1747368000001,
44+
fundingRate: -0.00059603,
45+
marketPrice: '0.15456000',
46+
epochDurationMs: 14400000,
47+
fundingRateCap: 2,
48+
fundingRateFloor: -2,
49+
},
50+
deribitFundingRate: null,
51+
queryDetails: { base: 'AERGO', quote: null },
52+
}),
53+
)
3854
})
3955
})
4056

0 commit comments

Comments
 (0)