Skip to content
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

Revert "Add Orderbook Mid Price Cache (#2289)" #2333

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

adamfraser
Copy link
Contributor

@adamfraser adamfraser commented Sep 24, 2024

This reverts commit 637c237.

Summary by CodeRabbit

  • Bug Fixes

    • Removed outdated caching functionality for order book mid prices, streamlining operations.
  • New Features

    • Introduced a new helper function for managing price levels in trading pairs.
  • Chores

    • Simplified configuration schema by removing unnecessary entries related to order book mid prices.
    • Eliminated related import statements and logic from the application startup process.
  • Tests

    • Updated tests to reflect changes in price management and removed tests for deleted caching functionality.

Copy link
Contributor

coderabbitai bot commented Sep 24, 2024

Walkthrough

The changes involve the removal of the orderbook-mid-prices-cache module and its associated tests, Lua scripts, and configurations from the codebase. This includes the deletion of functions for setting and retrieving mid prices in Redis, as well as the removal of related caching tasks and their configurations. Additionally, the codebase has been updated to replace references to the removed cache with a new caching mechanism.

Changes

File Path Change Summary
indexer/packages/redis/__tests__/caches/... Deleted unit tests for orderbook-mid-prices-cache, including tests for setting and getting prices.
indexer/packages/redis/src/caches/... Removed orderbook-mid-prices-cache.ts, including setPrice and getMedianPrice functions.
indexer/packages/redis/src/caches/scripts.ts Deleted Lua scripts addMarketPriceScript and getMarketMedianScript.
indexer/packages/redis/src/index.ts Removed export for OrderbookMidPricesCache.
indexer/packages/redis/src/scripts/... Deleted Lua scripts for managing market prices and calculating median prices.
indexer/services/ender/__tests__/lib/... Updated tests to use a new helper function for setting price levels, replacing direct cache calls.
indexer/services/ender/src/lib/... Changed import and method call to retrieve mid prices from OrderbookLevelsCache.
indexer/services/roundtable/__tests__/tasks/... Deleted tests for cache-orderbook-mid-prices task.
indexer/services/roundtable/src/config.ts Removed configuration entries related to caching order book mid prices.
indexer/services/roundtable/src/index.ts Eliminated logic for starting the cacheOrderbookMidPrices task.
indexer/services/roundtable/src/tasks/... Deleted the cache-orderbook-mid-prices.ts file, which updated the mid prices in the cache.

Possibly related PRs

  • Add Orderbook Mid Price Cache #2289: Introduces a caching mechanism for orderbook mid prices, directly relating to the functionality of the orderbook-mid-prices-cache module that was modified in the main PR.

Suggested reviewers

  • dydxwill

🐰 In the code where prices once danced,
A cache now gone, a new chance enhanced.
With tests and scripts all swept away,
A fresh start blooms, brightening the day!
Hopping along to new paths we tread,
In the world of code, new stories are spread! 🌼


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@adamfraser adamfraser marked this pull request as ready for review September 24, 2024 17:57
@adamfraser adamfraser requested a review from a team as a code owner September 24, 2024 17:57
@adamfraser adamfraser merged commit 1a33334 into main Sep 24, 2024
15 of 16 checks passed
@adamfraser adamfraser deleted the adam/revert-orderbook-cache branch September 24, 2024 18:03
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range and nitpick comments (2)
indexer/services/ender/__tests__/lib/candles-generator.test.ts (2)

430-432: LGTM: Dynamic price level updates in parameterized test.

The test now uses dynamic values to set buy and sell prices, allowing for more flexible testing of various scenarios. This approach enhances the test's ability to cover different market conditions.

Consider adding a test case with a larger spread between buy and sell prices to ensure the system handles extreme market conditions correctly. For example:

it('handles large price spreads correctly', async () => {
  const largeMidPriceSpread = 1000;
  await updatePriceLevel('BTC-USD', String(10000 + largeMidPriceSpread), OrderSide.SELL);
  await updatePriceLevel('BTC-USD', String(10000 - largeMidPriceSpread), OrderSide.BUY);
  // ... rest of the test
});

663-678: LGTM: Comprehensive test for orderbook price map creation.

The test now uses updatePriceLevel to set price levels for multiple markets, providing a more comprehensive check of the orderbook price map creation. The expected result correctly includes undefined values for markets without set price levels.

