M3 #28: Rust SDK: HTTP client for REST API#68
Merged
Conversation
- Add client module to SDK with HTTP client for REST API: - config.rs: ClientConfig with base URL, timeout, retries, API key - error.rs: ClientError for HTTP errors, rate limiting, API errors - http.rs: MatchbookClient with async methods - Market data methods: - get_markets() → Vec<Market> - get_market(address) → Market - get_orderbook(market, depth) → OrderBook - get_trades(market, limit, before) → Vec<Trade> - User data methods: - get_orders(owner, market) → Vec<Order> - get_user_trades(owner, market) → Vec<Trade> - get_balances(owner) → Vec<Balance> - Client features: - Configurable base URL, timeout, max retries - Optional API key authentication - Automatic retry with exponential backoff - Rate limiting handling (429) - Typed error responses - Connection pooling via reqwest - Add reqwest to workspace dependencies - 16 unit tests for client configuration and creation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the HTTP client that wraps the REST API endpoints, providing a type-safe interface for fetching market data, order book snapshots, and user data.
Changes
New Module:
sdk/src/client/mod.rsconfig.rserror.rshttp.rsClient Configuration
Market Data Methods
get_markets()→Vec<Market>get_market(address)→Marketget_orderbook(market, depth)→OrderBookget_trades(market, limit, before)→Vec<Trade>User Data Methods
get_orders(owner, market)→Vec<Order>get_user_trades(owner, market)→Vec<Trade>get_balances(owner)→Vec<Balance>Error Handling
ClientError::Request— HTTP request failuresClientError::Deserialization— JSON parsing errorsClientError::Api— API error responsesClientError::RateLimited— 429 with retry-afterClientError::NotFound— 404 responsesClientError::Unauthorized— 401 responsesClientError::Timeout— Request timeoutsDependencies
reqwestv0.12 with json and rustls-tls featuresTechnical Decisions
Testing
Checklist
.internalDoc/09-rust-guidelines.mdcargo clippycargo fmtpassesCloses #28