Skip to content

feat: add Binance WebSocket price provider#138

Merged
dianacarvalho1 merged 10 commits intomainfrom
lp/ENG-5605-binance
Apr 1, 2026
Merged

feat: add Binance WebSocket price provider#138
dianacarvalho1 merged 10 commits intomainfrom
lp/ENG-5605-binance

Conversation

@louise-poole
Copy link
Copy Markdown
Contributor

Summary

  • Add BinanceWsProvider that subscribes to Binance bookTicker WebSocket streams for real-time bid/ask prices
  • Pair discovery cross-references SharedMarketData tokens with Binance /api/v3/exchangeInfo, re-syncs every 60s
  • Price resolution: direct pair (bid) → reverse pair (1/ask) → intermediate routing through USDT/USDC/ETH/BTC, using ask prices on the buy-side leg
  • Reconnects with exponential backoff (5s → 60s max)
  • Register as second default provider alongside Hyperliquid

@louise-poole louise-poole changed the title feat: feat: add Binance WebSocket price provider feat: add Binance WebSocket price provider Mar 25, 2026
Copy link
Copy Markdown
Contributor

@tamaralipows tamaralipows left a comment

Choose a reason for hiding this comment

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

Thank you for taking this @louise-poole ! Just a few comments to make this easier if we ever need to debug in the future - again we can take it from here though 🙏

Copy link
Copy Markdown
Collaborator

@dianacarvalho1 dianacarvalho1 left a comment

Choose a reason for hiding this comment

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

Thank you @louise-poole ! Only have smol comments

}

/// Resolves a price between two symbols, trying direct/reverse first,
/// then routing through intermediate assets.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is there a reason why we shouldn't route through intermediate assets in Hyperliquid too?

Copy link
Copy Markdown
Contributor

@tamaralipows tamaralipows Mar 30, 2026

Choose a reason for hiding this comment

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

IIUC, we don't need to. Hyperliquid's oracle prices are all USD-denominated. So pricing any pair is just usd_price_in / usd_price_out. USD is the intermediate for every single pair. (Note each asset returns a single oraclePx value - not a pair price)

Binance is different: it has specific trading pairs (ETHUSDT, LINKBTC, etc.), so if there's no direct LINK/ETH pair, you have to explicitly route through USDT or BTC.

Let me know if I missed something though

@tamaralipows tamaralipows force-pushed the lp/ENG-5604-hyperliquid branch 6 times, most recently from d98be1f to d7a4423 Compare March 30, 2026 20:18
@tamaralipows tamaralipows force-pushed the lp/ENG-5605-binance branch 2 times, most recently from d25be2d to 7a04efb Compare March 30, 2026 20:53
@tamaralipows
Copy link
Copy Markdown
Contributor

I rebased but it should still be fine to see the latest commits since they're signed with my name instead of Louise's

Troshchk
Troshchk previously approved these changes Mar 31, 2026
Copy link
Copy Markdown
Contributor

@Troshchk Troshchk left a comment

Choose a reason for hiding this comment

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

Thank you!
Looks good, have only one question

@Troshchk Troshchk dismissed their stale review March 31, 2026 09:56

Approved by mistake

Copy link
Copy Markdown
Collaborator

@dianacarvalho1 dianacarvalho1 left a comment

Choose a reason for hiding this comment

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

Thank you @tamaralipows ! I see that the USDC like tokens are way more relevant here than in Hyperliquid!

@dianacarvalho1 dianacarvalho1 force-pushed the lp/ENG-5604-hyperliquid branch 2 times, most recently from d6a1f85 to 0f32995 Compare March 31, 2026 16:01
@dianacarvalho1 dianacarvalho1 force-pushed the lp/ENG-5604-hyperliquid branch from 0f32995 to 4f07faf Compare March 31, 2026 16:51
Base automatically changed from lp/ENG-5604-hyperliquid to main March 31, 2026 16:56
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 31, 2026