Consider adding a test case for markets with only one side (buy or sell) set to ensure the system handles incomplete orderbooks correctly. For example:

await updatePriceLevel('LINK-USD', '10000', OrderSide.BUY);
// No sell price set for LINK-USD

expect(map).toEqual({
  // ... other markets
  'LINK-USD': undefined, // or however your system handles this case
});
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c34d56d and d0ef194.

Files selected for processing (12)
  • indexer/packages/redis/tests/caches/orderbook-mid-prices-cache.test.ts (0 hunks)
  • indexer/packages/redis/src/caches/orderbook-mid-prices-cache.ts (0 hunks)
  • indexer/packages/redis/src/caches/scripts.ts (0 hunks)
  • indexer/packages/redis/src/index.ts (0 hunks)
  • indexer/packages/redis/src/scripts/add_market_price.lua (0 hunks)
  • indexer/packages/redis/src/scripts/get_market_median_price.lua (0 hunks)
  • indexer/services/ender/tests/lib/candles-generator.test.ts (8 hunks)
  • indexer/services/ender/src/lib/candles-generator.ts (2 hunks)
  • indexer/services/roundtable/tests/tasks/cache-orderbook-mid-prices.test.ts (0 hunks)
  • indexer/services/roundtable/src/config.ts (0 hunks)
  • indexer/services/roundtable/src/index.ts (0 hunks)
  • indexer/services/roundtable/src/tasks/cache-orderbook-mid-prices.ts (0 hunks)
Files not reviewed due to no reviewable changes (10)
  • indexer/packages/redis/tests/caches/orderbook-mid-prices-cache.test.ts
  • indexer/packages/redis/src/caches/orderbook-mid-prices-cache.ts
  • indexer/packages/redis/src/caches/scripts.ts
  • indexer/packages/redis/src/index.ts
  • indexer/packages/redis/src/scripts/add_market_price.lua
  • indexer/packages/redis/src/scripts/get_market_median_price.lua
  • indexer/services/roundtable/tests/tasks/cache-orderbook-mid-prices.test.ts
  • indexer/services/roundtable/src/config.ts
  • indexer/services/roundtable/src/index.ts
  • indexer/services/roundtable/src/tasks/cache-orderbook-mid-prices.ts
Additional comments not posted (8)
indexer/services/ender/src/lib/candles-generator.ts (3)

23-23: Summary of changes: Orderbook mid price cache update

The changes in this file revolve around updating the orderbook mid price cache mechanism:

  1. The import has been changed from OrderbookMidPricesCache to OrderbookLevelsCache.
  2. The method call in getOrderbookMidPriceMap has been updated to use OrderbookLevelsCache.getOrderBookMidPrice.

These changes appear to be part of a larger refactoring effort to improve the orderbook data caching system. The localized nature of these changes suggests a minimal impact on the overall functionality of the CandlesGenerator class.

To ensure a smooth transition:

  1. Verify that all references to the old cache mechanism have been updated throughout the codebase.
  2. Update any relevant documentation or comments related to orderbook mid price retrieval.
  3. Consider adding or updating unit tests to cover the new caching mechanism.

Also applies to: 541-543


541-543: Verify the behavior of the new getOrderBookMidPrice method.

The method call has been updated from OrderbookMidPricesCache.getMedianPrice to OrderbookLevelsCache.getOrderBookMidPrice. The new method now takes redisClient as an additional parameter.

To ensure the new method behaves as expected:

  1. Verify the implementation of OrderbookLevelsCache.getOrderBookMidPrice:
#!/bin/bash
# Search for the implementation of getOrderBookMidPrice
rg -A 10 "getOrderBookMidPrice.*=" --type typescript
  1. Check if there are any other usages of the old method that need to be updated:
#!/bin/bash
# Search for any remaining usage of getMedianPrice
rg "getMedianPrice" --type typescript

23-23: Verify the impact of the import change throughout the file.

The import has been updated from OrderbookMidPricesCache to OrderbookLevelsCache. This change suggests a shift in the caching mechanism for orderbook data.

Let's verify if all usages of the old cache have been updated:

indexer/services/ender/__tests__/lib/candles-generator.test.ts (5)

21-21: LGTM: Import of OrderSide added.

