|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Build and Development Commands |
| 6 | + |
| 7 | +```bash |
| 8 | +# Build all binaries (release) |
| 9 | +cargo build --release |
| 10 | +# Binaries output to: ./target/release/{fintool,hyperliquid,binance,coinbase,okx,polymarket} |
| 11 | + |
| 12 | +# Run Rust unit tests |
| 13 | +cargo test --release |
| 14 | + |
| 15 | +# Check formatting |
| 16 | +cargo fmt -- --check |
| 17 | + |
| 18 | +# Apply formatting |
| 19 | +cargo fmt |
| 20 | + |
| 21 | +# Clippy linting |
| 22 | +cargo clippy --release -- -D warnings |
| 23 | +``` |
| 24 | + |
| 25 | +## Testing |
| 26 | + |
| 27 | +The Rust test suite (`cargo test`) covers unit tests only. Exchange-specific end-to-end tests are shell scripts under `tests/` that require live credentials and real exchange access — they are not run in CI automatically. |
| 28 | + |
| 29 | +```bash |
| 30 | +# Run a specific Rust test |
| 31 | +cargo test <test_name> |
| 32 | + |
| 33 | +# E2E shell tests (require configured credentials) |
| 34 | +bash tests/hyperliquid/e2e_trading.sh |
| 35 | +bash tests/binance/e2e_trading.sh |
| 36 | +bash tests/okx/e2e_trading.sh |
| 37 | +``` |
| 38 | + |
| 39 | +## Architecture |
| 40 | + |
| 41 | +This is a multi-binary Rust workspace with one library crate and six CLI binaries. |
| 42 | + |
| 43 | +### Binary Structure |
| 44 | + |
| 45 | +Each binary (`src/bin/*.rs`) handles CLI argument parsing via `clap` and dispatches to shared command handlers: |
| 46 | + |
| 47 | +- `fintool` — exchange-agnostic market intelligence (quotes, news, SEC filings); no authentication required for most commands |
| 48 | +- `hyperliquid` — spot + perp + HIP-3 commodity/stock perps; uses EIP-712 signing with a wallet private key |
| 49 | +- `binance` — spot + futures; HMAC-SHA256 signed requests with API key/secret |
| 50 | +- `coinbase` — spot only; HMAC-SHA256 signed requests |
| 51 | +- `okx` — spot + perp; HMAC-SHA256 + base64 signed requests, plus a passphrase |
| 52 | +- `polymarket` — prediction markets on Polygon; EIP-712 signing via `alloy` |
| 53 | + |
| 54 | +Each binary also accepts a `--json` flag where the entire command is passed as a JSON string and all output (including errors) is returned as JSON — this is the primary interface for agent/script integration. |
| 55 | + |
| 56 | +There is no `--exchange` flag. Exchange selection is done by invoking the appropriate binary. Internally, each binary has a `const EXCHANGE: &str = "..."` constant that is passed to shared command functions for exchange-specific routing. |
| 57 | + |
| 58 | +### Library Modules (`src/`) |
| 59 | + |
| 60 | +- `config.rs` — Config file loading from `~/.fintool/config.toml`; credential accessors for each exchange |
| 61 | +- `signing.rs` — Hyperliquid wallet signing, asset resolution, and order execution via `hyperliquid_rust_sdk` |
| 62 | +- `hip3.rs` — HIP-3 builder-deployed perps EIP-712 signing (SILVER, GOLD, TSLA, etc. using USDT0 collateral on the `cash` dex) |
| 63 | +- `binance.rs` / `coinbase.rs` / `okx.rs` — Exchange API clients with auth signing |
| 64 | +- `bridge.rs` — Across Protocol cross-chain USDC bridge (Ethereum/Base → Arbitrum → Hyperliquid) |
| 65 | +- `unit.rs` — HyperUnit bridge for ETH/BTC/SOL deposit/withdraw to/from Hyperliquid |
| 66 | +- `polymarket.rs` — Polymarket CLOB/Gamma/Bridge SDK helpers |
| 67 | +- `format.rs` — Terminal color formatting and number formatting utilities |
| 68 | + |
| 69 | +### Commands Layer (`src/commands/`) |
| 70 | + |
| 71 | +Command implementations are shared across exchange binaries. Each file handles one logical command (e.g., `order.rs` for spot buy/sell, `perp.rs` for futures, `deposit.rs` for deposits). Each command function receives an exchange name string and executes the operation against the appropriate API. |
| 72 | + |
| 73 | +### Key Design Patterns |
| 74 | + |
| 75 | +- All HTTP is done via `reqwest` with rustls (no OpenSSL dependency, except vendored OpenSSL pulled in transitively) |
| 76 | +- Dual output mode: human-readable colored/tabular output by default; JSON via `--json` flag |
| 77 | +- Config is loaded fresh from disk on each invocation (no daemon) |
| 78 | +- HIP-3 perps are auto-detected by symbol (SILVER, GOLD, TSLA, NVDA, etc.) and routed to the `cash` dex instead of the standard Hyperliquid perp market |
| 79 | +- Withdrawal `--to` can be either a chain name or a destination address; `lib.rs::resolve_withdraw_destination` disambiguates using the `KNOWN_CHAINS` constant |
| 80 | + |
| 81 | +## Configuration |
| 82 | + |
| 83 | +Config file at `~/.fintool/config.toml`. Run `fintool init` to generate a template. |
| 84 | + |
| 85 | +Key sections: |
| 86 | +- `[wallet]` — `private_key` (hex) or `wallet_json` + `wallet_passcode` (keystore). Used by Hyperliquid and Polymarket. |
| 87 | +- `[network]` — `testnet = true` for Hyperliquid testnet |
| 88 | +- `[api_keys]` — Per-exchange API credentials; optional `openai_api_key` for LLM-enriched quotes |
| 89 | +- `[polymarket]` — `signature_type`: `proxy` (default), `eoa`, or `gnosis-safe` |
| 90 | + |
| 91 | +Additional config keys not in the README: `cryptopanic_token`, `newsapi_key`, `binance_base_url` (set to `https://api.binance.us` for Binance US — disables futures/options support). |
0 commit comments