Skip to content

Commit

Permalink
Merge pull request #304 from mithraiclabs/bugfix/puts-not-showing-up
Browse files Browse the repository at this point in the history
Fix contractSize logic so puts show up
  • Loading branch information
evanpipta authored May 7, 2021
2 parents bd6d39c + 7276900 commit 6fcbce8
Showing 1 changed file with 34 additions and 36 deletions.
70 changes: 34 additions & 36 deletions src/hooks/useOptionsChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,8 @@ const useOptionsChain = (): {
return
}

const callKeyPart = `${dateTimestamp}-${uAsset.tokenSymbol}-${
qAsset.tokenSymbol
}${contractSize ? `-${contractSize}` : ''}`
const putKeyPart = `${dateTimestamp}-${qAsset.tokenSymbol}-${
uAsset.tokenSymbol
}${contractSize ? `-${contractSize}` : ''}`
const callKeyPart = `${dateTimestamp}-${uAsset.tokenSymbol}-${qAsset.tokenSymbol}`
const putKeyPart = `${dateTimestamp}-${qAsset.tokenSymbol}-${uAsset.tokenSymbol}`

const callPutMap = (
k: string,
Expand Down Expand Up @@ -130,36 +126,38 @@ const useOptionsChain = (): {
return false
})

Array.from(sizes).forEach(async (size) => {
const call = matchingCalls.find((c) => c.size === size)
const put = matchingPuts.find(
(p) => p.quoteAmountPerContract.toString() === size,
)

const row = {
strike,
size,
call: call
? {
...callOrPutTemplate,
...call,
serumKey: `${call?.optionMintKey}-${call?.qAssetMint}`,
initialized: true,
}
: (callOrPutTemplate as OptionRow),
put: put
? {
...callOrPutTemplate,
...put,
serumKey: `${put?.optionMintKey}-${put?.uAssetMint}`,
initialized: true,
}
: (callOrPutTemplate as OptionRow),
key: `${callKeyPart}-${size}-${strike}`,
}

rows.push(row)
})
Array.from(sizes)
.filter((size) => size === `${contractSize}`)
.forEach(async (size) => {
const call = matchingCalls.find((c) => c.size === size)
const put = matchingPuts.find(
(p) => p.quoteAmountPerContract.toString() === size,
)

const row = {
strike,
size,
call: call
? {
...callOrPutTemplate,
...call,
serumKey: `${call?.optionMintKey}-${call?.qAssetMint}`,
initialized: true,
}
: (callOrPutTemplate as OptionRow),
put: put
? {
...callOrPutTemplate,
...put,
serumKey: `${put?.optionMintKey}-${put?.uAssetMint}`,
initialized: true,
}
: (callOrPutTemplate as OptionRow),
key: `${callKeyPart}-${size}-${strike}`,
}

rows.push(row)
})
})

rows.sort((a, b) => a.strike.minus(b.strike).toNumber())
Expand Down

0 comments on commit 6fcbce8

Please sign in to comment.