Breaking API Changes (Intentional)

Breaking API changes detected and declared in the PR title.
Ensure the minor version is bumped before merging (breaking changes on 0.x.x bump the minor).

semver-checks output
Checking fynd-core v0.43.2 -> v0.43.2 (no change; assume minor)
     Checked [   0.520s] 196 checks: 195 pass, 1 fail, 0 warn, 49 skip

--- failure function_missing: pub fn removed or renamed ---

Description:
A publicly-visible function cannot be imported by its prior path. A `pub use` may have been removed, or the function itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/function_missing.ron

Failed in:
  function fynd_core::price_guard::utils::resolve_token, previously in file fynd-core/src/price_guard/utils.rs:16

     Summary semver requires new major version: 1 major and 0 minor checks failed
    Finished [   0.776s] fynd-core
    Checking fynd-rpc v0.43.2 -> v0.43.2 (no change; assume minor)
     Checked [   0.083s] 196 checks: 196 pass, 49 skip
     Summary no semver update required
    Finished [   0.138s] fynd-rpc
    Checking fynd-rpc-types v0.43.2 -> v0.43.2 (no change; assume minor)
     Checked [   0.129s] 196 checks: 196 pass, 49 skip
     Summary no semver update required
    Finished [   0.209s] fynd-rpc-types
    Checking fynd-client v0.43.2 -> v0.43.2 (no change; assume minor)
     Checked [   0.142s] 196 checks: 196 pass, 49 skip
     Summary no semver update required
    Finished [   0.261s] fynd-client

Copy link
Copy Markdown
Contributor

@Troshchk Troshchk left a comment

Choose a reason for hiding this comment

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

Thank you @dianacarvalho1!
Looks good, have one question about the websocket reconnects

tamaralipows and others added 2 commits April 1, 2026 14:21
They were essentially saying the exact same thing and raised only when the token was not found.

Took 5 minutes


Took 2 minutes

Took 33 seconds

Took 5 minutes
Add BinanceWsProvider that connects to Binance bookTicker streams with
dynamic pair discovery, bid/ask-aware price resolution (direct, reverse,
and intermediate routing), exponential backoff reconnection, and 60s
re-sync for new tokens. Also uppercases normalize_symbol output for
exchange compatibility.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Took 36 seconds
tamaralipows and others added 7 commits April 1, 2026 14:22
Since different providers treat tokens differently, this has to be defined per provider. The list is not so big, so it's fine to keep this in the provider file itself and not in a json.

Also fixed some rebase-related errors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Took 28 seconds
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fix: broken doc link and stale OpenAPI spec

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Rename TickerCache to PriceCache to match Hyperliquid
- More descriptive docstrings, better function naming

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When the Binance WS receives a ticker quoted in USDT or USDC (e.g. ETHUSDT),
inject synthetic cache entries for every USD stablecoin in stable_usd.json
(e.g. ETHDAI, ETHGHO, ETHLUSD). This mirrors the approach used by the
Hyperliquid provider and ensures unlisted stablecoins can be priced without
lookup-time substitution hacks. Real Binance tickers are never overwritten.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Also move constants up in hyperliquid.rs
Add prefix test in tests

Took 1 hour 37 minutes
This is similar to the "k-" prefix in Hyperliquid.
Binance lists certain very low-priced meme coins as "1000CHEEMS", where the oracle price is quoted per 1,000 tokens rather than per 1 token.

Took 2 minutes
@dianacarvalho1 dianacarvalho1 merged commit 1a89ee4 into main Apr 1, 2026
15 checks passed
@dianacarvalho1 dianacarvalho1 deleted the lp/ENG-5605-binance branch April 1, 2026 13:31
@propellerci
Copy link
Copy Markdown

propellerci bot commented Apr 1, 2026

This PR is included in version 0.44.0 🎉

@propellerci propellerci bot added the true label Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants