Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Refactor Perpetuals to use HyperliquidObserverService#1635

Merged
DRadmir merged 18 commits into
mainfrom
1142-websockets-for-perpetuals
Jan 29, 2026
Merged

Refactor Perpetuals to use HyperliquidObserverService#1635
DRadmir merged 18 commits into
mainfrom
1142-websockets-for-perpetuals

Conversation

@DRadmir
Copy link
Copy Markdown
Contributor

@DRadmir DRadmir commented Jan 26, 2026

Replaces PerpetualObserverService with HyperliquidObserverService for perpetuals observation and updates related dependency injection, protocols, and usages throughout the codebase. Removes periodic polling in favor of WebSocket-based updates, adds Hyperliquid-specific protocol and types, and updates wallet/account accessors. Also updates WebSocketConnectable to support sending string messages and adds a PerpetualService mock for testing.

Introduces real-time candlestick chart updates for perpetuals by integrating HyperliquidChartService and chart subscription management in PerpetualSceneViewModel. Updates the observer service to handle candle messages, adds ChartCandleStick interval support, and wires dependencies through navigation and environment. This enables live chart data streaming and proper subscription lifecycle handling.

Simulator Screenshot - iPhone 17 Pro - 2026-01-28 at 00 06 15 Simulator Screenshot - iPhone 17 Pro - 2026-01-28 at 00 06 22 Simulator Screenshot - iPhone 17 Pro - 2026-01-28 at 00 06 27 Simulator Screenshot - iPhone 17 Pro - 2026-01-28 at 00 06 42

Close: #1082
Close: #1142

Replaces PerpetualObserverService with HyperliquidObserverService for perpetuals observation and updates related dependency injection, protocols, and usages throughout the codebase. Removes periodic polling in favor of WebSocket-based updates, adds Hyperliquid-specific protocol and types, and updates wallet/account accessors. Also updates WebSocketConnectable to support sending string messages and adds a PerpetualService mock for testing.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @DRadmir, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the perpetuals feature by migrating its data observation mechanism from a polling-based system to a real-time WebSocket-driven approach using Hyperliquid's services. The change aims to provide users with more immediate and accurate updates for perpetuals, including live chart data, by establishing persistent connections and handling streaming messages. This improves responsiveness and efficiency by eliminating the need for frequent manual data fetches.

Highlights

  • Real-time Data Integration: The PerpetualObserverService has been replaced by HyperliquidObserverService, transitioning from periodic polling to a more efficient WebSocket-based real-time data streaming for perpetuals. This enables live updates for clearinghouse state, open orders, and candlestick charts.
  • Live Chart Updates: Introduced real-time candlestick chart updates for perpetuals by integrating HyperliquidChartService and managing chart subscriptions within PerpetualSceneViewModel. This allows for dynamic chart data streaming and proper lifecycle handling for subscriptions based on user interaction and view state.
  • Dependency Injection and Protocol Updates: Updated dependency injection across the application to use the new HyperliquidObserverService. New protocols like HyperliquidPerpetualServiceable have been introduced, and existing protocols (PerpetualServiceable) have been refined to reflect the new architecture.
  • WebSocket Enhancements: The WebSocketConnectable protocol and its implementation (WebSocketConnection) have been extended to support sending string messages, which is crucial for Hyperliquid's WebSocket API communication.
  • Wallet and Account Accessors: Wallet and account accessors related to perpetuals have been updated to specifically target hyperliquidAccount, ensuring correct data retrieval for Hyperliquid-specific operations.
  • Testing Utility: A PerpetualServiceMock has been added to facilitate testing of perpetual-related functionalities, conforming to both PerpetualServiceable and HyperliquidPerpetualServiceable.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@DRadmir DRadmir self-assigned this Jan 26, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request successfully refactors the perpetuals observation mechanism from periodic polling to a more efficient WebSocket-based approach using HyperliquidObserverService. The changes introduce real-time candlestick chart updates, update dependency injection across various services and views, and streamline wallet/account accessors. The new HyperliquidChartService and related types are well-integrated, and the PerpetualServiceMock provides good test coverage. Overall, the implementation demonstrates a robust shift towards real-time data handling and improved resource management.

@DRadmir DRadmir force-pushed the 1142-websockets-for-perpetuals branch from fd99d7f to 6014b47 Compare January 26, 2026 18:07
Introduces real-time candlestick chart updates for perpetuals by integrating HyperliquidChartService and chart subscription management in PerpetualSceneViewModel. Updates the observer service to handle candle messages, adds ChartCandleStick interval support, and wires dependencies through navigation and environment. This enables live chart data streaming and proper subscription lifecycle handling.
@DRadmir DRadmir force-pushed the 1142-websockets-for-perpetuals branch from 6014b47 to 589861c Compare January 27, 2026 04:55
Advanced the core submodule reference to commit f706ce21a167f0c9b58ae2b8717eebc09d22febf. This pulls in the latest changes from the core repository.
Added dynamic axis tick count and price formatting to ChartBounds. Updated CandlestickChartView to use the new axis formatting and display a highlighted label for the current price with color based on price movement.
Introduces AllMids price subscription handling in HyperliquidObserverService and PerpetualsSceneViewModel, enabling real-time price updates for perpetuals. PerpetualService and PerpetualStore now support updating prices, with update frequency throttled via Preferences. Updates related protocols, mocks, and dependency injection to support the new functionality.
@DRadmir DRadmir force-pushed the 1142-websockets-for-perpetuals branch from 5f283d4 to 19dbdb8 Compare January 27, 2026 10:57
@DRadmir DRadmir marked this pull request as ready for review January 27, 2026 11:05
@DRadmir DRadmir force-pushed the 1142-websockets-for-perpetuals branch 3 times, most recently from 99f2e5b to fe8051c Compare January 27, 2026 19:03
Moved subscription logic for candles and mids to async onAppear/onDisappear methods in both PerpetualScene and PerpetualsScene. Updated ViewModels to subscribe/unsubscribe to all periods or mids on appearance/disappearance, and removed redundant or now-unnecessary code. This improves resource management and ensures subscriptions are properly handled with SwiftUI view lifecycle.
@DRadmir DRadmir force-pushed the 1142-websockets-for-perpetuals branch from fe8051c to ce03fa8 Compare January 27, 2026 19:08
…Socket node support

- Extract PerpetualObservable protocol with associated type for subscriptions
- Extract ChartStreamable protocol and rename HyperliquidChartService to ChartObserverService
- Replace specific subscribe/unsubscribe methods with generic subscribe(_:)/unsubscribe(_:)
- Subscribe only to current chart period instead of all periods
- Add PerpetualNodeService with Preferences-backed node selection
- Add WebSocket base URLs to Constants and Chain extension for WS URLs
- Remove hardcoded hyperliquidWebSocketURL constant
DRadmir and others added 5 commits January 28, 2026 23:39
…ockets-for-perpetuals

# Conflicts:
#	Features/Perpetuals/Sources/ViewModels/PerpetualsSceneViewModel.swift
#	Features/Perpetuals/TestKit/PerpetualsSceneViewModel+TestKit.swift
#	Gem/Services/ObserversService.swift
#	core
@DRadmir DRadmir merged commit 715451f into main Jan 29, 2026
1 check passed
@DRadmir DRadmir deleted the 1142-websockets-for-perpetuals branch January 29, 2026 15:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrate websockets for perpetuals Implement HyperCoreObserver

2 participants