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

Add missing fields to perpetual markets kafka update #2539

Merged
merged 6 commits into from
Oct 25, 2024

Conversation

shrenujb
Copy link
Contributor

@shrenujb shrenujb commented Oct 24, 2024

Changelist

Add additional fields to the perpetual markets updates needed by the websocket message to the FE

Test Plan

Existing tests

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Summary by CodeRabbit

  • New Features
    • Enhanced trading market messages with additional parameters: marketType, tickSize, stepSize, priceChange24H, volume24H, trades24H, nextFundingRate, openInterest, and baseOpenInterest.
    • Added optional properties tickSize and stepSize to the TradingPerpetualMarketMessage interface for more detailed market information.

@shrenujb shrenujb requested a review from a team as a code owner October 24, 2024 21:47
Copy link
Contributor

coderabbitai bot commented Oct 24, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes in this pull request involve updates to the TradingPerpetualMarketMessage interface and the generatePerpetualMarketMessage function within the codebase. Two optional properties, tickSize and stepSize, have been added to the interface, enhancing the data structure for market trading parameters. Additionally, the generatePerpetualMarketMessage function has been modified to include several new properties, allowing for more detailed information to be conveyed in the perpetual market messages.

Changes

File Path Change Summary
indexer/packages/postgres/src/types/websocket-message-types.ts Added optional properties tickSize?: string and stepSize?: string to the TradingPerpetualMarketMessage interface.
indexer/services/ender/src/helpers/kafka-helper.ts Added import for protocolTranslations and expanded generatePerpetualMarketMessage to include new properties: marketType, tickSize, stepSize, priceChange24H, volume24H, trades24H, nextFundingRate, openInterest, and baseOpenInterest.

Possibly related PRs

Suggested reviewers

  • dydxwill

🐇 In the market where rabbits play,
New fields have come to brighten the day.
Tick sizes and steps, oh what a treat,
For trading messages, they can't be beat!
With each hop, the data flows,
In the world of trading, excitement grows! 🐇


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.

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 (1)
indexer/packages/postgres/src/types/websocket-message-types.ts (1)

226-229: Add JSDoc comments for the new derived fields.

While the fields follow the interface's conventions, they would benefit from documentation explaining:

  • The purpose and meaning of each field
  • The expected string format (decimal places, valid ranges)
  • How these values are derived

Add JSDoc comments like this:

  // Derived fields
+ /**
+  * The minimum price increment for the market.
+  * @example "0.1" for a market that trades in $0.10 increments
+  */
  tickSize?: string,
+ /**
+  * The minimum size increment for orders in the market.
+  * @example "0.001" for a market that trades in 0.001 unit increments
+  */
  stepSize?: string,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 317a74e and 1620c8f.

📒 Files selected for processing (2)
  • indexer/packages/postgres/src/types/websocket-message-types.ts (1 hunks)
  • indexer/services/ender/src/helpers/kafka-helper.ts (3 hunks)
🔇 Additional comments (5)
indexer/packages/postgres/src/types/websocket-message-types.ts (1)

226-229: Changes look good!

The new optional fields maintain backward compatibility and follow the established patterns in the interface. The string type is appropriate for financial values to avoid floating-point precision issues.

indexer/services/ender/src/helpers/kafka-helper.ts (4)

23-23: LGTM: Import changes are appropriate.

The addition of protocolTranslations is well-organized and necessary for the new functionality.


331-331: LGTM: Market type field addition.

The marketType field addition provides important market classification information.


341-342: LGTM: Protocol translation usage for market parameters.

The use of protocol translation helpers for tickSize and stepSize ensures consistent calculations across the system.


Line range hint 331-348: Verify Kafka message consumers are prepared for new fields.

The addition of new fields to the perpetual market message structure may impact downstream consumers. Let's verify that all consumers are prepared to handle these new fields.

✅ Verification successful

Let's examine the message structure and its consumers more deeply.


Let's check one more aspect to see how these fields are being consumed in the websocket service.


Based on the gathered information, I can now provide a final response:

The new fields are safe to add and won't break existing consumers.

The investigation reveals:

  • The TradingPerpetualMarketMessage interface in websocket-message-types.ts defines all fields as optional (with ? modifier)
  • The message is primarily consumed by websocket services and handlers that use JSON serialization/deserialization
  • The message structure follows a flexible schema where additional fields won't break existing consumers due to:
    • Optional field definitions
    • JSON's inherent forward compatibility
    • Consumers only accessing documented fields they need
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all files that might be consuming the perpetual market message

# Search for files importing or using TradingPerpetualMarketMessage
echo "Files potentially consuming TradingPerpetualMarketMessage:"
rg -l "TradingPerpetualMarketMessage"

# Search for files consuming the Kafka message
echo "\nFiles potentially consuming the Kafka message:"
rg -l "generatePerpetualMarketMessage"

Length of output: 854


Script:

#!/bin/bash
# Check the message type definition and its consumers
echo "=== Checking message type definition ==="
rg -A 10 "interface TradingPerpetualMarketMessage" indexer/packages/postgres/src/types/websocket-message-types.ts

