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

Add websocket models and parsing for Hyperliquid - #907

Merged
DRadmir merged 13 commits into
mainfrom
hyperliquid-socket
Jan 29, 2026
Merged

DRadmir merged 13 commits into
mainfrom
hyperliquid-socket

Conversation

@DRadmir

@DRadmir DRadmir commented Jan 26, 2026

Copy link
Copy Markdown
Contributor

Introduces websocket message models and parsing logic in gem_hypercore for handling Hyperliquid websocket channels, including clearinghouse state, open orders, and subscription responses. Adds corresponding mapping and diffing utilities in gemstone to process and compare positions and orders from websocket data.

Introduces an interval field to candlestick and chart models, updates related conversions, and adds support for handling candle messages over WebSocket. This enables interval-aware candlestick data processing and transmission throughout the system.

Introduces websocket message models and parsing logic in gem_hypercore for handling Hyperliquid websocket channels, including clearinghouse state, open orders, and subscription responses. Adds corresponding mapping and diffing utilities in gemstone to process and compare positions and orders from websocket data.
@semanticdiff-com

semanticdiff-com Bot commented Jan 26, 2026 •

Copy link
Copy Markdown

@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 enhances the system's ability to interact with the Hyperliquid exchange by integrating its WebSocket API. It establishes robust data models and parsing logic for real-time market and user-specific information, such as clearinghouse states, open orders, and detailed candlestick data. The changes also introduce mechanisms within gemstone to efficiently process and reconcile this streaming data, ensuring that the application can maintain up-to-date and accurate representations of trading positions and orders.

Highlights

  • Hyperliquid WebSocket Models: Introduced new data models in gem_hypercore for handling Hyperliquid WebSocket messages, including WebSocketChannel, WebSocketMessage, ClearinghouseStateData, OpenOrdersData, and SubscriptionResponseData.
  • WebSocket Parsing Logic: Added parsing functions in gem_hypercore::provider::websocket_mapper to deserialize raw WebSocket JSON data into structured Rust types for various channels like clearinghouse state, open orders, subscription responses, and candlestick data.
  • Candlestick Interval Support: Modified Candlestick and ChartCandleStick models to include an interval field, enabling interval-aware processing and display of candlestick data received via WebSocket.
  • Gemstone Integration and Diffing: Integrated the new WebSocket parsing capabilities into gemstone with a Hyperliquid object. This includes methods to parse incoming WebSocket data into a GemHyperliquidSocketMessage enum and utilities to diff clearinghouse positions and open orders, updating take-profit/stop-loss values.

🧠 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. ↩

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

Copy link
Copy Markdown
Contributor

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 introduces models and parsing logic for Hyperliquid websockets, along with adding an interval field to candlestick-related models. The changes are generally well-structured. However, I've identified a critical issue with a duplicate type definition that will prevent compilation. Additionally, I've provided suggestions to refactor some repetitive code and improve error handling for better maintainability and clarity. Addressing these points will enhance the quality of the code.

Comment thread gemstone/src/models/perpetual.rs
Comment thread crates/gem_hypercore/src/provider/websocket_mapper.rs Outdated
Comment thread gemstone/src/perpetual.rs Outdated
@DRadmir
DRadmir marked this pull request as draft January 26, 2026 17:43
@DRadmir
DRadmir force-pushed the hyperliquid-socket branch from 51b6801 to a63faf6 Compare January 26, 2026 17:50
Introduces an interval field to candlestick and chart models, updates related conversions, and adds support for handling candle messages over WebSocket. This enables interval-aware candlestick data processing and transmission throughout the system.
@DRadmir
DRadmir force-pushed the hyperliquid-socket branch from a63faf6 to 7d064f8 Compare January 26, 2026 17:53
Introduces handling for the AllMids WebSocket channel, including parsing and mapping of mid prices as a HashMap<String, f64>. Updates relevant models and message enums to support this new channel.
@DRadmir DRadmir self-assigned this Jan 27, 2026
@DRadmir
DRadmir marked this pull request as ready for review January 27, 2026 10:59
Comment thread crates/gem_hypercore/src/models/websocket.rs Outdated
Comment thread crates/gem_hypercore/src/provider/websocket_mapper.rs Outdated
Comment thread gemstone/src/models/perpetual.rs
Comment thread gemstone/src/perpetual.rs
DRadmir and others added 3 commits January 27, 2026 17:26
Moved the logic for diffing clearinghouse and open order positions from the Gemstone layer into the gem_hypercore provider module. Introduced the PositionsDiff struct and related functions in gem_hypercore, updated WebSocketMessage to be generic, and adjusted usages in Gemstone to call the new provider functions. This improves code reuse and separation of concerns.
Added a generic parse method to WebSocketMessage for deserializing JSON. Updated websocket_mapper functions to use the new parse method, reducing code duplication and improving readability.
pub summary: PerpetualPositionsSummary,
}

#[derive(Debug)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

move to models?

Ok(WebSocketMessage::<serde_json::Value>::parse(json)?.channel)
}

pub fn parse_clearinghouse_state(json: &str) -> Result<ClearinghouseResult, serde_json::Error> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do you need all those parse methods? does not make much sense to have a separate method

Comment thread gemstone/src/perpetual.rs
Self {}
}

pub fn parse_websocket_data(&self, data: Vec<u8>) -> Result<GemHyperliquidSocketMessage, crate::GemstoneError> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we move parse_websocket_data to hyperliquid lib?

Unified websocket message parsing into a single function returning a typed enum, replacing multiple parsing functions. Added comprehensive tests and JSON fixtures for all supported websocket message types. Updated dependent code to use the new parsing API and type alias for GemHyperliquidSocketMessage.
@DRadmir
DRadmir merged commit 238dd69 into main Jan 29, 2026
7 checks passed
@DRadmir
DRadmir deleted the hyperliquid-socket branch January 29, 2026 15:54
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.

3 participants