#!/usr/bin/env node // Open Broker CLI - Hyperliquid trading toolkit import { spawn } from 'child_process'; import { fileURLToPath } from 'url'; import path from 'path'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const scriptsDir = path.resolve(__dirname, '../scripts'); const commands: Record = { // Setup 'install': { script: 'setup/install.ts', description: 'Install companion packages or an agent harness' }, 'setup': { script: 'setup/onboard.ts', description: 'Interactive setup wizard' }, 'onboard': { script: 'setup/onboard.ts', description: 'Interactive setup wizard' }, 'approve-builder': { script: 'setup/approve-builder.ts', description: 'Approve builder fee' }, // Info 'account': { script: 'info/account.ts', description: 'View account balance and equity' }, 'positions': { script: 'info/positions.ts', description: 'View open positions' }, 'funding': { script: 'info/funding.ts', description: 'View funding rates' }, 'markets': { script: 'info/markets.ts', description: 'View market data' }, 'all-markets': { script: 'info/all-markets.ts', description: 'View all markets (perps, HIP-3, spot, HIP-4)' }, 'search': { script: 'info/search-markets.ts', description: 'Search for assets across providers' }, 'spot': { script: 'info/spot.ts', description: 'View spot markets and balances' }, 'fills': { script: 'info/fills.ts', description: 'View trade fill history' }, 'orders': { script: 'info/orders.ts', description: 'View order history' }, 'order-status': { script: 'info/order-status.ts', description: 'Check status of a specific order' }, 'fees': { script: 'info/fees.ts', description: 'View fee schedule and volume' }, 'candles': { script: 'info/candles.ts', description: 'View OHLCV candle data' }, 'funding-history': { script: 'info/funding-history.ts', description: 'View historical funding rates' }, 'trades': { script: 'info/trades.ts', description: 'View recent trades for an asset' }, 'rate-limit': { script: 'info/rate-limit.ts', description: 'View API rate limit status' }, 'funding-scan': { script: 'info/funding-scan.ts', description: 'Scan funding rates across all dexes' }, 'outcomes': { script: 'info/outcomes.ts', description: 'Search and inspect HIP-4 outcome markets' }, // Operations 'buy': { script: 'operations/market-order.ts', description: 'Market buy order' }, 'sell': { script: 'operations/market-order.ts', description: 'Market sell order' }, 'market': { script: 'operations/market-order.ts', description: 'Market order' }, 'limit': { script: 'operations/limit-order.ts', description: 'Limit order' }, 'trigger': { script: 'operations/trigger-order.ts', description: 'Trigger order (TP/SL)' }, 'tpsl': { script: 'operations/set-tpsl.ts', description: 'Set TP/SL on position' }, 'cancel': { script: 'operations/cancel.ts', description: 'Cancel orders' }, 'twap': { script: 'operations/twap.ts', description: 'Native TWAP order' }, 'twap-cancel': { script: 'operations/twap-cancel.ts', description: 'Cancel a TWAP order' }, 'twap-status': { script: 'operations/twap-status.ts', description: 'View TWAP order status' }, 'scale': { script: 'operations/scale.ts', description: 'Scale in/out orders' }, 'bracket': { script: 'operations/bracket.ts', description: 'Bracket order (entry + TP + SL)' }, 'chase': { script: 'operations/chase.ts', description: 'Chase order with ALO' }, 'spot-buy': { script: 'operations/spot-order.ts', description: 'Spot buy order' }, 'spot-sell': { script: 'operations/spot-order.ts', description: 'Spot sell order' }, 'spot-order': { script: 'operations/spot-order.ts', description: 'Spot order (market or limit)' }, 'outcome-buy': { script: 'operations/outcome-order.ts', description: 'Buy a HIP-4 outcome token' }, 'outcome-sell': { script: 'operations/outcome-order.ts', description: 'Sell a HIP-4 outcome token' }, 'outcome-open': { script: 'operations/outcome-order.ts', description: 'Open a HIP-4 outcome position' }, 'outcome-close': { script: 'operations/outcome-order.ts', description: 'Close a HIP-4 outcome position' }, 'outcome-order': { script: 'operations/outcome-order.ts', description: 'HIP-4 outcome order (market or limit)' }, // Automations 'auto': { script: 'auto/cli.ts', description: 'Run/manage trading automations' }, // Guardian (position risk monitoring) 'guardian': { script: 'guardian/cli.ts', description: 'Watch positions for risk, alert via Telegram' }, }; function printHelp() { console.log(` Open Broker - Hyperliquid Trading CLI Usage: openbroker [options] Setup: install Install companion packages or OpenBroker for an agent harness setup One-command setup (wallet + config + builder approval) Info Commands: account View account balance, equity, and margin positions View open positions with PnL fills View trade fill history orders View order history (all statuses) order-status Check status of a specific order fees View fee schedule, tiers, and volume funding View funding rates (sorted by annualized rate) funding-history View historical funding rates for an asset candles View OHLCV candle data trades View recent trades (tape) for an asset markets View market data for main perps all-markets View all markets (perps, HIP-3, spot, HIP-4) search Search for assets across all providers spot View spot markets and balances rate-limit View API rate limit status funding-scan Scan funding rates across all dexes (main + HIP-3) outcomes Search and inspect HIP-4 outcome markets Trading Commands: buy Market buy order sell Market sell order market Market order (specify --side) limit Limit order trigger Trigger order (stop loss / take profit) tpsl Set TP/SL on existing position cancel Cancel orders Spot Trading: spot-buy Spot buy order spot-sell Spot sell order spot-order Spot order (market or limit, specify --side) HIP-4 Outcome Trading: outcome-buy Buy a YES/NO outcome token outcome-sell Sell a YES/NO outcome token outcome-open Alias for outcome-buy outcome-close Alias for outcome-sell outcome-order Outcome order (market or limit, specify --side) Advanced Execution: twap Native TWAP order (exchange-managed) twap-cancel Cancel a running TWAP order twap-status View TWAP order history/status scale Scale in/out with multiple orders bracket Entry with TP and SL chase Chase price with ALO orders Automations: auto run