-
Notifications
You must be signed in to change notification settings - Fork 14
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
fix: change data generation according to latest final api spec #59
Conversation
Reviewer's Guide by SourceryThis pull request updates the data transformation and generation logic to align with the latest API specifications. The changes include modifications to property names, data types, and the structure of the transformed data. Mock data generation and usage have also been updated to reflect these changes. Updated class diagram for CandleData and TransformedCandleclassDiagram
class CandleData {
+open_epoch_ms: string
+open: string
+high: string
+low: string
+close: string
+close_epoch_ms: string
}
class TransformedCandle {
+open_time: number
+open: string
+high: string
+low: string
+close: string
+epoch: number
}
CandleData -- TransformedCandle : transforms to
Updated class diagram for TickData and TransformedTickclassDiagram
class TickData {
+epoch_ms: string
+ask: string
+bid: string
+price: string
}
class TransformedTick {
+epoch: number
+ask: string
+bid: string
+quote: string
}
TickData -- TransformedTick : transforms to
Updated class diagram for TransformedCandleDataclassDiagram
class TransformedCandleDataMultiple {
+msg_type: string
+candles: TransformedCandle[]
+instrument_id: string
}
class TransformedCandleDataSingle {
+msg_type: string
+ohlc: TransformedCandle
+instrument_id: string
}
TransformedCandleDataMultiple -- TransformedCandle : contains
TransformedCandleDataSingle -- TransformedCandle : contains
TransformedCandleDataMultiple --|> TransformedCandleData
TransformedCandleDataSingle --|> TransformedCandleData
class TransformedCandleData
note for TransformedCandleData "Type = TransformedCandleDataMultiple | TransformedCandleDataSingle"
Updated class diagram for TransformedTickDataclassDiagram
class TransformedTickDataMultiple {
+msg_type: string
+instrument_id: string
+history: TransformedTick[]
}
class TransformedTickDataSingle {
+msg_type: string
+instrument_id: string
+tick: TransformedTick
}
TransformedTickDataMultiple -- TransformedTick : contains
TransformedTickDataSingle -- TransformedTick : contains
TransformedTickDataMultiple --|> TransformedTickData
TransformedTickDataSingle --|> TransformedTickData
class TransformedTickData
note for TransformedTickData "Type = TransformedTickDataMultiple | TransformedTickDataSingle"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Manifest Files |
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.
Hey @henry-deriv - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding a unit test for the transformTickData function to ensure correct transformation of tick data.
- The openTime ref in useChartData is initialized with Date.now() but later used as seconds - be consistent with milliseconds.
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
const transformedCandles = candles.map(candle => ({ | ||
open_time: candle.openEpochMs, | ||
const transformedCandles = candles.map((candle) => ({ | ||
open_time: Math.floor(parseInt(candle.open_epoch_ms) / 1000), |
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.
suggestion: Specify the radix in parseInt for clarity.
Consider using parseInt(candle.open_epoch_ms, 10) to avoid potential issues with different number formats.
Suggested implementation:
open_time: Math.floor(parseInt(candle.open_epoch_ms, 10) / 1000),
epoch: Math.floor(parseInt(candle.close_epoch_ms, 10) / 1000),
const transformedTicks = ticks.map(tick => ({ | ||
epoch: Math.floor(tick.epochMs / 1000), | ||
const transformedTicks = ticks.map((tick) => ({ | ||
epoch: Math.floor(parseInt(tick.epoch_ms) / 1000), |
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.
suggestion (bug_risk): Include radix parameter when parsing string timestamps.
Changing parseInt(tick.epoch_ms) to parseInt(tick.epoch_ms, 10) would be more explicit and robust.
epoch: Math.floor(parseInt(tick.epoch_ms) / 1000), | |
epoch: Math.floor(parseInt(tick.epoch_ms, 10) / 1000), |
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.
I've reviewed the changes adapting the chart data to the latest API spec. The implementation looks solid with proper field name changes and timestamp handling. I've left a few suggestions regarding error handling, unused code cleanup, and type safety improvements. Feel free to reach out if you need any clarification on the comments.
Follow-up suggestion: @devloai please verify the changes after the suggested improvements are implemented.
ohlc: TransformedCandle; | ||
instrument_id: string; |
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.
Consider adding error handling for parseInt() calls when parsing epoch_ms strings. A malformed string could cause the Math.floor operation to produce NaN. Consider adding a validation or fallback:
instrument_id: string; | |
open_time: Math.floor(Number.isNaN(parseInt(candle.open_epoch_ms)) ? Date.now() : parseInt(candle.open_epoch_ms) / 1000), |
// const data = generateHistoricalCandles(100, 60); | ||
// return transformCandleData(data); | ||
// }, []); | ||
const historicalData1 = useMemo(() => { |
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.
The variable historicalData1
and streamingData1
are defined but never used. Either remove them or use them as intended. Keeping unused code makes maintenance harder.
@@ -1,21 +1,28 @@ | |||
export const generateHistoricalCandles = (count: number = 100, durationInSeconds: number = 60) => { | |||
const currentTime = Math.floor(Date.now() / 1000); // Convert to seconds | |||
export const generateHistoricalCandles = ( |
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.
Consider importing and using the CandleData and TickData interfaces from transformChartData.ts to ensure type consistency between generated and transformed data.
Summary by Sourcery
Updates the data transformation and mock data generation to align with the latest API specification. This includes changes to property names, data types, and the addition of instrument IDs to the transformed data. The changes ensure that the chart data is correctly formatted and displayed according to the API requirements.
Bug Fixes:
Enhancements: