-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adam/ct 1059 address issue with orderbookmidprice calculation #2012
Adam/ct 1059 address issue with orderbookmidprice calculation #2012
Conversation
WalkthroughThe recent changes enhance the precision and formatting of financial calculations within the order book management system. Notably, the return type of the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant OrderBook
participant RedisClient
User->>OrderBook: Request Mid Price
OrderBook->>RedisClient: Fetch Prices
RedisClient-->>OrderBook: Return Prices
OrderBook->>OrderBook: Calculate Mid Price
OrderBook-->>User: Return Mid Price as String
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (1)
indexer/services/ender/src/lib/candles-generator.ts (1)
544-544
: Ensure downstream processing handles the new format.The return statement now returns the price directly as a number instead of a string. Verify that all downstream processing, especially the test cases in
indexer/services/ender/__tests__/lib/candles-generator.test.ts
, can handle this change.
indexer/services/ender/src/lib/candles-generator.ts
: Ensure that the downstream processing oforderbookMidPriceMap
correctly handles prices as numbers.indexer/services/ender/__tests__/lib/candles-generator.test.ts
: Update the test cases to expect prices as numbers instead of strings.Analysis chain
Ensure downstream processing handles the new format.
The return statement now returns the price directly without converting it to a string. Verify that all downstream processing can handle this change.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all downstream processing of `getOrderbookMidPriceMap` handles the new format. # Test: Search for the function usage. Expect: Ensure all occurrences handle the new format. rg --type javascript -A 5 $'getOrderbookMidPriceMap'Length of output: 86
Script:
#!/bin/bash # Description: Verify all downstream processing of `getOrderbookMidPriceMap` handles the new format. # Test: Search for the function usage. Expect: Ensure all occurrences handle the new format. rg -A 5 'getOrderbookMidPriceMap'Length of output: 2813
Script:
#!/bin/bash # Description: Extract and review the relevant code sections from `candles-generator.ts` and `candles-generator.test.ts` to verify downstream processing. # Extract the relevant code section from `candles-generator.ts` rg -A 10 'const orderbookMidPriceMap = await getOrderbookMidPriceMap();' indexer/services/ender/src/lib/candles-generator.ts # Extract the relevant test cases from `candles-generator.test.ts` rg -A 10 'const map = await getOrderbookMidPriceMap();' indexer/services/ender/__tests__/lib/candles-generator.test.tsLength of output: 247
Script:
#!/bin/bash # Description: Extract and review the relevant code sections from `candles-generator.ts` and `candles-generator.test.ts` to verify downstream processing. # Extract the relevant code section from `candles-generator.ts` rg 'const orderbookMidPriceMap = await getOrderbookMidPriceMap();' -A 20 indexer/services/ender/src/lib/candles-generator.ts # Extract the relevant test cases from `candles-generator.test.ts` rg 'const map = await getOrderbookMidPriceMap();' -A 20 indexer/services/ender/__tests__/lib/candles-generator.test.tsLength of output: 247
Script:
#!/bin/bash # Description: Verify the presence and usage of `getOrderbookMidPriceMap` function across the entire repository. # Search for the function definition with increased context rg 'async function getOrderbookMidPriceMap' -A 20 # Search for the function usage with increased context rg 'getOrderbookMidPriceMap()' -A 20Length of output: 9367
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- indexer/packages/redis/tests/caches/orderbook-levels-cache.test.ts (1 hunks)
- indexer/packages/redis/src/caches/orderbook-levels-cache.ts (2 hunks)
- indexer/services/ender/src/lib/candles-generator.ts (1 hunks)
Additional comments not posted (7)
indexer/packages/redis/src/caches/orderbook-levels-cache.ts (3)
536-536
: Update the function signature in documentation.The function signature has changed to return a
Promise<string | undefined>
. Ensure that all relevant documentation reflects this change.
548-549
: Use theBig
library for precise arithmetic operations.The use of the
Big
library for handlinghumanPrice
values enhances precision in arithmetic operations.
554-554
: Return the mid-price as a string.The final return statement now returns a string formatted result using
toFixed()
, reflecting a focus on precision and format.indexer/packages/redis/__tests__/caches/orderbook-levels-cache.test.ts (4)
747-747
: Update test case to expect a string mid price.The expected value has been adjusted to a string type, reflecting the updated return type of the
getOrderBookMidPrice
function.
751-771
: Add test case for very small numerical values.The new test case verifies the correct calculation of the mid price for very small numerical values, ensuring accurate computation.
773-792
: Add test case for decimal precision.The new test case checks that the mid price calculation maintains appropriate decimal precision, ensuring precision in financial calculations.
793-795
: Add test case for undefined mid price.The test case verifies that the function returns undefined if there are no bids or asks, ensuring correct handling of such cases.
@Mergifyio backport release/indexer/v5.x |
✅ Backports have been created
|
(cherry picked from commit 9385c5a)
#2012) (#2015) Co-authored-by: Adam Fraser <[email protected]>
Changelist
Fixes an issue when calculating orderbookMidPrice that would occur if the prices were numbers with lots of decimal places.
Test Plan
Summary by CodeRabbit
New Features
Bug Fixes
Documentation