Skip to content

Commit 7edd9ba

Browse files
committed
fix: fix deribit casing for options that contain 'd' (decimal) symbol
1 parent d311b28 commit 7edd9ba

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

src/mappers/deribit.ts

+28-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
1-
import { asNumberIfValid, upperCaseSymbols } from '../handy'
1+
import { asNumberIfValid } from '../handy'
22
import { BookChange, BookTicker, DerivativeTicker, Liquidation, OptionSummary, Trade } from '../types'
33
import { Mapper, PendingTickerInfoHelper } from './mapper'
44

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

7+
function deribitCasing(symbols?: string[]) {
8+
if (symbols !== undefined) {
9+
return symbols.map((symbol) => {
10+
if (symbol.endsWith('-C') || symbol.endsWith('-P')) {
11+
const parts = symbol.split('-')
12+
if (parts[2] !== undefined && parts[2].toUpperCase().includes('D')) {
13+
parts[2] = parts[2].replace('D', 'd')
14+
return parts.join('-')
15+
} else {
16+
return symbol.toUpperCase()
17+
}
18+
} else {
19+
return symbol.toUpperCase()
20+
}
21+
})
22+
}
23+
24+
return
25+
}
26+
727
export const deribitTradesMapper: Mapper<'deribit', Trade> = {
828
canHandle(message: any) {
929
const channel = message.params !== undefined ? (message.params.channel as string | undefined) : undefined
@@ -15,7 +35,7 @@ export const deribitTradesMapper: Mapper<'deribit', Trade> = {
1535
},
1636

1737
getFilters(symbols?: string[]) {
18-
symbols = upperCaseSymbols(symbols)
38+
symbols = deribitCasing(symbols)
1939

2040
return [
2141
{
@@ -60,7 +80,7 @@ export const deribitBookChangeMapper: Mapper<'deribit', BookChange> = {
6080
},
6181

6282
getFilters(symbols?: string[]) {
63-
symbols = upperCaseSymbols(symbols)
83+
symbols = deribitCasing(symbols)
6484

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

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

106127
getFilters(symbols?: string[]) {
107-
symbols = upperCaseSymbols(symbols)
128+
symbols = deribitCasing(symbols)
108129

109130
return [
110131
{
@@ -133,7 +154,7 @@ export class DeribitDerivativeTickerMapper implements Mapper<'deribit', Derivati
133154

134155
export class DeribitOptionSummaryMapper implements Mapper<'deribit', OptionSummary> {
135156
getFilters(symbols?: string[]) {
136-
symbols = upperCaseSymbols(symbols)
157+
symbols = deribitCasing(symbols)
137158

138159
return [
139160
{
@@ -222,7 +243,7 @@ export const deribitLiquidationsMapper: Mapper<'deribit', Liquidation> = {
222243
},
223244

224245
getFilters(symbols?: string[]) {
225-
symbols = upperCaseSymbols(symbols)
246+
symbols = deribitCasing(symbols)
226247

227248
return [
228249
{
@@ -270,7 +291,7 @@ export const deribitBookTickerMapper: Mapper<'deribit', BookTicker> = {
270291
},
271292

272293
getFilters(symbols?: string[]) {
273-
symbols = upperCaseSymbols(symbols)
294+
symbols = deribitCasing(symbols)
274295

275296
return [
276297
{

0 commit comments

Comments
 (0)