Read
BTC and ETH market parameters, account balances, positions, history and protocol state. Wallet data arrives through a server-sent event stream.
Independent project / Developer documentation / v0.1
A small API between
your strategy and Papertrade.
Read markets and account state, preview orders, and submit signed trade intents through one HTTP service. Your caller decides what to trade; this service handles data, signing, risk checks and submission.
01 / Overview
papertrade-api is an independent, open-source integration with papertrade.xyz, a synthetic perpetuals protocol on Hyperliquid’s HyperEVM. It exposes a bearer-token-protected API for callers such as trading bots and research tools. It contains no trading strategy.
BTC and ETH market parameters, account balances, positions, history and protocol state. Wallet data arrives through a server-sent event stream.
Quotes and order previews with risk violations. Dry-runs exercise intent encoding with throwaway keys and return no replayable signature.
In live mode, sign EIP-712 intents with a session key and submit them to Papertrade’s relayer. Open, close and cancel queued intents.
02 / Quick start
The hosted instance is for authorized clients. Obtain its bearer token from the operator and set API_TOKEN in your shell. Keep it on the server; do not embed it in browser code or commit it.
/health needs no token. It reports the current mode and wallet-stream freshness. A successful liveness response alone does not mean that upstream data is ready.
curl --fail-with-body \
https://papertrade-api.euncasino.com/health
export API_BASE=https://papertrade-api.euncasino.com
curl --fail-with-body \
-H "Authorization: Bearer $API_TOKEN" \
"$API_BASE/v1/markets"
This request explicitly uses dryRun: true, even if the server later enables live trading. The amounts below demonstrate the request format. Review violations; a preview can return HTTP 200 while reporting unmet account or risk requirements.
curl --fail-with-body \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" \
-X POST "$API_BASE/v1/orders/open" \
-d '{
"market": "BTC",
"side": "long",
"marginUsd": "100",
"leverage": 100,
"dryRun": true
}'
Successful previews return mode: "dry-run" and submission: null. Amounts should be USD strings; raw 18-decimal values in responses are strings to preserve precision.
03 / API reference
Every /v1 route requires Authorization: Bearer <token>. Route details below reflect the repository at commit af5d474.
| Method | Path | Purpose |
|---|---|---|
| GET | /health | Public liveness, mode and snapshot age. |
| GET | /v1/markets | BTC/ETH parameters, limits and best bid/ask. |
| GET | /v1/account | Balances, lifetime PnL, fees and session state. |
| GET | /v1/positions | Open positions and estimated close PnL. |
| GET | /v1/positions/closed | Recent closes observed on the stream. |
| GET | /v1/history/:kind | trades, cashflows, queue or staking; optional ?cursor=. |
| GET | /v1/intents/:id | Observed status of an intent; ID is a 32-byte hex string. |
| GET | /v1/protocol | LP, queue, relayer health and notices. |
| POST | /v1/quote | Quote for market, side, margin and leverage; optional entry/exit prices. |
| POST | /v1/orders/open | Open or preview: market, side, marginUsd, leverage, optional dryRun. |
| POST | /v1/orders/close | Position IDs and optional dryRun; split into batches of up to 12. |
| POST | /v1/orders/close-all | Close all open positions; optional dryRun. |
| POST | /v1/intents/:id/cancel | Cancel a queued intent; optional dryRun. |
| GET | /v1/session | Wallet address and session-key status. |
| POST | /v1/session/register | Register a session key. This is a signed upstream write, including in dry-run mode. |
| GET / POST | /v1/kill-switch | Read or set {engaged, reason?}. |
| GET | /v1/funding/deposit-address | Cross-check the wallet’s deposit proxy against the chain and relayer. |
Live opens and closes return 202; poll the intent or positions endpoint. Handle 400 for invalid requests, 401 for missing or invalid tokens, 422 for rejected risk checks, 429 for upstream rate limits, 502 for upstream errors and 503 when the wallet snapshot has not arrived. Error bodies contain an error object with code and message.
04 / Controls & limits
The wallet key signs session registrations. A separate session key signs trades and cannot withdraw funds through this service. Writes are serialized, nonces and state persist, and live submissions are recorded in an audit log.
LIVE_TRADING=false makes trade operations previews. A client can request a dry-run but cannot force live mode.| Setting | Default |
|---|---|
MAX_MARGIN_USD | 100 |
MAX_LEVERAGE | 100 |
MAX_OPEN_POSITIONS | 3 |
MAX_TOTAL_MARGIN_USD | 300 |
DAILY_LOSS_LIMIT_USD | 50 |
SNAPSHOT_MAX_AGE_MS | 30,000 |
These are software defaults, not recommended trading parameters. The upstream protocol applies additional constraints; inspect /v1/markets before constructing an order.
05 / Self-hosting
Use Docker Compose or Node.js 24+. The repository contains the service, tests, Dockerfile, an environment example and VM provisioning scripts.
git clone https://github.com/romme86/papertrade-api.git
cd papertrade-api
cp .env.example .env
chmod 600 .env
docker compose --env-file .env build
Generate a dedicated wallet and token privately on your deployment machine. The key generator prints secrets: run it only in a private terminal and store the values in .env.
docker compose --env-file .env run --rm --no-deps \
papertrade-api node dist/keygen.js
Set WALLET_PRIVATE_KEY and a strong API_TOKEN of at least 32 characters. Keep LIVE_TRADING=false, then start the service:
docker compose --env-file .env up -d
curl --fail-with-body http://127.0.0.1:8787/health
The repository’s Compose file binds to loopback by default. For remote access, use a private network or a TLS reverse proxy. Preserve the data volume: it contains session keys, nonce counters and the audit log. See the repository’s operator checklist for the separate, manual steps required to enable live trading.
06 / Limitations
This is an independent integration, not an official Papertrade API. It mirrors the frontend’s signed-intent protocol, which is undocumented and may change. Build-ID discovery refreshes periodically, but upstream compatibility still needs verification.
Documentation reviewed on 11 October 2026 against source commit af5d474. The source and authenticated API responses are the reference for current behavior.