Skip to content

M3 #28: Rust SDK: HTTP client for REST API#68

Merged
joaquinbejar merged 1 commit into
mainfrom
M3/issue-28-http-client
Feb 1, 2026
Merged

M3 #28: Rust SDK: HTTP client for REST API#68
joaquinbejar merged 1 commit into
mainfrom
M3/issue-28-http-client

Conversation

@joaquinbejar

Copy link
Copy Markdown
Owner

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/

File Description
mod.rs Module exports
config.rs Client configuration
error.rs Client-specific errors
http.rs HTTP client implementation

Client Configuration

  • Base URL: Configurable API endpoint
  • Timeout: Request timeout (default: 30s)
  • Max Retries: Automatic retry count (default: 3)
  • API Key: Optional authentication
  • User Agent: Customizable user agent

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>

Error Handling

  • ClientError::Request — HTTP request failures
  • ClientError::Deserialization — JSON parsing errors
  • ClientError::Api — API error responses
  • ClientError::RateLimited — 429 with retry-after
  • ClientError::NotFound — 404 responses
  • ClientError::Unauthorized — 401 responses
  • ClientError::Timeout — Request timeouts

Dependencies

  • Add reqwest v0.12 with json and rustls-tls features

Technical Decisions

  • reqwest: Industry-standard async HTTP client
  • Automatic retry: Exponential backoff for transient failures
  • Rate limiting: Respects Retry-After header on 429
  • Connection pooling: Reuses connections via reqwest
  • Typed responses: Deserializes into SDK types

Testing

  • 16 unit tests for client configuration and creation
  • Configuration validation tests
  • Builder pattern tests

Checklist

  • Code follows .internalDoc/09-rust-guidelines.md
  • Documentation added for all public items
  • No warnings from cargo clippy
  • cargo fmt passes
  • All tests pass

Closes #28

- 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
@joaquinbejar joaquinbejar added this to the M3: Client SDKs milestone Feb 1, 2026
@joaquinbejar joaquinbejar merged commit 7149f0f into main Feb 1, 2026
5 checks passed
@joaquinbejar joaquinbejar deleted the M3/issue-28-http-client branch February 2, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rust SDK: HTTP client for REST API

1 participant