Skip to content

Commit

Permalink
fix: fix deribit casing for options that contain 'd' (decimal) symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
thaaddeus committed Jun 19, 2024
1 parent d311b28 commit 7edd9ba
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/mappers/deribit.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
import { asNumberIfValid, upperCaseSymbols } from '../handy'
import { asNumberIfValid } from '../handy'
import { BookChange, BookTicker, DerivativeTicker, Liquidation, OptionSummary, Trade } from '../types'
import { Mapper, PendingTickerInfoHelper } from './mapper'

// https://docs.deribit.com/v2/#subscriptions

function deribitCasing(symbols?: string[]) {
if (symbols !== undefined) {
return symbols.map((symbol) => {
if (symbol.endsWith('-C') || symbol.endsWith('-P')) {
const parts = symbol.split('-')
if (parts[2] !== undefined && parts[2].toUpperCase().includes('D')) {
parts[2] = parts[2].replace('D', 'd')
return parts.join('-')
} else {
return symbol.toUpperCase()
}
} else {
return symbol.toUpperCase()
}
})
}

return
}

export const deribitTradesMapper: Mapper<'deribit', Trade> = {
canHandle(message: any) {
const channel = message.params !== undefined ? (message.params.channel as string | undefined) : undefined
Expand All @@ -15,7 +35,7 @@ export const deribitTradesMapper: Mapper<'deribit', Trade> = {
},

getFilters(symbols?: string[]) {
symbols = upperCaseSymbols(symbols)
symbols = deribitCasing(symbols)

return [
{
Expand Down Expand Up @@ -60,7 +80,7 @@ export const deribitBookChangeMapper: Mapper<'deribit', BookChange> = {
},

getFilters(symbols?: string[]) {
symbols = upperCaseSymbols(symbols)
symbols = deribitCasing(symbols)

return [
{
Expand All @@ -78,6 +98,7 @@ export const deribitBookChangeMapper: Mapper<'deribit', BookChange> = {
deribitBookChange.prev_change_id === undefined ||
deribitBookChange.prev_change_id === 0

console.log(JSON.stringify(message))
yield {
type: 'book_change',
symbol: deribitBookChange.instrument_name.toUpperCase(),
Expand All @@ -104,7 +125,7 @@ export class DeribitDerivativeTickerMapper implements Mapper<'deribit', Derivati
}

getFilters(symbols?: string[]) {
symbols = upperCaseSymbols(symbols)
symbols = deribitCasing(symbols)

return [
{
Expand Down Expand Up @@ -133,7 +154,7 @@ export class DeribitDerivativeTickerMapper implements Mapper<'deribit', Derivati

export class DeribitOptionSummaryMapper implements Mapper<'deribit', OptionSummary> {
getFilters(symbols?: string[]) {
symbols = upperCaseSymbols(symbols)
symbols = deribitCasing(symbols)

return [
{
Expand Down Expand Up @@ -222,7 +243,7 @@ export const deribitLiquidationsMapper: Mapper<'deribit', Liquidation> = {
},

getFilters(symbols?: string[]) {
symbols = upperCaseSymbols(symbols)
symbols = deribitCasing(symbols)

return [
{
Expand Down Expand Up @@ -270,7 +291,7 @@ export const deribitBookTickerMapper: Mapper<'deribit', BookTicker> = {
},

getFilters(symbols?: string[]) {
symbols = upperCaseSymbols(symbols)
symbols = deribitCasing(symbols)

return [
{
Expand Down

0 comments on commit 7edd9ba

Please sign in to comment.