echo -e "\n=== Checking websocket documentation ==="
rg -A 10 "TradingPerpetualMarketMessage" indexer/services/comlink/public/websocket-documentation.md

echo -e "\n=== Checking handler implementations ==="
rg -B 5 -A 10 "generatePerpetualMarketMessage" indexer/services/ender/src/handlers/perpetual-market-handler.ts indexer/services/ender/src/handlers/liquidity-tier-handler.ts

Length of output: 6932


Script:

#!/bin/bash
# Check how the websocket service handles these messages
echo "=== Checking websocket message handling ==="
rg -B 5 -A 10 "TradingPerpetualMarketMessage" indexer/services/comlink/src/ --type ts

# Check for any tests that might verify the message structure
echo -e "\n=== Checking related tests ==="
rg -B 5 -A 10 "TradingPerpetualMarketMessage" indexer/services/comlink/__tests__/ --type ts

Length of output: 351

Comment on lines +343 to +348
priceChange24H: perpetualMarket.priceChange24H,
volume24H: perpetualMarket.volume24H,
trades24H: perpetualMarket.trades24H,
nextFundingRate: perpetualMarket.nextFundingRate,
openInterest: perpetualMarket.openInterest,
baseOpenInterest: perpetualMarket.baseOpenInterest,
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null checks and type safety for numeric fields.

The new market metrics fields are directly accessed without null checks. Consider adding safety checks to handle potential undefined values.

Apply this diff to add null checks and type safety:

-        priceChange24H: perpetualMarket.priceChange24H,
-        volume24H: perpetualMarket.volume24H,
-        trades24H: perpetualMarket.trades24H,
-        nextFundingRate: perpetualMarket.nextFundingRate,
-        openInterest: perpetualMarket.openInterest,
-        baseOpenInterest: perpetualMarket.baseOpenInterest,
+        priceChange24H: perpetualMarket.priceChange24H ?? '0',
+        volume24H: perpetualMarket.volume24H ?? '0',
+        trades24H: perpetualMarket.trades24H ?? 0,
+        nextFundingRate: perpetualMarket.nextFundingRate ?? '0',
+        openInterest: perpetualMarket.openInterest ?? '0',
+        baseOpenInterest: perpetualMarket.baseOpenInterest ?? '0',

This ensures that:

  1. Numeric string fields default to '0' if undefined
  2. Integer fields default to 0 if undefined
  3. Prevents potential null/undefined errors in downstream processing
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
priceChange24H: perpetualMarket.priceChange24H,
volume24H: perpetualMarket.volume24H,
trades24H: perpetualMarket.trades24H,
nextFundingRate: perpetualMarket.nextFundingRate,
openInterest: perpetualMarket.openInterest,
baseOpenInterest: perpetualMarket.baseOpenInterest,
priceChange24H: perpetualMarket.priceChange24H ?? '0',
volume24H: perpetualMarket.volume24H ?? '0',
trades24H: perpetualMarket.trades24H ?? 0,
nextFundingRate: perpetualMarket.nextFundingRate ?? '0',
openInterest: perpetualMarket.openInterest ?? '0',
baseOpenInterest: perpetualMarket.baseOpenInterest ?? '0',

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1620c8f and cdb0043.

📒 Files selected for processing (1)
  • .github/workflows/indexer-build-and-push-dev-staging.yml (1 hunks)

@@ -3,6 +3,7 @@ name: Indexer Build & Push Images to AWS ECR for Dev / Staging branches
on: # yamllint disable-line rule:truthy
push:
branches:
- 'sbansal*'
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove personal branch pattern from shared workflow.

Adding a personal branch pattern ('sbansal*') to the shared workflow file raises several concerns:

  1. Security: This allows any branch starting with "sbansal" to trigger builds and pushes to AWS ECR across multiple environments
  2. Resource usage: Automatic builds for personal branches could lead to unnecessary AWS resource consumption and costs
  3. Maintainability: Workflow triggers should remain standardized without developer-specific patterns

Recommendations:

  1. Remove the personal branch pattern
  2. Use PR-based workflows for testing instead
  3. If needed, create a separate workflow file for development/testing purposes
name: Indexer Build & Push Images to AWS ECR for Dev / Staging branches

on: # yamllint disable-line rule:truthy
  push:
    branches:
-      - 'sbansal*'
      - 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
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- 'sbansal*'
- 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

Signed-off-by: Shrenuj Bansal <[email protected]>
@shrenujb shrenujb merged commit 15aa042 into main Oct 25, 2024
14 of 15 checks passed
@shrenujb shrenujb deleted the sbansal/perp-fields branch October 25, 2024 22:25
@shrenujb
Copy link
Contributor Author

@Mergifyio release/indexer/v7.x

Copy link
Contributor

mergify bot commented Oct 28, 2024

release /indexer/v7.x

❌ Sorry but I didn't understand the command. Please consult the commands documentation 📚.

@shrenujb
Copy link
Contributor Author

@Mergifyio backport release/indexer/v7.x

Copy link
Contributor

mergify bot commented Oct 28, 2024

backport release/indexer/v7.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Oct 28, 2024
Signed-off-by: Shrenuj Bansal <[email protected]>
(cherry picked from commit 15aa042)
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