M3 #31: TypeScript SDK: HTTP and WebSocket client implementation#71
Merged
Conversation
- Add client module to TypeScript SDK: - config.ts: ClientConfig with base URL, WS URL, timeout, API key - errors.ts: Client-specific error classes - http.ts: MatchbookClient HTTP client - websocket.ts: MatchbookWsClient WebSocket client - HTTP client methods: - getMarkets(), getMarket(address) - getOrderbook(market, depth) - getTrades(market, options) - getOrders(owner, market), getUserTrades(owner, market) - getBalances(owner) - buildPlaceOrderTx(), buildCancelOrderTx() - buildDepositTx(), buildWithdrawTx() - WebSocket client methods: - connect(), disconnect() - subscribeBook(market, callback, depth) - subscribeTrades(market, callback) - subscribeOrders(callback) - unsubscribe(subscriptionId) - Error classes: - ClientError, HttpError, ApiError - TimeoutError, RateLimitError - NotFoundError, UnauthorizedError - WebSocketError - Features: - Automatic reconnection with exponential backoff - Heartbeat ping/pong handling - Subscription management - Type-safe callbacks - Add README.md with usage examples - 26 unit tests for client configuration and errors - 60 total tests passing
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 and WebSocket client for the TypeScript SDK, providing a complete client library for JavaScript/TypeScript applications to interact with Matchbook.
Changes
New Module:
ts-sdk/src/client/config.tserrors.tshttp.tswebsocket.tsindex.tsHTTP Client (
MatchbookClient)Market Data Methods:
getMarkets()— Get all marketsgetMarket(address)— Get market by addressgetOrderbook(market, depth?)— Get order bookgetTrades(market, options?)— Get recent tradesUser Data Methods:
getOrders(owner, market?)— Get user ordersgetUserTrades(owner, market?)— Get user tradesgetBalances(owner)— Get user balancesTransaction Building Methods:
buildPlaceOrderTx(params)— Build place order transactionbuildCancelOrderTx(params)— Build cancel order transactionbuildDepositTx(params)— Build deposit transactionbuildWithdrawTx(params)— Build withdraw transactionWebSocket Client (
MatchbookWsClient)Connection Methods:
connect()— Connect to WebSocket serverdisconnect()— Disconnect from serverSubscription Methods:
subscribeBook(market, callback, depth?)— Subscribe to order booksubscribeTrades(market, callback)— Subscribe to tradessubscribeOrders(callback)— Subscribe to order updatesunsubscribe(subscriptionId)— Unsubscribe from channelFeatures:
Error Classes
ClientError— Base error classHttpError— HTTP request errorsApiError— API error responsesTimeoutError— Request timeoutsRateLimitError— Rate limiting (429)NotFoundError— Resource not found (404)UnauthorizedError— Authentication errors (401)WebSocketError— WebSocket errorsDocumentation
Technical Decisions
Testing
Checklist
Closes #31