Skip to content

Commit

Permalink
improvement: handle edge case for okex-options summary mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
thaaddeus committed Dec 27, 2021
1 parent e12eae0 commit b4e768a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/mappers/okex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ export class OkexV5OptionSummaryMapper implements Mapper<'okex-options', OptionS
for (const dataMessage of message.data) {
const indexTickerMessage = dataMessage as OkexV5IndexTickerMessage['data'][0]

const lastIndexPrice = Number(indexTickerMessage.idxPx)
if (lastIndexPrice > 0) {
const lastIndexPrice = asNumberIfValid(indexTickerMessage.idxPx)
if (lastIndexPrice !== undefined) {
this._indexPrices.set(indexTickerMessage.instId, lastIndexPrice)
}
}
Expand All @@ -366,8 +366,8 @@ export class OkexV5OptionSummaryMapper implements Mapper<'okex-options', OptionS
for (const dataMessage of message.data) {
const openInterestMessage = dataMessage as OkexV5OpenInterestMessage['data'][0]

const openInterestValue = Number(openInterestMessage.oi)
if (openInterestValue > 0) {
const openInterestValue = asNumberIfValid(openInterestMessage.oi)
if (openInterestValue !== undefined) {
this._openInterests.set(openInterestMessage.instId, openInterestValue)
}
}
Expand All @@ -378,8 +378,8 @@ export class OkexV5OptionSummaryMapper implements Mapper<'okex-options', OptionS
for (const dataMessage of message.data) {
const markPriceMessage = dataMessage as OkexV5MarkPriceMessage['data'][0]

const markPrice = Number(markPriceMessage.markPx)
if (markPrice > 0) {
const markPrice = asNumberIfValid(markPriceMessage.markPx)
if (markPrice !== undefined) {
this._markPrices.set(markPriceMessage.instId, markPrice)
}
}
Expand Down
32 changes: 32 additions & 0 deletions test/__snapshots__/mappers.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7368,6 +7368,38 @@ Array [
]
`;

exports[`mappers map okex-options messages 30`] = `
Array [
Object {
"bestAskAmount": undefined,
"bestAskIV": 5,
"bestAskPrice": undefined,
"bestBidAmount": undefined,
"bestBidIV": undefined,
"bestBidPrice": undefined,
"delta": -1.0127414362,
"exchange": "okex-options",
"expirationDate": 2021-12-27T08:00:00.000Z,
"gamma": 5.1005664647,
"lastPrice": undefined,
"localTimestamp": 2021-12-23T00:00:00.000Z,
"markIV": 1.30710927,
"markPrice": undefined,
"openInterest": undefined,
"optionType": "put",
"rho": undefined,
"strikePrice": 4150,
"symbol": "ETH-USD-211227-4150-P",
"theta": -0.0002998793,
"timestamp": 2021-12-27T07:00:00.390Z,
"type": "option_summary",
"underlyingIndex": "ETH-USD",
"underlyingPrice": 3814.05,
"vega": 0.0000045884,
},
]
`;

exports[`mappers map okex-swap messages 1`] = `
Array [
Object {
Expand Down
24 changes: 24 additions & 0 deletions test/mappers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2002,6 +2002,30 @@ describe('mappers', () => {
{
arg: { channel: 'trades', instId: 'BTC-USD-211224-56000-C' },
data: [{ instId: 'BTC-USD-211224-56000-C', tradeId: '376', px: '0.0005', sz: '1', side: 'buy', ts: '1640001607045' }]
},
{
arg: { channel: 'opt-summary', uly: 'ETH-USD' },
data: [
{
instType: 'OPTION',
instId: 'ETH-USD-211227-4150-P',
uly: 'ETH-USD',
delta: '-1.0127414362',
gamma: '5.1005664647',
vega: '0.0000045884',
theta: '-0.0002998793',
lever: '0',
markVol: '1.30710927',
bidVol: '',
askVol: '5',
realVol: '',
deltaBS: '-0.9826286266',
gammaBS: '0.000755397',
thetaBS: '-43.7640140001',
vegaBS: '0.0186786885',
ts: '1640588400390'
}
]
}
]

Expand Down

0 comments on commit b4e768a

Please sign in to comment.