feat: add Binance WebSocket price provider#138
Conversation
3cd8708 to
029507f
Compare
tamaralipows
left a comment
There was a problem hiding this comment.
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 🙏
dianacarvalho1
left a comment
There was a problem hiding this comment.
Thank you @louise-poole ! Only have smol comments
| } | ||
|
|
||
| /// Resolves a price between two symbols, trying direct/reverse first, | ||
| /// then routing through intermediate assets. |
There was a problem hiding this comment.
is there a reason why we shouldn't route through intermediate assets in Hyperliquid too?
There was a problem hiding this comment.
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
d98be1f to
d7a4423
Compare
d25be2d to
7a04efb
Compare
|
I rebased but it should still be fine to see the latest commits since they're signed with my name instead of Louise's |
b8054e0 to
62b866b
Compare
Troshchk
left a comment
There was a problem hiding this comment.
Thank you!
Looks good, have only one question
dianacarvalho1
left a comment
There was a problem hiding this comment.
Thank you @tamaralipows ! I see that the USDC like tokens are way more relevant here than in Hyperliquid!
d6a1f85 to
0f32995
Compare
62b866b to
b1e7a0d
Compare
0f32995 to
4f07faf
Compare
b1e7a0d to
a33d5c4
Compare
Breaking API Changes (Intentional)Breaking API changes detected and declared in the PR title. semver-checks output |
365a4f9 to
4c913c6
Compare
Troshchk
left a comment
There was a problem hiding this comment.
Thank you @dianacarvalho1!
Looks good, have one question about the websocket reconnects
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
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
4c913c6 to
d24407b
Compare
Took 7 minutes
|
This PR is included in version 0.44.0 🎉 |
Summary
BinanceWsProviderthat subscribes to BinancebookTickerWebSocket streams for real-time bid/ask pricesSharedMarketDatatokens with Binance/api/v3/exchangeInfo, re-syncs every 60s