import { OrderRequest, Pair, OrderBook, Order, Candle, MarketSnapshot } from '../types/index.js'; import { BaseClient } from './base.js'; import { Result } from '../utils/result.js'; import { Big } from '../utils/decimal.js'; export declare class CLOBClient extends BaseClient { _cachedSignature: string | null; /** * Transform API pair response to match standardized field names. * Maps lowercase/camelCase API fields to snake_case SDK fields. * Preserves existing snake_case fields if present, otherwise transforms from alternative formats. */ private _transformPairFromAPI; private _coerceOrderNumeric; private _coerceOrderBlock; private _coerceOptionalOrderBlock; private _enumToName; /** * Resolve and validate (timeInForce, stp) for an order. Returns the * integer type2/stp values or a failure describing the invalid * modifier / combination. Shared by every write path so the order-type * matrix is enforced uniformly. Defaults preserve prior behavior * (GTC / CANCEL_TAKER). */ private _resolveOrderModifiers; private _toHexIdentifier; private _findPairInfoByTradePairId; private _resolvePairFromOrder; private _resolveTradePairIdFromPair; private _buildCanonicalOrder; /** * Fetch and store trading pair metadata. * Cached for 15 minutes (semi-static data). * Returns the list of pair data objects. */ getClobPairs(): Promise>; _ensurePairExists(pair: string): boolean; /** * Validate and quantize an order's price/amount against the pair's * display decimals and min/max trade-amount bounds. * * Inputs whose precision exceeds the pair's display decimals are * rejected — the SDK does not silently round, because that would * silently slip orders (e.g. a stop at 99.99 quietly becoming 99.9). * Float-representation noise (residual <= 1e-10) is tolerated and * snapped to the nearest displayable value. * * After the display-precision check, the resulting notional * (`price * amount`) is checked against the pair's bounds (quote- * token denominated) so the SDK fails fast instead of waiting for * the contract to reject. * * @param price Order price (null or 0 skips the price-side checks) * @param amount Order amount (always validated) * @param pairData Resolved pair metadata */ protected _normalizeOrderAmounts(price: number | string | Big | null | undefined, amount: number | string | Big, pairData: Pair): Result<{ price: Big | null; amount: Big; }>; /** Fetch CLOB pairs if needed, then verify the pair exists. */ _ensurePairExistsAsync(pair: string): Promise; /** Run an operation against TradePairs on the subnet RPC with provider failover. */ private _withL1TradePairsContract; /** Normalize an order id argument to 32-byte `0x` hex for contract calls. */ private _orderIdToBytes32Hex; private _classifyOrderIdInput; private _buildOrderResolutionSequence; private _isEmptyOrderData; private _fetchOrderByInternalId; private _fetchOrderByClientIdPath; private _resolveOrderReference; private _slotToBytes32Hex; private _getOrCreateWsManager; /** * Subscribe to WebSocket events. Requires wsManagerEnabled in config. */ subscribeToEvents(topic: string, callback: (data: unknown) => void, isPrivate?: boolean): Promise; unsubscribeFromEvents(topic: string): void; closeWebsocket(graceS?: number): Promise; /** * Fetch the most recent OHLCV candles for a CLOB trading pair. * * Wraps `GET /api/trading/candle-chunk` (count-back endpoint). The * backend returns up to `limit` candles ending at the current time, * in chronological order. Cached for 1 second (orderbook tier). */ getCandles(pair: string, interval: string, limit: number): Promise>; /** * Fetch the global market snapshot for all CLOB pairs. * * Wraps `GET /api/stats/market-snapshot`. Returns the full envelope * (per-pair list with rolling 24h OHLCV, plus exchange-wide totals). * Cached for 1 second (orderbook tier). */ getMarketSnapshot(): Promise>; /** * Fetch 24h ticker stats for a single CLOB trading pair. * * Filters the global market snapshot to the requested pair. Reuses * the cached snapshot served by `getMarketSnapshot`, so calling this * for many pairs in close succession costs at most one network call. */ get24hStats(pair: string): Promise>; /** * Place a new order. */ addOrder(req: OrderRequest, waitForReceipt?: boolean): Promise>; /** * Cancel a single order. */ cancelOrder(orderId: string | Uint8Array, waitForReceipt?: boolean): Promise>; /** * Cancel a single open order by client order ID (on-chain). */ cancelOrderByClientId(clientOrderId: string | Uint8Array, waitForReceipt?: boolean): Promise>; /** * Cancel all open orders. */ cancelAllOrders(): Promise>; cancelListOrders(orderIds: string[], waitForReceipt?: boolean): Promise>; /** * Get Open Orders from REST API. */ /** * Transform API order response to match Order interface field names. * Maps lowercase/snake_case API fields to camelCase SDK fields. */ private _transformOrderFromAPI; getOpenOrders(pair?: string): Promise>; /** * Paginated per-account order history (any status: NEW, PARTIAL, * FILLED, CANCELED, EXPIRED, KILLED, REJECTED). Returns canonical * `Order[]` rows in the same shape as `getOpenOrders` — they pass * through the shared `_transformOrderFromAPI` helper so callers can * mix the two result sets without re-normalising. * * Routes through the signed REST endpoint * `/api/trading/signed/orders` (distinct from `getOpenOrders`' * `/privapi/signed/orders` which only returns currently-open * rows). The trade-kit's `clob_get_orders_by_account` tool calls * the same endpoint via `signedGet("orders", ...)` and provided * the empirical verification for the path + query shape used here. * * Cached for 10 seconds (balance tier) per `(address, opts)` tuple. * The resolved address is either the explicit `account` argument * or the connected wallet address; distinct addresses and * distinct filter combinations never share a cache slot. * * When no wallet is configured AND no explicit `account` is * passed, returns `Result.fail` — the call has no addressee. * When a wallet IS configured, the `x-signature` header is * attached via the shared `_getAuthHeaders()` helper; when only * an explicit account is supplied (no signer), the auth header * is omitted and the backend may reject — this lets read-only * callers query by address without forcing a key, mirroring the * SDK's general read-only ergonomics. * * @param account Optional trader address; defaults to the * connected wallet's address. At least one must be available. * @param opts Optional filters and pagination * (`pair` / `status` / `limit` / `offset`); defaults to * `{ limit: 100, offset: 0 }` to match the trade-kit's tool wrapper. */ getOrderHistory(account?: string, opts?: { pair?: string; status?: 'NEW' | 'REJECTED' | 'PARTIAL' | 'FILLED' | 'CANCELED' | 'EXPIRED' | 'KILLED' | string; limit?: number; offset?: number; }): Promise>; /** * Get OrderBook. * Cached for 1 second (orderbook data). */ getOrderBook(pair: string): Promise>; _parseNBook(data: any[], pairData: Pair): { price: number; quantity: number; }[]; _getAuthHeaders(): Promise>; getOrder(orderId: string | Uint8Array): Promise>; getOrderByClientId(clientOrderId: string | Uint8Array): Promise>; addLimitOrderList(orders: OrderRequest[], waitForReceipt?: boolean): Promise>; /** * Alias for {@link addLimitOrderList}. The batch path accepts mixed * order types (per-order `type` / `timeInForce` / `stp`), so this name * reads more accurately than the historical `addLimitOrderList`, which * is retained for backward compatibility. */ addOrderList(orders: OrderRequest[], waitForReceipt?: boolean): Promise>; /** * Cancel an existing order and replace it atomically with a new price * and quantity, via the contract's `cancelReplaceOrder`. * * Note: `cancelReplaceOrder` carries only a new price and quantity, so * the replacement **inherits** the original order's `type1`, * `timeInForce` (`type2`) and `stp`. This method therefore exposes no * time-in-force / stp parameters; to change those, cancel the order and * place a new one (e.g. via {@link cancelAddList}). */ replaceOrder(orderId: string, newPrice: number, newAmount: number, waitForReceipt?: boolean): Promise>; cancelListOrdersByClientId(clientOrderIds: string[], waitForReceipt?: boolean): Promise>; cancelAddList(replacements: any[], waitForReceipt?: boolean): Promise>; _formatOrderData(orderData: any[]): Promise>; } //# sourceMappingURL=clob.d.ts.map