From a654483339782bc7cd3edda28e5a8b4b41246ed4 Mon Sep 17 00:00:00 2001 From: Adam Fraser Date: Thu, 1 Aug 2024 19:55:06 -0400 Subject: [PATCH 1/4] Remove unhelpful logs --- .../redis/src/caches/orderbook-levels-cache.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/indexer/packages/redis/src/caches/orderbook-levels-cache.ts b/indexer/packages/redis/src/caches/orderbook-levels-cache.ts index c28f32ff6f..bcabbaa152 100644 --- a/indexer/packages/redis/src/caches/orderbook-levels-cache.ts +++ b/indexer/packages/redis/src/caches/orderbook-levels-cache.ts @@ -542,11 +542,6 @@ export async function getOrderBookMidPrice( }); if (levels.bids.length === 0 || levels.asks.length === 0) { - const message: string = `Orderbook bid length: ${levels.bids.length}, ask length: ${levels.asks.length}. Expected > 0`; - logger.error({ - at: 'orderbook-levels-cache#getOrderBookMidPrice', - message, - }); return undefined; } @@ -554,11 +549,6 @@ export async function getOrderBookMidPrice( const bestBid = Number(levels.bids[0].humanPrice); if (bestAsk === undefined || bestBid === undefined) { - const message: string = `Orderbook bid or ask failed to parse to Number, bid: ${levels.bids[0]}, ask: ${levels.asks[0]}`; - logger.error({ - at: 'orderbook-levels-cache#getOrderBookMidPrice', - message, - }); return undefined; } From 8308ba2845fd36fa51c542975b17d12a2ddfb6d1 Mon Sep 17 00:00:00 2001 From: Adam Fraser Date: Thu, 1 Aug 2024 19:56:34 -0400 Subject: [PATCH 2/4] Use Big library to handle numbers with lots of decimals --- .../caches/orderbook-levels-cache.test.ts | 45 ++++++++++++++++++- .../src/caches/orderbook-levels-cache.ts | 9 ++-- .../ender/src/lib/candles-generator.ts | 2 +- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/indexer/packages/redis/__tests__/caches/orderbook-levels-cache.test.ts b/indexer/packages/redis/__tests__/caches/orderbook-levels-cache.test.ts index 6bb08e3497..603e332865 100644 --- a/indexer/packages/redis/__tests__/caches/orderbook-levels-cache.test.ts +++ b/indexer/packages/redis/__tests__/caches/orderbook-levels-cache.test.ts @@ -744,9 +744,52 @@ describe('orderbookLevelsCache', () => { ]); const midPrice = await getOrderBookMidPrice(ticker, client); - expect(midPrice).toEqual(45350); + expect(midPrice).toEqual('45350'); }); + }); + it('returns the correct mid price for very small numbers', async () => { + await Promise.all([ + updatePriceLevel({ + ticker, + side: OrderSide.SELL, + humanPrice: '0.000000002346', + sizeDeltaInQuantums: '2000', + client, + }), + updatePriceLevel({ + ticker, + side: OrderSide.BUY, + humanPrice: '0.000000002344', + sizeDeltaInQuantums: '2000', + client, + }), + ]); + + const midPrice = await getOrderBookMidPrice(ticker, client); + expect(midPrice).toEqual('0.000000002345'); + }); + + it('returns the approprite amount of decimal precision', async () => { + await Promise.all([ + updatePriceLevel({ + ticker, + side: OrderSide.SELL, + humanPrice: '1.02', + sizeDeltaInQuantums: '2000', + client, + }), + updatePriceLevel({ + ticker, + side: OrderSide.BUY, + humanPrice: '1.01', + sizeDeltaInQuantums: '2000', + client, + }), + ]); + + const midPrice = await getOrderBookMidPrice(ticker, client); + expect(midPrice).toEqual('1.015'); }); it('returns undefined if there are no bids or asks', async () => { diff --git a/indexer/packages/redis/src/caches/orderbook-levels-cache.ts b/indexer/packages/redis/src/caches/orderbook-levels-cache.ts index bcabbaa152..cb75fda584 100644 --- a/indexer/packages/redis/src/caches/orderbook-levels-cache.ts +++ b/indexer/packages/redis/src/caches/orderbook-levels-cache.ts @@ -533,7 +533,7 @@ function convertToPriceLevels( export async function getOrderBookMidPrice( ticker: string, client: RedisClient, -): Promise { +): Promise { const levels = await getOrderBookLevels(ticker, client, { removeZeros: true, sortSides: true, @@ -545,12 +545,11 @@ export async function getOrderBookMidPrice( return undefined; } - const bestAsk = Number(levels.asks[0].humanPrice); - const bestBid = Number(levels.bids[0].humanPrice); + const bestAsk = Big(levels.asks[0].humanPrice); + const bestBid = Big(levels.bids[0].humanPrice); if (bestAsk === undefined || bestBid === undefined) { return undefined; } - - return bestBid + (bestAsk - bestBid) / 2; + return bestBid.plus(bestAsk).div(2).toFixed(); } diff --git a/indexer/services/ender/src/lib/candles-generator.ts b/indexer/services/ender/src/lib/candles-generator.ts index 034095e378..00fd1ab598 100644 --- a/indexer/services/ender/src/lib/candles-generator.ts +++ b/indexer/services/ender/src/lib/candles-generator.ts @@ -541,7 +541,7 @@ export async function getOrderbookMidPriceMap(): Promise<{ [ticker: string]: Ord perpetualMarket.ticker, redisClient, ); - return { [perpetualMarket.ticker]: price === undefined ? undefined : String(price) }; + return { [perpetualMarket.ticker]: price === undefined ? undefined : price }; }); const pricesArray = await Promise.all(promises); From c418b03730b130ecf97d735890ff7bb456d2d818 Mon Sep 17 00:00:00 2001 From: Adam Fraser Date: Thu, 1 Aug 2024 20:07:37 -0400 Subject: [PATCH 3/4] Modify deploy flow --- .../indexer-build-and-push-dev-staging.yml | 42 +------------------ 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/.github/workflows/indexer-build-and-push-dev-staging.yml b/.github/workflows/indexer-build-and-push-dev-staging.yml index 5a98b72552..0b066892f5 100644 --- a/.github/workflows/indexer-build-and-push-dev-staging.yml +++ b/.github/workflows/indexer-build-and-push-dev-staging.yml @@ -6,17 +6,9 @@ on: # yamllint disable-line rule:truthy - main - 'release/indexer/v[0-9]+.[0-9]+.x' # e.g. release/indexer/v0.1.x - 'release/indexer/v[0-9]+.x' # e.g. release/indexer/v1.x - # TODO(DEC-837): Customize github build and push to ECR by service with paths + - 'adam/ct-1059-address-issue-with-orderbookmidprice-calculation' jobs: - # Build and push to dev - call-build-and-push-ecs-services-dev: - name: (Dev) Build and Push ECS Services - uses: ./.github/workflows/indexer-build-and-push-all-ecr-images.yml - with: - ENVIRONMENT: dev - secrets: inherit - # Build and push to dev2 call-build-and-push-ecs-services-dev2: name: (Dev2) Build and Push ECS Services @@ -24,35 +16,3 @@ jobs: with: ENVIRONMENT: dev2 secrets: inherit - - # Build and push to dev3 - call-build-and-push-ecs-services-dev3: - name: (Dev3) Build and Push ECS Services - uses: ./.github/workflows/indexer-build-and-push-all-ecr-images.yml - with: - ENVIRONMENT: dev3 - secrets: inherit - - # Build and push to dev4 - call-build-and-push-ecs-services-dev4: - name: (Dev4) Build and Push ECS Services - uses: ./.github/workflows/indexer-build-and-push-all-ecr-images.yml - with: - ENVIRONMENT: dev4 - secrets: inherit - - # Build and push to dev5 - call-build-and-push-ecs-services-dev5: - name: (Dev5) Build and Push ECS Services - uses: ./.github/workflows/indexer-build-and-push-all-ecr-images.yml - with: - ENVIRONMENT: dev5 - secrets: inherit - - # Build and push to staging - call-build-and-push-ecs-services-staging: - name: (Staging) Build and Push ECS Services - uses: ./.github/workflows/indexer-build-and-push-all-ecr-images.yml - with: - ENVIRONMENT: staging - secrets: inherit From c407064535435bfef8790c24a00a621de3e0292b Mon Sep 17 00:00:00 2001 From: Adam Fraser Date: Thu, 1 Aug 2024 21:00:33 -0400 Subject: [PATCH 4/4] Revert deploy changes --- .../indexer-build-and-push-dev-staging.yml | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/.github/workflows/indexer-build-and-push-dev-staging.yml b/.github/workflows/indexer-build-and-push-dev-staging.yml index 0b066892f5..5a98b72552 100644 --- a/.github/workflows/indexer-build-and-push-dev-staging.yml +++ b/.github/workflows/indexer-build-and-push-dev-staging.yml @@ -6,9 +6,17 @@ on: # yamllint disable-line rule:truthy - main - 'release/indexer/v[0-9]+.[0-9]+.x' # e.g. release/indexer/v0.1.x - 'release/indexer/v[0-9]+.x' # e.g. release/indexer/v1.x - - 'adam/ct-1059-address-issue-with-orderbookmidprice-calculation' + # TODO(DEC-837): Customize github build and push to ECR by service with paths jobs: + # Build and push to dev + call-build-and-push-ecs-services-dev: + name: (Dev) Build and Push ECS Services + uses: ./.github/workflows/indexer-build-and-push-all-ecr-images.yml + with: + ENVIRONMENT: dev + secrets: inherit + # Build and push to dev2 call-build-and-push-ecs-services-dev2: name: (Dev2) Build and Push ECS Services @@ -16,3 +24,35 @@ jobs: with: ENVIRONMENT: dev2 secrets: inherit + + # Build and push to dev3 + call-build-and-push-ecs-services-dev3: + name: (Dev3) Build and Push ECS Services + uses: ./.github/workflows/indexer-build-and-push-all-ecr-images.yml + with: + ENVIRONMENT: dev3 + secrets: inherit + + # Build and push to dev4 + call-build-and-push-ecs-services-dev4: + name: (Dev4) Build and Push ECS Services + uses: ./.github/workflows/indexer-build-and-push-all-ecr-images.yml + with: + ENVIRONMENT: dev4 + secrets: inherit + + # Build and push to dev5 + call-build-and-push-ecs-services-dev5: + name: (Dev5) Build and Push ECS Services + uses: ./.github/workflows/indexer-build-and-push-all-ecr-images.yml + with: + ENVIRONMENT: dev5 + secrets: inherit + + # Build and push to staging + call-build-and-push-ecs-services-staging: + name: (Staging) Build and Push ECS Services + uses: ./.github/workflows/indexer-build-and-push-all-ecr-images.yml + with: + ENVIRONMENT: staging + secrets: inherit