# papertrade-terminal
[](LICENSE)
[](https://github.com/nirholas/papertrade-terminal)
[](https://papertrade.xyz)
[](https://github.com/nirholas/papertrade-terminal/stargazers)
[](https://github.com/nirholas/papertrade-terminal/commits/main)
[](https://papertrade-terminal.pages.dev/docs/mcp/)
[](https://papertrade-terminal.pages.dev/docs/)
[](#the-papertrade-toolkit)
[Live site](https://papertrade-terminal.pages.dev) · [Terminal](https://papertrade-terminal.pages.dev/app/) · [Docs](https://papertrade-terminal.pages.dev/docs/) · [MCP](https://papertrade-terminal.pages.dev/mcp) · [Issues](https://github.com/nirholas/papertrade-terminal/issues) · [Discussions](https://github.com/nirholas/papertrade-terminal/discussions) · [Papertrade](https://papertrade.xyz) · [Toolkit](#the-papertrade-toolkit)
Unofficial, non-custodial trading terminal for [Papertrade](https://papertrade.xyz), the fully on-chain 1000x synthetic perps exchange on Hyperliquid's HyperEVM (chain 999). Static app plus a tiny same-origin proxy, deployable on Cloudflare Pages.
> **Unofficial, not affiliated with Papertrade. High leverage can lose your whole margin.** Nothing here is financial advice. Review every confirmation dialog before you sign.
## What it is
A browser terminal built on [papertrade-sdk](https://github.com/nirholas/papertrade-sdk). Your wallet key never touches the page: you connect an injected wallet (EIP-6963, with a `window.ethereum` fallback), sign one `RegisterSessionKey` message, and from then on a session key stored in this browser signs orders. Session keys can open and close positions but can never withdraw.
The screen has a candle chart on the left, the order ticket on the right (Trade, Fund, Swap), and positions, history and pending orders below. On a phone it collapses to a bottom nav (Chart, Trade, Positions, Fund, Swap) with no horizontal scroll at 360px. Light and dark follow `prefers-color-scheme`; `prefers-reduced-motion` is honored.
## Features
- **Wallet**: EIP-6963 discovery, `window.ethereum` fallback, switch or add HyperEVM (999), address and USDC/HYPE balances, designed no-wallet, wrong-chain and rejected states. Watch-only mode with `?watch=0x...`.
- **Session key**: generated by the SDK, registered with a wallet signature after a plain-language summary, stored in `localStorage` with a clear control, expiry shown, re-registered when expired.
- **Trading**: market selector with live marks, long/short, margin, leverage slider (up to 1000x), pre-trade panel (notional, entry, bust price, what a close pays at several price moves after deadband, impact and fee), validations (min $10 margin, $10,000 notional, per-market caps), confirm dialog, session-key signing, submission through the proxy, intent status and toasts.
- **Positions**: live table over the wallet SSE stream, close one or close selected (batched at 12 per intent), trade history, pending orders with cancel.
- **Charts**: lightweight-charts candles with interval switcher (Hyperliquid candles), entry and bust lines for your positions, a TradingView tab (BTC and ETH), and a HYPE/USDC pool tab (native GeckoTerminal candles, with DexTools and GeckoTerminal embed toggles).
- **Fund**: deposit through `buildHyperEvmDeposit` (each step signed in your wallet, with the activation fee and minimum shown), withdraw through `prepareWithdraw` with route (HyperCore or HyperEVM), fee and minimum shown.
- **Swap**: KyberSwap quote on HyperEVM, route, rate, minimum received, price impact, gas, exact-amount approve, and a transaction your wallet signs.
- **Quote ladder**: besides the close-outcome table, a leverage ladder shows the bust price and room to liquidation at every leverage step for the live mark.
- **Deep links**: `/?market=BTC&side=long&margin=1000&leverage=10` opens the terminal with the ticket prefilled behind a review banner. `?embed=1` hides marketing chrome so it can run as a window in [Papertrade OS](https://papertrade-os.pages.dev/?open=terminal).
- **Keyboard**: `B` long, `S` short, `/` margin, `M` market, `[` `]` leverage, `1` to `4` Trade, Positions, Fund, Swap, `C` chart, `?` help, `Esc` close.
## MCP server and AI connectors
A read-only [Model Context Protocol](https://modelcontextprotocol.io) server runs at **https://papertrade-terminal.pages.dev/mcp** (Streamable HTTP, stateless, no key). Nine tools: `list_markets`, `quote_open_position`, `quote_leverage_ladder`, `quote_close_position`, `get_wallet_positions`, `get_recent_trades`, `get_candles`, `get_protocol_status` and `build_trade_plan`. Nothing signs, sends funds or places orders. `build_trade_plan` returns an unsigned plan plus a deep link that opens this terminal prefilled; the user signs in their own wallet.
```sh
claude mcp add --transport http papertrade-terminal https://papertrade-terminal.pages.dev/mcp
codex mcp add papertrade-terminal --url https://papertrade-terminal.pages.dev/mcp
```
Gemini CLI, Cursor, VS Code, Claude Desktop and claude.ai, ChatGPT, the Claude and OpenAI APIs, Windsurf, Zed, Cline, Goose and Continue are covered in [Connect your AI](https://papertrade-terminal.pages.dev/docs/connect-your-ai/). Discovery files: [`/.well-known/mcp/server-card.json`](https://papertrade-terminal.pages.dev/.well-known/mcp/server-card.json), [`/.well-known/agent-card.json`](https://papertrade-terminal.pages.dev/.well-known/agent-card.json), [`/.well-known/api-catalog`](https://papertrade-terminal.pages.dev/.well-known/api-catalog), [`/openapi.json`](https://papertrade-terminal.pages.dev/openapi.json), [`/llms.txt`](https://papertrade-terminal.pages.dev/llms.txt). Documentation lives in [`docs/`](docs/) and is published at https://papertrade-terminal.pages.dev/docs/.
## Quick start
```sh
npm install ../papertrade-sdk-0.1.0.tgz viem # SDK is not on npm yet
npm install
npm run dev:site # builds, then wrangler pages dev on :8788
```
Open http://localhost:8788. Add `?watch=0xYourAddress` to browse an account read-only.
## Scripts
| Script | Does |
| --- | --- |
| `npm run typecheck` | `tsc --noEmit` for the app and for `site/functions` (Workers types) |
| `npm test` | vitest: trade math, deep links, MCP protocol and tools, discovery files, docs build, signing round-trips, swap parsing, session store, util |
| `npm run build:site` | renders `docs/` to `site/public/docs`, regenerates the discovery files, then esbuild (splitting, lazy chunks) into `site/public` |
| `npm run dev:site` | build and serve with `wrangler pages dev` |
| `npm run deploy:site` | build and `wrangler pages deploy` |
## Architecture
```
browser (site/public/app.js + lazy chunks)
|- PapertradeClient -> /api/papertrade/* (Pages Function, same origin) -> exchange.papertrade.xyz
|- viem public client -> rpc.hyperliquid.xyz/evm (balances, allowance, receipts)
|- Hyperliquid info API (candles), KyberSwap aggregator, GeckoTerminal (pool candles)
|- wallet (EIP-1193): RegisterSessionKey, deposits, withdrawals, swaps
`- session key (localStorage): open, close, cancel intents
```
Papertrade sends no CORS headers, so `site/functions/api/papertrade/[[path]].ts` forwards only the public routes (state and query reads, the SSE stream, signed intent POSTs). It holds no keys. Heavy code (charts, TradingView, swap) loads on demand. A strict CSP lives in `site/public/_headers` (no inline styles or scripts).
## Environment variables
None are required. Optional, in `site/.dev.vars` or the Pages project settings:
| Name | Default | Purpose |
| --- | --- | --- |
| `PAPERTRADE_API_URL` | `https://exchange.papertrade.xyz` | Upstream the proxy forwards to |
## Deploy
```sh
gh repo create nirholas/papertrade-terminal --public --source . --push
cd site && npx wrangler pages deploy
```
(`npm run build:site` first, or use `npm run deploy:site`.) The site is expected at https://papertrade-terminal.pages.dev.
## The Papertrade toolkit
Nine open-source building blocks for [Papertrade](https://papertrade.xyz), the fully on-chain 1000x perps exchange on Hyperliquid HyperEVM. Use them together or on their own.
| Project | What it does |
|---|---|
| [papertrade-ai](https://github.com/nirholas/papertrade-ai) | MCP server and CLI: trade Papertrade from Claude, ChatGPT, Cursor and any MCP client |
| [papertrade-sdk](https://github.com/nirholas/papertrade-sdk) | Typed API client, live account stream, EIP-712 signing and verified settlement math. |
| **papertrade-terminal** (this repo) | Non-custodial web trading terminal with charts, order ticket, funding and swaps. |
| [papertrade-analytics](https://github.com/nirholas/papertrade-analytics) | DefiLlama-style dashboard and JSON API: TVL, volume, OI, PAPER economics. |
| [papertrade-explorer](https://github.com/nirholas/papertrade-explorer) | Linkable wallet pages, decoded transactions and a live leaderboard. |
| [papertrade-liquidations](https://github.com/nirholas/papertrade-liquidations) | Liquidation map and closest-to-bust feed, recomputed with the verified formula. |
| [papertrade-yield](https://github.com/nirholas/papertrade-yield) | PAPER staking dashboard with realized USDC yield and wallet-signed actions. |
| [papertrade-alerts](https://github.com/nirholas/papertrade-alerts) | Know before the liquidation: Telegram, Discord and webhook alerts. |
| [papertrade-copytrade](https://github.com/nirholas/papertrade-copytrade) | Guard-railed copy-trading CLI. Dry run by default. |
| [papertrade-x402](https://github.com/nirholas/papertrade-x402) | Pay-per-call intelligence API for AI agents, paid in USDC on Solana or Base. |
## Contributing and support
- Found a bug or want a feature? [Open an issue](https://github.com/nirholas/papertrade-terminal/issues/new/choose).
- Questions and show-and-tell: [Discussions](https://github.com/nirholas/papertrade-terminal/discussions).
- Pull requests are welcome, see [CONTRIBUTING.md](CONTRIBUTING.md). Security reports go through [SECURITY.md](SECURITY.md).
- If this saved you time, a star helps other Papertrade traders and builders find it.
Built by [three.ws](https://three.ws).
## Disclaimer
Unofficial, not affiliated with Papertrade, high leverage can lose your whole margin. Apache-2.0 licensed. See [SECURITY.md](SECURITY.md).
<!-- nirholas:watermark -->
---
<p align="center">
Built by <a href="https://github.com/nirholas"><b>nirholas</b></a> · <a href="https://x.com/nichxbt">@nichxbt</a> · <a href="https://github.com/nirholas">github.com/nirholas</a>
</p>
<!-- /nirholas:watermark -->