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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ export interface TradingPerpetualMarketMessage {
volume24H?: string,
trades24H?: number,
nextFundingRate?: string,

// Derived fields
tickSize?: string,
stepSize?: string,
}

export type OraclePriceMarketMessageContentsMapping = {
Expand Down
10 changes: 10 additions & 0 deletions indexer/services/ender/src/helpers/kafka-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
PerpetualPositionFromDatabase,
PerpetualPositionSubaccountMessageContents,
PositionSide,
protocolTranslations,
SubaccountMessageContents,
SubaccountTable,
TradingMarketMessageContents,
Expand Down Expand Up @@ -328,6 +329,7 @@ export function generatePerpetualMarketMessage(
atomicResolution: perpetualMarket.atomicResolution,
subticksPerTick: perpetualMarket.subticksPerTick,
stepBaseQuantums: perpetualMarket.stepBaseQuantums,
marketType: perpetualMarket.marketType,
initialMarginFraction: helpers.ppmToString(Number(liquidityTier.initialMarginPpm)),
maintenanceMarginFraction: helpers.ppmToString(
helpers.getMaintenanceMarginPpm(
Expand All @@ -337,6 +339,14 @@ export function generatePerpetualMarketMessage(
),
openInterestLowerCap: liquidityTier.openInterestLowerCap,
openInterestUpperCap: liquidityTier.openInterestUpperCap,
tickSize: protocolTranslations.getTickSize(perpetualMarket),
stepSize: protocolTranslations.getStepSize(perpetualMarket),
priceChange24H: perpetualMarket.priceChange24H,
volume24H: perpetualMarket.volume24H,
trades24H: perpetualMarket.trades24H,
nextFundingRate: perpetualMarket.nextFundingRate,
openInterest: perpetualMarket.openInterest,
baseOpenInterest: perpetualMarket.baseOpenInterest,
Comment on lines +344 to +349
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',

};
})
.value();
Expand Down
Loading