Add portfolio chart and statistics types#1079
Conversation
Expand portfolio primitives with richer types for charts and stats. Introduces PortfolioType, PortfolioChartType, PortfolioChartData, PortfolioMarginUsage, PortfolioStatistic, and PortfolioData, and imports ChartPeriod for available chart periods. Updates crate exports to expose the new types and adjusts asset_price import accordingly to support portfolio charting and margin/statistics data.
There was a problem hiding this comment.
Code Review
This pull request refactors portfolio primitives by renaming PerpetualPortfolioChartType to PortfolioType and introducing several new structures, including PortfolioChartData, PortfolioStatistic, and PortfolioData. The review feedback suggests adding missing trait derivations such as Eq, Hash, and PartialEq to these new types to ensure consistency across the crate and improve usability in Swift, particularly for UI state management.
| #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)] | ||
| #[typeshare(swift = "Equatable, Sendable, CaseIterable, Identifiable")] |
There was a problem hiding this comment.
For consistency with other primitives in this crate and to improve usability in Swift (e.g., in ForEach or as dictionary keys), PortfolioType should derive Eq and Hash in Rust, and Hashable in the typeshare attribute.
| #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)] | |
| #[typeshare(swift = "Equatable, Sendable, CaseIterable, Identifiable")] | |
| #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)] | |
| #[typeshare(swift = "Equatable, Sendable, CaseIterable, Identifiable, Hashable")] |
| #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)] | ||
| #[typeshare(swift = "Equatable, Sendable, CaseIterable, Identifiable")] |
There was a problem hiding this comment.
Similar to PortfolioType, PortfolioChartType should derive Eq and Hash in Rust and Hashable in Swift to maintain consistency across the primitive types.
| #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)] | |
| #[typeshare(swift = "Equatable, Sendable, CaseIterable, Identifiable")] | |
| #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)] | |
| #[typeshare(swift = "Equatable, Sendable, CaseIterable, Identifiable, Hashable")] |
| #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | ||
| #[typeshare(swift = "Equatable, Sendable")] |
There was a problem hiding this comment.
Adding Hashable to the typeshare attribute for PortfolioChartData ensures it can be used in hashed collections in Swift, matching the pattern used for other portfolio-related structs like PortfolioMarginUsage and PerpetualPortfolio.
| #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | |
| #[typeshare(swift = "Equatable, Sendable")] | |
| #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | |
| #[typeshare(swift = "Equatable, Sendable, Hashable")] |
| #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | ||
| #[typeshare(swift = "Equatable, Sendable")] |
There was a problem hiding this comment.
PortfolioStatistic should also include Hashable in its typeshare definition. Since its members (like PortfolioMarginUsage and ChartValuePercentage) are already marked as Hashable, this maintains a consistent API for the frontend.
| #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | |
| #[typeshare(swift = "Equatable, Sendable")] | |
| #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | |
| #[typeshare(swift = "Equatable, Sendable, Hashable")] |
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| #[typeshare(swift = "Sendable")] |
There was a problem hiding this comment.
PortfolioData is currently missing PartialEq and Equatable derivations, which are present on almost all other structs in this file. This inconsistency might make it difficult to use in UI state management (e.g., deciding when to re-render). Note that ChartPeriod in asset_price.rs would also need to derive PartialEq for this to compile.
Addresses review feedback on PR #1079. Adds Eq/Hash Rust derives and Swift Hashable typeshare attributes to PortfolioType, PortfolioChartType, PortfolioChartData, and PortfolioStatistic. Adds PartialEq + Equatable to PortfolioData, with matching PartialEq/Eq/Hash + Hashable on ChartPeriod so the derive compiles.
Expand portfolio primitives with richer types for charts and stats. Introduces PortfolioType, PortfolioChartType, PortfolioChartData, PortfolioMarginUsage, PortfolioStatistic, and PortfolioData, and imports ChartPeriod for available chart periods. Updates crate exports to expose the new types and adjusts asset_price import accordingly to support portfolio charting and margin/statistics data.