Skip to content

Patch mobula state EA to work when only one exchange returns the funding rate #3904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gentle-horses-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/mobula-state-adapter': patch
---

When a specific exchange returns nil ignore its funding rate value
5 changes: 5 additions & 0 deletions packages/sources/mobula-state/src/transport/funding-rate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ export const wsTransport = new WebSocketTransport<WsTransportTypes>({
return
}

if (!value) {
// Dont add results when the value is null - one of the exchanges could be unavailable
return
}

const exchange = key.slice(0, -'FundingRate'.length).toLowerCase()
results.push(getFundingRateResult(exchange, queryDetails, value as FundingRateResponse))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ exports[`websocket funding rate endpoint have data should return success 1`] = `
}
`;

exports[`websocket funding rate endpoint have partial data return success 1`] = `
{
"data": {
"epochDuration": 14400,
"fundingRate": -0.00059603,
"fundingTimestamp": 1747368000,
},
"result": null,
"statusCode": 200,
"timestamps": {
"providerDataReceivedUnixMs": 4048,
"providerDataStreamEstablishedUnixMs": 4040,
},
}
`;

exports[`websocket funding rate endpoint no data should return failure 1`] = `
{
"error": {
Expand Down
12 changes: 12 additions & 0 deletions packages/sources/mobula-state/test/integration/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ describe('websocket', () => {
endpoint: 'funding-rate',
}

const dataFundingRateAergo = {
base: 'AERGO',
quote: '',
exchange: 'binance',
endpoint: 'funding-rate',
}

beforeAll(async () => {
oldEnv = JSON.parse(JSON.stringify(process.env))
process.env['WS_API_ENDPOINT'] = wsEndpoint
Expand Down Expand Up @@ -77,6 +84,11 @@ describe('websocket', () => {
expect(response.json()).toMatchSnapshot()
})

it('have partial data return success', async () => {
const response = await testAdapter.request(dataFundingRateAergo)
expect(response.json()).toMatchSnapshot()
})

it('no data should return failure', async () => {
const response = await testAdapter.request({
base: 'ETH',
Expand Down
16 changes: 16 additions & 0 deletions packages/sources/mobula-state/test/integration/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ export const mockWebsocketServer = (URL: string): MockWebsocketServer => {
queryDetails: { base: 'BTC', quote: null },
}),
)

socket.send(
JSON.stringify({
binanceFundingRate: {
symbol: 'AERGOUSDT',
fundingTime: 1747368000001,
fundingRate: -0.00059603,
marketPrice: '0.15456000',
epochDurationMs: 14400000,
fundingRateCap: 2,
fundingRateFloor: -2,
},
deribitFundingRate: null,
queryDetails: { base: 'AERGO', quote: null },
}),
)
})
})

Expand Down
Loading