/** * Smart Order Execution — best bid/ask + 1 tick pricing. * * Instead of `marketOrder()` which can sweep deep into the book (Hyperliquid * DEX uses 5% slippage by default), this fetches the orderbook and places an * order at exactly the best available price plus one tick. * * For buys: limit price = best ask + 1 tick (fills at best ask or better) * For sells: limit price = best bid - 1 tick (fills at best bid or better) * * Uses IOC (Immediate-Or-Cancel) so the order fills instantly at the best * level and any unfilled remainder is cancelled — no resting orders left. * * Benefits: * - Fills only at the top-of-book price (no multi-level sweep) * - Saves 5-50+ bps vs raw market orders on thin books * - Predictable execution price * * SSOT rule #2: silent fallback is forbidden. The opt-in `fallback: true` flag * is preserved for callers that explicitly want best-effort market substitution * after IOC reject, but the DEFAULT is `false` — failure must surface as a * thrown error, never a silent market sweep. */ import type { ExchangeAdapter } from "./exchanges/index.js"; export interface SmartOrderOpts { /** Extra ticks of tolerance beyond best price. Default: 1 */ tickTolerance?: number; /** * Opt-in: fall back to market order if IOC limit fails. * SSOT rule #2 default: `false` — failure throws unless caller explicitly opts in. */ fallback?: boolean; /** Reduce only flag for closing positions. Default: false */ reduceOnly?: boolean; } export interface SmartOrderResult { result: unknown; method: "limit_ioc" | "market_fallback"; /** The actual limit price used for the order */ price: string; /** The best price from the orderbook */ bestBookPrice: string; /** Tick size inferred from orderbook */ tickSize: string; } /** * Execute a smart order at best bid/ask + 1 tick. * Drop-in replacement for `adapter.marketOrder()`. */ export declare function smartOrder(adapter: ExchangeAdapter, symbol: string, side: "buy" | "sell", size: string, opts?: SmartOrderOpts): Promise;