From c5545b1fbfa9fef030343f565f3c4fd9f5a2fc5d Mon Sep 17 00:00:00 2001 From: OpenClaw AI Date: Sun, 15 Mar 2026 18:41:08 +0000 Subject: [PATCH] types(client): replace market data any returns with typed responses --- src/client.ts | 24 ++++++++++++++++-------- src/types.ts | 25 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/client.ts b/src/client.ts index 7a2ff56..dca71df 100644 --- a/src/client.ts +++ b/src/client.ts @@ -102,9 +102,13 @@ import type { L2HeaderArgs, L2PolyHeader, L2WithBuilderHeader, + LastTradePriceResponse, + LastTradePricesResponse, MarketPrice, MarketReward, MarketTradeEvent, + MidpointResponse, + MidpointsResponse, NegRisk, NewOrder, Notification, @@ -121,8 +125,12 @@ import type { PaginationPayload, PostOrdersArgs, PriceHistoryFilterParams, + PriceResponse, + PricesResponse, ReadonlyApiKeyResponse, RewardsPercentages, + SpreadResponse, + SpreadsResponse, TickSize, TickSizes, TotalUserEarning, @@ -374,49 +382,49 @@ export class ClobClient { return generateOrderBookSummaryHash(orderbook); } - public async getMidpoint(tokenID: string): Promise { + public async getMidpoint(tokenID: string): Promise { return this.get(`${this.host}${GET_MIDPOINT}`, { params: { token_id: tokenID }, }); } - public async getMidpoints(params: BookParams[]): Promise { + public async getMidpoints(params: BookParams[]): Promise { return this.post(`${this.host}${GET_MIDPOINTS}`, { data: params, }); } - public async getPrice(tokenID: string, side: string): Promise { + public async getPrice(tokenID: string, side: string): Promise { return this.get(`${this.host}${GET_PRICE}`, { params: { token_id: tokenID, side: side }, }); } - public async getPrices(params: BookParams[]): Promise { + public async getPrices(params: BookParams[]): Promise { return this.post(`${this.host}${GET_PRICES}`, { data: params, }); } - public async getSpread(tokenID: string): Promise { + public async getSpread(tokenID: string): Promise { return this.get(`${this.host}${GET_SPREAD}`, { params: { token_id: tokenID }, }); } - public async getSpreads(params: BookParams[]): Promise { + public async getSpreads(params: BookParams[]): Promise { return this.post(`${this.host}${GET_SPREADS}`, { data: params, }); } - public async getLastTradePrice(tokenID: string): Promise { + public async getLastTradePrice(tokenID: string): Promise { return this.get(`${this.host}${GET_LAST_TRADE_PRICE}`, { params: { token_id: tokenID }, }); } - public async getLastTradesPrices(params: BookParams[]): Promise { + public async getLastTradesPrices(params: BookParams[]): Promise { return this.post(`${this.host}${GET_LAST_TRADES_PRICES}`, { data: params, }); diff --git a/src/types.ts b/src/types.ts index 2464336..72161e6 100644 --- a/src/types.ts +++ b/src/types.ts @@ -297,6 +297,31 @@ export enum PriceHistoryInterval { ONE_HOUR = "1h", } +export interface MidpointResponse { + midpoint: string; +} + +export type MidpointsResponse = MidpointResponse[] | Record; + +export interface PriceResponse { + price: string; +} + +export type PricesResponse = PriceResponse[] | Record; + +export interface SpreadResponse { + spread: string; +} + +export type SpreadsResponse = SpreadResponse[] | Record; + +export interface LastTradePriceResponse { + last_trade_price?: string; + price?: string; +} + +export type LastTradePricesResponse = LastTradePriceResponse[] | Record; + export interface DropNotificationParams { ids: string[]; }