Skip to content

Commit

Permalink
improvement: handle case when okex swap does not provide funding rate…
Browse files Browse the repository at this point in the history
… info
  • Loading branch information
thaaddeus committed Dec 30, 2021
1 parent 95902a7 commit ff1c4a3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/mappers/okex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,12 @@ export class OkexV5DerivativeTickerMapper implements Mapper<'okex-futures' | 'ok
if (message.arg.channel === 'funding-rate') {
const fundingRateMessage = dataMessage as OkexV5FundingRateMessage['data'][0]

pendingTickerInfo.updateFundingRate(Number(fundingRateMessage.fundingRate))
//
pendingTickerInfo.updateFundingTimestamp(new Date(Number(fundingRateMessage.fundingTime)))
if (fundingRateMessage.fundingRate !== undefined) {
pendingTickerInfo.updateFundingRate(Number(fundingRateMessage.fundingRate))
}
if (fundingRateMessage.fundingTime !== undefined) {
pendingTickerInfo.updateFundingTimestamp(new Date(Number(fundingRateMessage.fundingTime)))
}

if (fundingRateMessage.nextFundingRate !== undefined) {
pendingTickerInfo.updatePredictedFundingRate(Number(fundingRateMessage.nextFundingRate))
Expand Down Expand Up @@ -544,7 +547,9 @@ type OkexV5IndexTickerMessage = {

type OkexV5FundingRateMessage = {
arg: { channel: 'funding-rate'; instId: string }
data: [{ fundingRate: '0.00048105'; fundingTime: '1640131200000'; instId: string; instType: 'SWAP'; nextFundingRate: '0.00114' }]
data: [
{ fundingRate: '0.00048105' | undefined; fundingTime: '1640131200000'; instId: string; instType: 'SWAP'; nextFundingRate: '0.00114' }
]
}

type OkexV5LiquidationMessage = {
Expand Down
19 changes: 19 additions & 0 deletions test/__snapshots__/mappers.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7787,6 +7787,25 @@ Array [
]
`;

exports[`mappers map okex-swap messages 21`] = `
Array [
Object {
"exchange": "okex-swap",
"fundingRate": undefined,
"fundingTimestamp": 2021-12-30T08:00:00.000Z,
"indexPrice": undefined,
"lastPrice": undefined,
"localTimestamp": 2021-12-23T00:00:00.000Z,
"markPrice": undefined,
"openInterest": undefined,
"predictedFundingRate": 0.0003,
"symbol": "SOS-USDT-SWAP",
"timestamp": 2021-12-23T00:00:00.000Z,
"type": "derivative_ticker",
},
]
`;

exports[`mappers map phemex messages 1`] = `
Array [
Object {
Expand Down
4 changes: 4 additions & 0 deletions test/mappers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,10 @@ describe('mappers', () => {
{
arg: { channel: 'open-interest', instId: 'WNCG-USDT-SWAP' },
data: [{ instId: 'WNCG-USDT-SWAP', instType: 'SWAP', oi: '644195', oiCcy: '644195', ts: '1640131258756' }]
},
{
arg: { channel: 'funding-rate', instId: 'SOS-USDT-SWAP' },
data: [{ fundingTime: '1640851200000', instId: 'SOS-USDT-SWAP', instType: 'SWAP', nextFundingRate: '0.0003' }]
}
]
for (const message of okexSwapV5Messages) {
Expand Down

0 comments on commit ff1c4a3

Please sign in to comment.