The addition of OrderSide to the imports suggests that the tests now differentiate between buy and sell orders when updating price levels. This change likely reflects an update in the underlying implementation to more accurately represent the orderbook structure.


158-159: LGTM: Consistent use of updatePriceLevel in another test case.

The test consistently uses the new updatePriceLevel function to set both buy and sell prices for 'BTC-USD'. This change maintains consistency with the previous test case and aligns with the overall refactoring approach.


597-599: LGTM: Consistent use of updatePriceLevel for updating previous candles.

The test case for updating previous candles now uses the updatePriceLevel function consistently with other test cases. This change ensures that the orderbook state is accurately represented when testing the update of previous candles.


Line range hint 1-878: Overall assessment: Consistent and beneficial refactoring.

The changes in this test file consistently implement the new updatePriceLevel function across all test cases. This refactoring improves the accuracy of orderbook representation in tests and aligns with the removal of direct OrderbookMidPricesCache.setPrice calls mentioned in the summary. The modifications enhance the flexibility of the tests and provide a more comprehensive coverage of various market scenarios.

Key improvements:

  1. Explicit setting of both buy and sell prices for each market.
  2. More accurate representation of orderbook states in different test scenarios.
  3. Improved handling of markets with undefined price levels.

These changes should result in more robust and maintainable tests for the candles generator functionality.


116-118: LGTM: Price level updates refactored using updatePriceLevel.

The test now uses the new updatePriceLevel function to set both buy and sell prices for 'BTC-USD'. This change provides a more accurate representation of the orderbook state and is consistent with the refactoring mentioned earlier.

To ensure consistency, please verify if similar changes have been made across all test cases:

Verification successful

: updatePriceLevel is used consistently across all test cases in candles-generator.test.ts. No instances of the old method OrderbookMidPricesCache.setPrice were found, ensuring uniform refactoring and accurate orderbook state representation.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent usage of updatePriceLevel across test cases
# Test: Search for all occurrences of updatePriceLevel in the test file
rg "updatePriceLevel" indexer/services/ender/__tests__/lib/candles-generator.test.ts

Length of output: 1239

@@ -31,11 +32,9 @@ import { KafkaPublisher } from '../../src/lib/kafka-publisher';
import { ConsolidatedKafkaEvent } from '../../src/lib/types';
import { defaultTradeContent, defaultTradeKafkaEvent } from '../helpers/constants';
import { contentToSingleTradeMessage, createConsolidatedKafkaEventFromTrade } from '../helpers/kafka-publisher-helpers';
import { updatePriceLevel } from '../helpers/redis-helpers';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Issue Found: updatePriceLevel function is missing in redis-helpers.ts.

The import statement references updatePriceLevel from ../helpers/redis-helpers, but the function does not exist in the specified file. Please verify the implementation of updatePriceLevel or update the import path accordingly.

Analysis chain

LGTM: New helper function updatePriceLevel imported.

The introduction of updatePriceLevel suggests a refactoring of the price level update logic, which should improve code reusability and maintainability. This change is consistent with the removal of direct calls to OrderbookMidPricesCache.setPrice mentioned in the summary.

To ensure the correctness of this refactoring, please verify the implementation of updatePriceLevel in the redis-helpers file:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of updatePriceLevel function
# Test: Check if the function exists and its basic structure
rg -A 10 "export function updatePriceLevel" ../helpers/redis-helpers.ts

Length of output: 141


Script:

#!/bin/bash
# Description: Search for redis-helpers.ts in the entire codebase
fd --type f --exact "redis-helpers.ts"

Length of output: 263


Script:

#!/bin/bash
# Description: Search for redis-helpers.ts in the entire codebase
fd --type f redis-helpers.ts

Length of output: 88


Script:

#!/bin/bash
# Description: Verify the implementation of updatePriceLevel function in redis-helpers.ts
# Test: Check if the function exists and review its basic structure
rg -A 10 "export function updatePriceLevel" indexer/services/ender/__tests__/helpers/redis-helpers.ts

Length of output: 103

@adamfraser
Copy link
Contributor Author

@Mergifyio backport release/indexer/v7.x

Copy link
Contributor

mergify bot commented Sep 24, 2024

backport release/indexer/v7.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Sep 24, 2024
adamfraser added a commit that referenced this pull request Sep 24, 2024
Co-authored-by: Adam Fraser <adamfraser0@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants