From 0ec7d800f58be12d861afa64334197e9177ef7fe Mon Sep 17 00:00:00 2001 From: wphan Date: Wed, 31 May 2023 22:54:34 -0700 Subject: [PATCH] honor grouping and depth in get l2 --- package.json | 2 +- src/index.ts | 14 ++++++++++++-- yarn.lock | 8 ++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index e9a4e99..449b362 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "lib/index.js", "license": "Apache-2.0", "dependencies": { - "@drift-labs/sdk": "2.31.0-beta.4", + "@drift-labs/sdk": "2.31.0-beta.5", "@opentelemetry/api": "^1.1.0", "@opentelemetry/auto-instrumentations-node": "^0.31.1", "@opentelemetry/exporter-prometheus": "^0.31.0", diff --git a/src/index.ts b/src/index.ts index 46c0e6e..ab914ee 100644 --- a/src/index.ts +++ b/src/index.ts @@ -906,10 +906,17 @@ const main = async () => { const isSpot = isVariant(normedMarketType, 'spot'); + let adjustedDepth = depth ?? '10'; + if (grouping !== undefined) { + // If grouping is also supplied, we want the entire book depth. + // we will apply depth after grouping + adjustedDepth = '-1'; + } + const l2 = dlobSubscriber.getL2({ marketIndex: normedMarketIndex, marketType: normedMarketType, - depth: depth ? parseInt(depth as string) : 10, + depth: parseInt(adjustedDepth as string), includeVamm: `${includeVamm}`.toLowerCase() === 'true', fallbackL2Generators: isSpot ? [ @@ -922,6 +929,7 @@ const main = async () => { }); if (grouping) { + const finalDepth = depth ? parseInt(depth as string) : 10; if (isNaN(parseInt(grouping as string))) { res .status(400) @@ -930,7 +938,9 @@ const main = async () => { } const groupingBN = new BN(parseInt(grouping as string)); res.writeHead(200); - res.end(JSON.stringify(l2WithBNToStrings(groupL2(l2, groupingBN)))); + res.end( + JSON.stringify(l2WithBNToStrings(groupL2(l2, groupingBN, finalDepth))) + ); } else { // make the BNs into strings res.writeHead(200); diff --git a/yarn.lock b/yarn.lock index e76475f..283903f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -80,10 +80,10 @@ enabled "2.0.x" kuler "^2.0.0" -"@drift-labs/sdk@2.31.0-beta.4": - version "2.31.0-beta.4" - resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.31.0-beta.4.tgz#e03d7dc40078f9ccf63cb3899ea07994ef7a2b74" - integrity sha512-3tiNn6LTyUENNu+7TjLJvbPlWXDohRsONYAQOC4DVljXk8jUVFo0tLTyKXkZe9EJsMS+TE3WikIgf9jYJIGHjg== +"@drift-labs/sdk@2.31.0-beta.5": + version "2.31.0-beta.5" + resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.31.0-beta.5.tgz#d95092a5e3e689c2a05e95012cc93b86892f8285" + integrity sha512-WP1DAgo4gb03tMBUl3ApyeUxmctcLQuzGMjDhER5fPR+HbEi01P7s6bAwdrGlqINdlnqNm2uutxh3Re5VAkCqg== dependencies: "@coral-xyz/anchor" "0.26.0" "@ellipsis-labs/phoenix-sdk" "^1.4.2"