perp-cli 0.12.17 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +247 -27
- package/dist/_stderr-filter.js +0 -1
- package/dist/agent-wallet/lighter-keystore.d.ts +11 -0
- package/dist/agent-wallet/lighter-keystore.js +92 -10
- package/dist/agent-wallet/passphrase.d.ts +1 -1
- package/dist/agent-wallet/passphrase.js +16 -3
- package/dist/agent-wallet/store.d.ts +37 -4
- package/dist/agent-wallet/store.js +132 -0
- package/dist/agent-wallet/venue-keystore.d.ts +14 -0
- package/dist/agent-wallet/venue-keystore.js +121 -0
- package/dist/api/public/hyperliquid.js +4 -4
- package/dist/api/public/lighter.js +5 -5
- package/dist/api/public/pacifica.d.ts +0 -1
- package/dist/api/public/pacifica.js +4 -13
- package/dist/api/public/urls.d.ts +9 -1
- package/dist/api/public/urls.js +35 -13
- package/dist/arb/file-lock.d.ts +11 -0
- package/dist/arb/file-lock.js +74 -0
- package/dist/arb/index.d.ts +2 -2
- package/dist/arb/index.js +2 -2
- package/dist/arb/pending-entry.d.ts +32 -0
- package/dist/arb/pending-entry.js +77 -0
- package/dist/arb/sizing.d.ts +6 -13
- package/dist/arb/sizing.js +12 -51
- package/dist/arb/state.d.ts +45 -12
- package/dist/arb/state.js +214 -42
- package/dist/arb/utils.d.ts +20 -6
- package/dist/arb/utils.js +43 -39
- package/dist/bot/conditions.d.ts +4 -4
- package/dist/bot/conditions.js +11 -6
- package/dist/bot/config.d.ts +17 -1
- package/dist/bot/config.js +48 -12
- package/dist/bot/engine.d.ts +61 -2
- package/dist/bot/engine.js +610 -144
- package/dist/bot/fill-size.d.ts +7 -0
- package/dist/bot/fill-size.js +18 -0
- package/dist/bot/index.d.ts +1 -1
- package/dist/bot/index.js +1 -1
- package/dist/bot/perp-order.d.ts +99 -0
- package/dist/bot/perp-order.js +299 -0
- package/dist/bot/presets.d.ts +7 -0
- package/dist/bot/presets.js +17 -0
- package/dist/bot/quarantine.d.ts +75 -0
- package/dist/bot/quarantine.js +190 -0
- package/dist/bot/quote-rules.d.ts +23 -0
- package/dist/bot/quote-rules.js +69 -0
- package/dist/bot/strategies/avellaneda-mm.d.ts +32 -2
- package/dist/bot/strategies/avellaneda-mm.js +72 -70
- package/dist/bot/strategies/basis-arb.js +2 -0
- package/dist/bot/strategies/dca-strategy.d.ts +2 -0
- package/dist/bot/strategies/dca-strategy.js +5 -0
- package/dist/bot/strategies/funding-arb-strategy.d.ts +43 -3
- package/dist/bot/strategies/funding-arb-strategy.js +571 -380
- package/dist/bot/strategies/funding-arb-utils.d.ts +48 -23
- package/dist/bot/strategies/funding-arb-utils.js +159 -195
- package/dist/bot/strategies/funding-arb-v2.d.ts +32 -0
- package/dist/bot/strategies/funding-arb-v2.js +258 -47
- package/dist/bot/strategies/funding-auto.js +215 -194
- package/dist/bot/strategies/spot-perp-arb-strategy.d.ts +14 -0
- package/dist/bot/strategies/spot-perp-arb-strategy.js +217 -50
- package/dist/bot/strategies/spot-perp-executor.d.ts +73 -19
- package/dist/bot/strategies/spot-perp-executor.js +319 -120
- package/dist/bot/strategies/spot-perp-state.d.ts +43 -0
- package/dist/bot/strategies/spot-perp-state.js +70 -0
- package/dist/bot/strategy-types.d.ts +6 -0
- package/dist/bot/tui/BotDashboard.d.ts +7 -2
- package/dist/bot/tui/BotDashboard.js +6 -3
- package/dist/bridge-engine.d.ts +120 -19
- package/dist/bridge-engine.js +710 -422
- package/dist/bridge-signers.d.ts +54 -0
- package/dist/bridge-signers.js +161 -0
- package/dist/cache.d.ts +4 -1
- package/dist/cache.js +11 -0
- package/dist/cli-flags.d.ts +50 -0
- package/dist/cli-flags.js +104 -0
- package/dist/cli-program.d.ts +35 -0
- package/dist/cli-program.js +286 -0
- package/dist/cli-spec.js +1 -1
- package/dist/client-id-tracker.js +11 -2
- package/dist/commands/account.d.ts +7 -1
- package/dist/commands/account.js +70 -92
- package/dist/commands/agent-import.d.ts +114 -0
- package/dist/commands/agent-import.js +794 -0
- package/dist/commands/agent.d.ts +232 -2
- package/dist/commands/agent.js +1858 -955
- package/dist/commands/alerts.d.ts +1 -0
- package/dist/commands/alerts.js +31 -28
- package/dist/commands/arb/index.d.ts +60 -1
- package/dist/commands/arb/index.js +381 -384
- package/dist/commands/arb-auto.d.ts +132 -4
- package/dist/commands/arb-auto.js +1474 -967
- package/dist/commands/arb.d.ts +3 -1
- package/dist/commands/arb.js +62 -30
- package/dist/commands/bot.js +127 -47
- package/dist/commands/bridge.d.ts +2 -1
- package/dist/commands/bridge.js +339 -192
- package/dist/commands/builder.d.ts +55 -0
- package/dist/commands/builder.js +387 -0
- package/dist/commands/funds-onchain.d.ts +32 -0
- package/dist/commands/funds-onchain.js +286 -0
- package/dist/commands/funds.d.ts +25 -0
- package/dist/commands/funds.js +939 -245
- package/dist/commands/history.js +72 -45
- package/dist/commands/init.d.ts +107 -15
- package/dist/commands/init.js +1116 -249
- package/dist/commands/jobs.d.ts +2 -1
- package/dist/commands/jobs.js +77 -15
- package/dist/commands/manage.js +136 -91
- package/dist/commands/market.d.ts +4 -1
- package/dist/commands/market.js +35 -32
- package/dist/commands/outcome.d.ts +10 -0
- package/dist/commands/outcome.js +396 -0
- package/dist/commands/plan.js +52 -12
- package/dist/commands/portfolio.d.ts +1 -0
- package/dist/commands/portfolio.js +60 -72
- package/dist/commands/rebalance.d.ts +2 -1
- package/dist/commands/rebalance.js +33 -43
- package/dist/commands/risk.js +46 -19
- package/dist/commands/settings.d.ts +1 -0
- package/dist/commands/settings.js +246 -51
- package/dist/commands/trade.d.ts +50 -0
- package/dist/commands/trade.js +1943 -695
- package/dist/commands/wallet.d.ts +30 -1
- package/dist/commands/wallet.js +316 -337
- package/dist/config.d.ts +60 -9
- package/dist/config.js +252 -82
- package/dist/constants.d.ts +29 -4
- package/dist/constants.js +62 -20
- package/dist/dashboard/server.d.ts +2 -0
- package/dist/dashboard/server.js +9 -6
- package/dist/dashboard/ui.js +6 -4
- package/dist/dashboard/ws-feeds.js +20 -8
- package/dist/dex-asset-map.js +5 -3
- package/dist/errors.d.ts +122 -0
- package/dist/errors.js +194 -0
- package/dist/event-stream.js +75 -19
- package/dist/evm-master-tx.d.ts +59 -0
- package/dist/evm-master-tx.js +154 -0
- package/dist/exchanges/adapter-network.d.ts +10 -0
- package/dist/exchanges/adapter-network.js +10 -0
- package/dist/exchanges/arcus/adapter.d.ts +196 -0
- package/dist/exchanges/arcus/adapter.js +1092 -0
- package/dist/exchanges/arcus/agent.d.ts +55 -0
- package/dist/exchanges/arcus/agent.js +188 -0
- package/dist/exchanges/arcus/client.d.ts +63 -0
- package/dist/exchanges/arcus/client.js +285 -0
- package/dist/exchanges/arcus/public.d.ts +65 -0
- package/dist/exchanges/arcus/public.js +138 -0
- package/dist/exchanges/arcus/signing.d.ts +176 -0
- package/dist/exchanges/arcus/signing.js +288 -0
- package/dist/exchanges/arcus/spot-chain.d.ts +60 -0
- package/dist/exchanges/arcus/spot-chain.js +241 -0
- package/dist/exchanges/arcus/spot-router.d.ts +177 -0
- package/dist/exchanges/arcus/spot-router.js +183 -0
- package/dist/exchanges/arcus/spot.d.ts +109 -0
- package/dist/exchanges/arcus/spot.js +645 -0
- package/dist/exchanges/aster-funds.d.ts +127 -0
- package/dist/exchanges/aster-funds.js +252 -0
- package/dist/exchanges/aster-nonce.d.ts +2 -0
- package/dist/exchanges/aster-nonce.js +107 -0
- package/dist/exchanges/aster-spot.d.ts +117 -0
- package/dist/exchanges/aster-spot.js +686 -0
- package/dist/exchanges/aster-typed-data.d.ts +133 -7
- package/dist/exchanges/aster-typed-data.js +121 -7
- package/dist/exchanges/aster.d.ts +219 -6
- package/dist/exchanges/aster.js +1023 -153
- package/dist/exchanges/builder-fee.d.ts +254 -0
- package/dist/exchanges/builder-fee.js +421 -0
- package/dist/exchanges/canonical-symbols.d.ts +32 -0
- package/dist/exchanges/canonical-symbols.js +96 -0
- package/dist/exchanges/capabilities.d.ts +7 -1
- package/dist/exchanges/capabilities.js +7 -0
- package/dist/exchanges/hl-signing.d.ts +165 -0
- package/dist/exchanges/hl-signing.js +158 -0
- package/dist/exchanges/hyperliquid-outcome.d.ts +211 -0
- package/dist/exchanges/hyperliquid-outcome.js +646 -0
- package/dist/exchanges/hyperliquid-spot.d.ts +44 -5
- package/dist/exchanges/hyperliquid-spot.js +308 -117
- package/dist/exchanges/hyperliquid.d.ts +462 -57
- package/dist/exchanges/hyperliquid.js +1575 -449
- package/dist/exchanges/index.d.ts +6 -0
- package/dist/exchanges/index.js +4 -0
- package/dist/exchanges/interface.d.ts +63 -10
- package/dist/exchanges/interface.js +18 -3
- package/dist/exchanges/ioc-outcome.d.ts +44 -0
- package/dist/exchanges/ioc-outcome.js +57 -0
- package/dist/exchanges/legacy-trading-v2.d.ts +39 -0
- package/dist/exchanges/legacy-trading-v2.js +940 -0
- package/dist/exchanges/lighter-public.d.ts +43 -0
- package/dist/exchanges/lighter-public.js +276 -0
- package/dist/exchanges/lighter-rh-deposit.d.ts +62 -0
- package/dist/exchanges/lighter-rh-deposit.js +185 -0
- package/dist/exchanges/lighter-signer.d.ts +123 -0
- package/dist/exchanges/lighter-signer.js +215 -0
- package/dist/exchanges/lighter-spot.d.ts +91 -13
- package/dist/exchanges/lighter-spot.js +595 -233
- package/dist/exchanges/lighter.d.ts +611 -39
- package/dist/exchanges/lighter.js +1890 -649
- package/dist/exchanges/ondo/adapter.d.ts +166 -0
- package/dist/exchanges/ondo/adapter.js +835 -0
- package/dist/exchanges/ondo/agent.d.ts +31 -0
- package/dist/exchanges/ondo/agent.js +101 -0
- package/dist/exchanges/ondo/client.d.ts +60 -0
- package/dist/exchanges/ondo/client.js +297 -0
- package/dist/exchanges/ondo/funds.d.ts +122 -0
- package/dist/exchanges/ondo/funds.js +290 -0
- package/dist/exchanges/ondo/public.d.ts +95 -0
- package/dist/exchanges/ondo/public.js +214 -0
- package/dist/exchanges/ondo/spot.d.ts +127 -0
- package/dist/exchanges/ondo/spot.js +392 -0
- package/dist/exchanges/outcome-interface.d.ts +140 -0
- package/dist/exchanges/outcome-interface.js +16 -0
- package/dist/exchanges/pacifica-spot.d.ts +83 -0
- package/dist/exchanges/pacifica-spot.js +324 -0
- package/dist/exchanges/pacifica-typed-data.d.ts +30 -13
- package/dist/exchanges/pacifica-typed-data.js +57 -9
- package/dist/exchanges/pacifica.d.ts +288 -4
- package/dist/exchanges/pacifica.js +1013 -76
- package/dist/exchanges/precision.d.ts +47 -0
- package/dist/exchanges/precision.js +209 -0
- package/dist/exchanges/qfex/adapter.d.ts +341 -0
- package/dist/exchanges/qfex/adapter.js +1383 -0
- package/dist/exchanges/qfex/agent.d.ts +58 -0
- package/dist/exchanges/qfex/agent.js +188 -0
- package/dist/exchanges/qfex/client.d.ts +54 -0
- package/dist/exchanges/qfex/client.js +138 -0
- package/dist/exchanges/qfex/errors.d.ts +70 -0
- package/dist/exchanges/qfex/errors.js +236 -0
- package/dist/exchanges/qfex/public.d.ts +122 -0
- package/dist/exchanges/qfex/public.js +268 -0
- package/dist/exchanges/qfex/signing.d.ts +160 -0
- package/dist/exchanges/qfex/signing.js +283 -0
- package/dist/exchanges/qfex/ws-transport.d.ts +294 -0
- package/dist/exchanges/qfex/ws-transport.js +798 -0
- package/dist/exchanges/rate-limiter.d.ts +12 -0
- package/dist/exchanges/rate-limiter.js +64 -0
- package/dist/exchanges/registry.d.ts +14 -2
- package/dist/exchanges/registry.js +20 -32
- package/dist/exchanges/slippage.d.ts +37 -0
- package/dist/exchanges/slippage.js +70 -0
- package/dist/exchanges/spot-factory.d.ts +166 -0
- package/dist/exchanges/spot-factory.js +431 -0
- package/dist/exchanges/spot-interface.d.ts +98 -4
- package/dist/exchanges/spot-interface.js +27 -1
- package/dist/exchanges/spot-result.d.ts +79 -0
- package/dist/exchanges/spot-result.js +273 -0
- package/dist/exchanges/trading-v2.d.ts +117 -0
- package/dist/exchanges/trading-v2.js +301 -0
- package/dist/exchanges/venue-types.d.ts +231 -0
- package/dist/exchanges/venue-types.js +87 -0
- package/dist/exchanges/venue.d.ts +211 -0
- package/dist/exchanges/venue.js +132 -0
- package/dist/exchanges/venues/arcus.d.ts +8 -0
- package/dist/exchanges/venues/arcus.js +109 -0
- package/dist/exchanges/venues/aster.d.ts +49 -0
- package/dist/exchanges/venues/aster.js +176 -0
- package/dist/exchanges/venues/create-helpers.d.ts +18 -0
- package/dist/exchanges/venues/create-helpers.js +199 -0
- package/dist/exchanges/venues/hyperliquid.d.ts +23 -0
- package/dist/exchanges/venues/hyperliquid.js +126 -0
- package/dist/exchanges/venues/index.d.ts +16 -0
- package/dist/exchanges/venues/index.js +26 -0
- package/dist/exchanges/venues/lighter-family.d.ts +92 -0
- package/dist/exchanges/venues/lighter-family.js +166 -0
- package/dist/exchanges/venues/lighter-rh.d.ts +7 -0
- package/dist/exchanges/venues/lighter-rh.js +58 -0
- package/dist/exchanges/venues/lighter.d.ts +6 -0
- package/dist/exchanges/venues/lighter.js +55 -0
- package/dist/exchanges/venues/ondo.d.ts +34 -0
- package/dist/exchanges/venues/ondo.js +140 -0
- package/dist/exchanges/venues/pacifica.d.ts +8 -0
- package/dist/exchanges/venues/pacifica.js +95 -0
- package/dist/exchanges/venues/qfex.d.ts +28 -0
- package/dist/exchanges/venues/qfex.js +132 -0
- package/dist/execution-log.js +10 -2
- package/dist/funding/legacy-public.d.ts +31 -0
- package/dist/funding/legacy-public.js +369 -0
- package/dist/funding/normalize.d.ts +28 -16
- package/dist/funding/normalize.js +61 -29
- package/dist/funding/rates.d.ts +46 -11
- package/dist/funding/rates.js +228 -277
- package/dist/guardrail/perp-guardrail.js +0 -0
- package/dist/index.js +156 -684
- package/dist/jobs.d.ts +84 -6
- package/dist/jobs.js +239 -41
- package/dist/landing.d.ts +7 -2
- package/dist/landing.js +19 -3
- package/dist/mcp-server.d.ts +14 -4
- package/dist/mcp-server.js +820 -402
- package/dist/mcp-trade-guard.d.ts +16 -0
- package/dist/mcp-trade-guard.js +59 -0
- package/dist/pacifica/client.d.ts +41 -10
- package/dist/pacifica/client.js +167 -63
- package/dist/pacifica/constants.d.ts +0 -1
- package/dist/pacifica/constants.js +0 -5
- package/dist/pacifica/deposit.d.ts +30 -3
- package/dist/pacifica/deposit.js +119 -2
- package/dist/pacifica/faucet.d.ts +29 -0
- package/dist/pacifica/faucet.js +100 -0
- package/dist/pacifica/sign-tx.d.ts +15 -0
- package/dist/pacifica/sign-tx.js +41 -0
- package/dist/pacifica/types/account.d.ts +28 -4
- package/dist/pacifica/types/lake.d.ts +20 -5
- package/dist/pacifica/types/lake.js +4 -0
- package/dist/pacifica/types/market.d.ts +5 -0
- package/dist/pacifica/types/order.d.ts +4 -1
- package/dist/pacifica/types/position.d.ts +9 -1
- package/dist/plan-executor.d.ts +10 -5
- package/dist/plan-executor.js +165 -54
- package/dist/position-history.js +13 -0
- package/dist/rebalance.d.ts +26 -2
- package/dist/rebalance.js +86 -7
- package/dist/relay-swap.d.ts +232 -0
- package/dist/relay-swap.js +630 -0
- package/dist/risk.js +5 -1
- package/dist/secret-env.d.ts +15 -0
- package/dist/secret-env.js +36 -0
- package/dist/settings.d.ts +169 -6
- package/dist/settings.js +219 -38
- package/dist/signer/ows-evm.d.ts +13 -0
- package/dist/signer/ows-evm.js +22 -0
- package/dist/smart-order.d.ts +9 -0
- package/dist/smart-order.js +53 -8
- package/dist/strategies/dca.d.ts +6 -2
- package/dist/strategies/dca.js +66 -26
- package/dist/strategies/funding-arb.d.ts +11 -1
- package/dist/strategies/funding-arb.js +202 -89
- package/dist/strategies/grid.d.ts +31 -0
- package/dist/strategies/grid.js +89 -11
- package/dist/strategies/pending-stop.d.ts +8 -0
- package/dist/strategies/pending-stop.js +12 -0
- package/dist/strategies/split-order.d.ts +45 -17
- package/dist/strategies/split-order.js +157 -91
- package/dist/strategies/trailing-stop.d.ts +2 -1
- package/dist/strategies/trailing-stop.js +52 -6
- package/dist/strategies/twap.d.ts +6 -1
- package/dist/strategies/twap.js +39 -11
- package/dist/trade-validator.d.ts +22 -0
- package/dist/trade-validator.js +119 -15
- package/dist/utils/numeric.d.ts +46 -0
- package/dist/utils/numeric.js +79 -0
- package/dist/utils.d.ts +19 -0
- package/dist/utils.js +96 -19
- package/dist/withdraw-gate.d.ts +49 -0
- package/dist/withdraw-gate.js +131 -0
- package/package.json +15 -6
- package/skills/perp-cli/SKILL.md +142 -55
- package/skills/perp-cli/references/agent-operations.md +110 -56
- package/skills/perp-cli/references/commands.md +266 -71
- package/skills/perp-cli/references/strategies.md +34 -31
- package/skills/perp-cli/scripts/arb-monitor.sh +10 -5
- package/skills/perp-cli/scripts/funding-analysis.sh +14 -9
- package/skills/perp-cli/scripts/preflight.sh +21 -14
- package/skills/perp-cli/scripts/spot-perp-scan.sh +12 -7
- package/skills/perp-cli/scripts/validate-arb.sh +31 -15
- package/vendor/lighter-signer/SHA256SUMS +2 -0
- package/vendor/lighter-signer/VERSION +8 -0
- package/vendor/lighter-signer/lighter-signer.wasm +0 -0
- package/vendor/lighter-signer/wasm_exec.js +575 -0
- package/dist/bot/strategies/funding-arb-v2-strategy.d.ts +0 -42
- package/dist/bot/strategies/funding-arb-v2-strategy.js +0 -864
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Withdraw gate for venues whose withdrawals are authorized by an API key alone — no owner
|
|
3
|
+
* signature (settings.withdraw.<venue>; today: qfex). Design §14.12 #8.
|
|
4
|
+
*
|
|
5
|
+
* Before such a withdrawal is sent it must pass, locally:
|
|
6
|
+
* 1. a gate is configured at all (absent → refused);
|
|
7
|
+
* 2. the destination is on the allowlist;
|
|
8
|
+
* 3. amount ≤ maxPerTx;
|
|
9
|
+
* 4. today's total (UTC day, from this machine's ledger) + amount ≤ maxPerDay.
|
|
10
|
+
* The adapter enforces it inside withdraw(), so no caller can skip it.
|
|
11
|
+
*
|
|
12
|
+
* What it is NOT: a defence against key theft. Someone holding the key file does not use this
|
|
13
|
+
* CLI. That defence is a trading key WITHOUT the withdraw permission (a separate key for
|
|
14
|
+
* funding). The gate limits mistakes and misdirected automation: its allowlist can only be
|
|
15
|
+
* changed with an interactive terminal confirmation (confirmWithdrawGateChange), never under
|
|
16
|
+
* --json, a pipe, the MCP server or a job.
|
|
17
|
+
*
|
|
18
|
+
* Ledger: ~/.perp/withdraw-ledger.json — amounts and addresses only (no secrets, Rule #3).
|
|
19
|
+
* An attempt is recorded BEFORE it is sent and removed only on a definite refusal, so an
|
|
20
|
+
* unknown outcome counts against the day.
|
|
21
|
+
*/
|
|
22
|
+
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
23
|
+
import { resolve } from "node:path";
|
|
24
|
+
import { randomUUID } from "node:crypto";
|
|
25
|
+
import { writeKeystoreAtomic } from "./agent-wallet/venue-keystore.js";
|
|
26
|
+
import { PerpError } from "./errors.js";
|
|
27
|
+
function ledgerPath() {
|
|
28
|
+
const home = process.env["HOME"];
|
|
29
|
+
if (!home)
|
|
30
|
+
throw new PerpError("INVALID_PARAMS", "HOME is not set; cannot locate ~/.perp/withdraw-ledger.json");
|
|
31
|
+
return resolve(home, ".perp", "withdraw-ledger.json");
|
|
32
|
+
}
|
|
33
|
+
function readLedger() {
|
|
34
|
+
const path = ledgerPath();
|
|
35
|
+
if (!existsSync(path))
|
|
36
|
+
return []; // nothing withdrawn from this machine yet
|
|
37
|
+
let parsed;
|
|
38
|
+
try {
|
|
39
|
+
parsed = JSON.parse(readFileSync(path, "utf-8"));
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
throw new PerpError("INVALID_PARAMS", `Invalid ${path}: not valid JSON (${e instanceof Error ? e.message : String(e)})`, {
|
|
43
|
+
remediation: `The daily withdraw total cannot be computed, so withdrawals are refused. Inspect ${path}; move it aside only after checking today's withdrawals on the venue`,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (!Array.isArray(parsed) || parsed.some(e => e === null || typeof e !== "object" || typeof e.id !== "string" || typeof e.venue !== "string"
|
|
47
|
+
|| typeof e.network !== "string" || typeof e.amount !== "string" || !Number.isFinite(Number(e.amount)) || typeof e.to !== "string" || !Number.isFinite(Date.parse(e.at)))) {
|
|
48
|
+
throw new PerpError("INVALID_PARAMS", `Invalid ${path}: not a list of withdraw entries`, {
|
|
49
|
+
remediation: `The daily withdraw total cannot be computed, so withdrawals are refused. Inspect ${path}`,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return parsed;
|
|
53
|
+
}
|
|
54
|
+
function writeLedger(entries) {
|
|
55
|
+
const path = ledgerPath();
|
|
56
|
+
const dir = resolve(path, "..");
|
|
57
|
+
if (!existsSync(dir))
|
|
58
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
59
|
+
writeKeystoreAtomic(path, JSON.stringify(entries, null, 2));
|
|
60
|
+
}
|
|
61
|
+
function utcDay(ms) {
|
|
62
|
+
return new Date(ms).toISOString().slice(0, 10);
|
|
63
|
+
}
|
|
64
|
+
/** Sum of the amounts attempted for venue + network on the UTC day of `nowMs`. */
|
|
65
|
+
export function withdrawnOnDay(venue, network, nowMs) {
|
|
66
|
+
const day = utcDay(nowMs);
|
|
67
|
+
return readLedger()
|
|
68
|
+
.filter(e => e.venue === venue && e.network === network && e.at.slice(0, 10) === day)
|
|
69
|
+
.reduce((sum, e) => sum + Number(e.amount), 0);
|
|
70
|
+
}
|
|
71
|
+
function denied(venue, why, remediation, details) {
|
|
72
|
+
return new PerpError("POLICY_DENIED", `${venue} withdraw refused by the local withdraw gate: ${why}`, { exchange: venue, ...details, remediation });
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Throws POLICY_DENIED unless the withdrawal passes `gate`. Nothing is sent before this returns.
|
|
76
|
+
* `gate` null = settings.withdraw.<venue> is not configured.
|
|
77
|
+
*/
|
|
78
|
+
export function assertWithdrawAllowed(venue, network, amount, to, gate, nowMs) {
|
|
79
|
+
const setHint = `Configure it in an interactive terminal: perp settings set withdraw.${venue} <address[+address…]>,<maxPerTx>,<maxPerDay>`;
|
|
80
|
+
if (gate === null) {
|
|
81
|
+
throw denied(venue, `settings.withdraw.${venue} is not configured — API-key withdrawals are off until you set an allowlist and limits`, setHint, {});
|
|
82
|
+
}
|
|
83
|
+
const n = Number(amount);
|
|
84
|
+
if (!Number.isFinite(n) || n <= 0)
|
|
85
|
+
throw new PerpError("INVALID_PARAMS", `Withdraw amount must be a positive decimal (got "${amount}")`);
|
|
86
|
+
if (!gate.allowlist.includes(to.toLowerCase())) {
|
|
87
|
+
throw denied(venue, `destination ${to} is not on the allowlist`, `Withdraw to an allowlisted address, or change the allowlist yourself. ${setHint}`, { allowlist: gate.allowlist });
|
|
88
|
+
}
|
|
89
|
+
if (n > gate.maxPerTx) {
|
|
90
|
+
throw denied(venue, `amount ${amount} exceeds maxPerTx ${gate.maxPerTx}`, `Withdraw at most ${gate.maxPerTx} USDC per transaction, or raise the limit. ${setHint}`, { maxPerTx: gate.maxPerTx });
|
|
91
|
+
}
|
|
92
|
+
const today = withdrawnOnDay(venue, network, nowMs);
|
|
93
|
+
if (today + n > gate.maxPerDay) {
|
|
94
|
+
throw denied(venue, `amount ${amount} plus ${today} already attempted today (UTC) exceeds maxPerDay ${gate.maxPerDay}`, `Wait for the next UTC day or raise the limit. ${setHint}`, { maxPerDay: gate.maxPerDay, withdrawnToday: today });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** Record an attempt (call BEFORE sending). Returns its id for forgetWithdrawAttempt. */
|
|
98
|
+
export function recordWithdrawAttempt(venue, network, amount, to, nowMs) {
|
|
99
|
+
const entries = readLedger();
|
|
100
|
+
const id = randomUUID();
|
|
101
|
+
entries.push({ id, venue, network, amount, to: to.toLowerCase(), at: new Date(nowMs).toISOString() });
|
|
102
|
+
writeLedger(entries);
|
|
103
|
+
return id;
|
|
104
|
+
}
|
|
105
|
+
/** Remove an attempt the venue DEFINITELY refused (nothing left the account). */
|
|
106
|
+
export function forgetWithdrawAttempt(id) {
|
|
107
|
+
writeLedger(readLedger().filter(e => e.id !== id));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Confirmation for creating or changing settings.withdraw.<venue>. Only an interactive
|
|
111
|
+
* terminal can confirm: --json, a non-TTY stdin/stdout (pipes, the MCP server, jobs) are
|
|
112
|
+
* refused, and there is no --yes.
|
|
113
|
+
*/
|
|
114
|
+
export async function confirmWithdrawGateChange(venue, gate, json) {
|
|
115
|
+
const what = `withdraw.${venue}: allow withdrawals to ${gate.allowlist.join(", ")} — up to ${gate.maxPerTx} USDC per transaction, ${gate.maxPerDay} USDC per UTC day`;
|
|
116
|
+
if (json || process.stdin.isTTY !== true || process.stdout.isTTY !== true) {
|
|
117
|
+
throw new PerpError("POLICY_DENIED", `Changing the withdraw gate needs an interactive terminal confirmation (${what})`, {
|
|
118
|
+
remediation: `Run it yourself in a terminal, without --json: perp settings set withdraw.${venue} <address[+address…]>,<maxPerTx>,<maxPerDay>`,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
const { createInterface } = await import("node:readline/promises");
|
|
122
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
123
|
+
try {
|
|
124
|
+
const a = (await rl.question(` ${what}.\n Anyone who can run perp on this machine can then withdraw to these addresses. Type the venue name (${venue}) to confirm: `)).trim().toLowerCase();
|
|
125
|
+
if (a !== venue)
|
|
126
|
+
throw new PerpError("INVALID_PARAMS", `withdraw.${venue} not changed — cancelled, nothing was saved`);
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
rl.close();
|
|
130
|
+
}
|
|
131
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "perp-cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Multi-DEX Perpetual Futures CLI - Pacifica, Hyperliquid, Lighter, Aster",
|
|
3
|
+
"version": "0.14.0",
|
|
4
|
+
"description": "Multi-DEX Perpetual Futures CLI - Pacifica, Hyperliquid, Lighter, Aster, Lighter RH, Ondo Perps, Arcus",
|
|
5
5
|
"bin": {
|
|
6
6
|
"perp": "dist/index.js",
|
|
7
7
|
"perp-mcp": "dist/mcp-server.js",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
|
12
|
-
"skills"
|
|
12
|
+
"skills",
|
|
13
|
+
"vendor/lighter-signer"
|
|
13
14
|
],
|
|
14
15
|
"type": "module",
|
|
15
16
|
"scripts": {
|
|
@@ -18,6 +19,9 @@
|
|
|
18
19
|
"test": "vitest run --exclude '**/integration/**'",
|
|
19
20
|
"test:integration": "vitest run -c vitest.integration.config.ts",
|
|
20
21
|
"test:all": "vitest run",
|
|
22
|
+
"e2e": "tsx scripts/e2e/run.ts",
|
|
23
|
+
"e2e:typecheck": "tsc -p scripts/e2e/tsconfig.json",
|
|
24
|
+
"typecheck:test": "tsc -p tsconfig.test.json",
|
|
21
25
|
"sync-skill-version": "node scripts/sync-skill-version.mjs",
|
|
22
26
|
"prepublishOnly": "node scripts/sync-skill-version.mjs && pnpm run build"
|
|
23
27
|
},
|
|
@@ -25,6 +29,12 @@
|
|
|
25
29
|
"pacifica",
|
|
26
30
|
"hyperliquid",
|
|
27
31
|
"lighter",
|
|
32
|
+
"aster",
|
|
33
|
+
"lighter-rh",
|
|
34
|
+
"robinhood-chain",
|
|
35
|
+
"ondo",
|
|
36
|
+
"ondo-perps",
|
|
37
|
+
"arcus",
|
|
28
38
|
"solana",
|
|
29
39
|
"perps",
|
|
30
40
|
"dex",
|
|
@@ -56,11 +66,9 @@
|
|
|
56
66
|
"commander": "^13.1.0",
|
|
57
67
|
"dotenv": "^16.5.0",
|
|
58
68
|
"ethers": "^6.13.2",
|
|
59
|
-
"hyperliquid": "^1.7.7",
|
|
60
69
|
"ink": "^6.8.0",
|
|
61
70
|
"ink-spinner": "^5.0.0",
|
|
62
71
|
"ink-table": "^3.1.0",
|
|
63
|
-
"lighter-ts-sdk": "1.0.10",
|
|
64
72
|
"react": "^19.2.4",
|
|
65
73
|
"tweetnacl": "^1.0.3",
|
|
66
74
|
"ws": "^8.19.0",
|
|
@@ -70,10 +78,11 @@
|
|
|
70
78
|
"devDependencies": {
|
|
71
79
|
"@types/node": "^25.3.3",
|
|
72
80
|
"@types/ws": "^8.18.1",
|
|
81
|
+
"@vitest/coverage-v8": "^4.1.6",
|
|
73
82
|
"ts-morph": "^27.0.2",
|
|
74
83
|
"tsup": "^8.4.0",
|
|
75
84
|
"tsx": "^4.21.0",
|
|
76
85
|
"typescript": "^5.7.0",
|
|
77
|
-
"vitest": "^4.
|
|
86
|
+
"vitest": "^4.1.6"
|
|
78
87
|
}
|
|
79
88
|
}
|
package/skills/perp-cli/SKILL.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: perp-cli
|
|
3
|
-
description: "Multi-DEX perpetual futures trading via the perp-cli command-line tool. Use when user asks to: trade perps, check funding rates, scan/execute arbitrage (perp-perp or spot-perp), run delta-neutral strategies, bridge USDC across chains, manage positions/orders/leverage, deposit/withdraw, hedge spot+perp, trade HIP-3 DEXes, or mentions perp-cli, hypurrquant, Pacifica, Hyperliquid, Lighter, Aster, HyperEVM, funding arb, or U-tokens (UBTC/UETH/USOL). Covers Pacifica (Solana), Hyperliquid (HyperEVM), Lighter (Ethereum),
|
|
3
|
+
description: "Multi-DEX perpetual futures trading via the perp-cli command-line tool. Use when user asks to: trade perps, check funding rates, scan/execute arbitrage (perp-perp or spot-perp), run delta-neutral strategies, bridge USDC across chains, manage positions/orders/leverage, deposit/withdraw, hedge spot+perp, trade HIP-3 DEXes, or mentions perp-cli, hypurrquant, Pacifica, Hyperliquid, Lighter, Aster, Lighter RH, Ondo Perps, Arcus, HyperEVM, funding arb, or U-tokens (UBTC/UETH/USOL). Covers Pacifica (Solana), Hyperliquid (HyperEVM), Lighter (Ethereum), Aster (BNB Chain), Lighter RH and Arcus (Robinhood chain) and Ondo Perps (off-chain)."
|
|
4
4
|
license: MIT
|
|
5
|
-
allowed-tools: "Bash(perp:*), Bash(npx perp-cli:*), Bash(
|
|
6
|
-
compatibility: "Requires Node.js 20 or newer and the perp-cli npm package (global install or npx). Network access required for exchange APIs and bridge providers. Mutating commands need wallet
|
|
5
|
+
allowed-tools: "Bash(perp:*), Bash(npx -y perp-cli:*), Bash(bash scripts/preflight.sh:*), Bash(bash scripts/arb-monitor.sh:*), Bash(bash scripts/funding-analysis.sh:*), Bash(bash scripts/spot-perp-scan.sh:*), Bash(bash scripts/validate-arb.sh:*)"
|
|
6
|
+
compatibility: "Requires Node.js 20 or newer and the perp-cli npm package (global install or npx). Network access required for exchange APIs and bridge providers. Mutating commands need a wallet key imported into the OWS vault via 'perp wallet set EXCHANGE' (key on stdin or hidden prompt — never argv). Skill is portable across Claude Code, Claude.ai, Cursor, Codex, and Gemini CLI — no platform-specific features."
|
|
7
7
|
metadata:
|
|
8
8
|
author: hypurrquant
|
|
9
|
-
version: "0.
|
|
9
|
+
version: "0.14.0"
|
|
10
10
|
---
|
|
11
11
|
|
|
12
12
|
# perp-cli
|
|
13
13
|
|
|
14
|
-
Multi-DEX perpetual futures CLI + MCP server for Pacifica (Solana), Hyperliquid (HyperEVM), Lighter (Ethereum),
|
|
14
|
+
Multi-DEX perpetual futures CLI + MCP server for Pacifica (Solana), Hyperliquid (HyperEVM), Lighter (Ethereum), Aster (BNB Chain), Lighter RH (`lighter-rh`, Robinhood chain, USDG), Ondo Perps (`ondo`), QFEX (`qfex`, custodial TradFi perps — import-only API key; resting reduce-only limits and automation are refused for now, see "QFEX" below), Arcus (`arcus`, Robinhood chain, USDG). v0.13.0+ also supports Hyperliquid Outcome markets (HIP-4) — fully-collateralized binary/range contracts; each outcome's quote token comes from `outcomeMeta.quoteToken` (USDC on every listed outcome as of 2026-10-12), minimum order value 10 quote tokens.
|
|
15
15
|
|
|
16
16
|
## Instructions
|
|
17
17
|
|
|
@@ -25,7 +25,7 @@ Activate whenever the user wants to do anything against perp-cli, including: sca
|
|
|
25
25
|
|
|
26
26
|
This skill uses progressive disclosure. Read these on demand:
|
|
27
27
|
|
|
28
|
-
- `references/commands.md` — full command tree for every group (market, account, trade, arb, funds, wallet, risk, history, strategy, background, alerts, settings, backtest)
|
|
28
|
+
- `references/commands.md` — full command tree for every group (market, account, trade, outcome, arb, funds, wallet, risk, history, strategy, background, alerts, settings, backtest)
|
|
29
29
|
- `references/agent-operations.md` — non-interactive setup flows, idempotency rules, error codes, common mistakes
|
|
30
30
|
- `references/strategies.md` — funding-arb decision framework + risk-management playbook (read before designing arb strategy)
|
|
31
31
|
|
|
@@ -33,40 +33,70 @@ Also bundled under `scripts/`: `preflight.sh`, `arb-monitor.sh`, `funding-analys
|
|
|
33
33
|
|
|
34
34
|
### Critical rules
|
|
35
35
|
|
|
36
|
-
1. **Always pass `--json`.** Without it, output is human-formatted and hard to parse.
|
|
37
|
-
2. **Always
|
|
38
|
-
3. **Always
|
|
39
|
-
4. **
|
|
40
|
-
5. **
|
|
41
|
-
6. **NEVER
|
|
42
|
-
7. **NEVER
|
|
36
|
+
1. **Always pass `--json`.** Without it, output is human-formatted and hard to parse. `ok:false` also exits 1.
|
|
37
|
+
2. **Always pass `-e <venue>`** on venue-scoped commands. The default is `settings.defaultExchange`, else `pacifica` — never rely on it.
|
|
38
|
+
3. **Always run `--dry-run` first** for any mutating command that supports it (`--help` says "supports --dry-run"). Show the result, get user confirmation, then execute without `--dry-run`. Commands without dry-run support refuse `--dry-run` with `INVALID_PARAMS` (see "Safety rules").
|
|
39
|
+
4. **Always use `--fields`** when you only need specific data — saves tokens.
|
|
40
|
+
5. **Avoid bare `perp setup` / `perp init` / `perp wallet setup`** — they prompt and will hang an agent. Use `printf '%s' "$KEY" | OWS_PASSPHRASE=<pp> perp --json wallet set <exchange>` for key registration (key on stdin; a key on argv or `-k` is rejected), or `perp --json setup --non-interactive --wallet <ows-wallet> --venues <list> [--default-venue <v>] [--slippage-bps <n>] [--slippage <venue>=<bps>]` (new wallet: `--wallet-name <name>` with the passphrase in `OWS_PASSPHRASE`; agent registration only with `--approve-agents --yes`, after user confirmation) (and `OWS_PASSPHRASE=<pp> perp wallet setup --name <n> --max-tx-usd <usd> --max-daily-usd <usd>`) when the wizard is required. The passphrase goes in `OWS_PASSPHRASE` or stdin — the root `--passphrase` flag is deprecated (visible in `ps`).
|
|
41
|
+
6. **NEVER trade without explicit user confirmation.** A dry-run is not consent.
|
|
42
|
+
7. **NEVER read `~/.perp/.env` or other key files.** The CLI reads them — you should not.
|
|
43
|
+
8. **NEVER manually add `-PERP` suffix** to symbols. Use bare names (`BTC`, `SOL`, `ICP`); the CLI resolves exchange-specific naming.
|
|
44
|
+
9. **NEVER resubmit after `ORDER_PENDING`** (or any unknown outcome). See "Safety rules".
|
|
43
45
|
|
|
44
46
|
### Step 1: Verify install + version
|
|
45
47
|
|
|
46
48
|
```bash
|
|
47
|
-
perp --version 2>/dev/null
|
|
48
|
-
npm install -g perp-cli@latest 2>/dev/null || npx -y perp-cli@latest --json --version
|
|
49
|
+
perp --version 2>/dev/null || npx -y perp-cli@latest --version # must be >= 0.14.0
|
|
49
50
|
```
|
|
50
51
|
|
|
51
|
-
If `perp` is not on PATH, prefix every command with `npx -y perp-cli@latest`.
|
|
52
|
+
If it is missing or older, ask the user before installing/upgrading (`npm install -g perp-cli@latest`) — never install on your own. If `perp` is not on PATH, prefix every command with `npx -y perp-cli@latest`.
|
|
52
53
|
|
|
53
54
|
### Step 2: Verify wallet + balance
|
|
54
55
|
|
|
55
56
|
```bash
|
|
56
57
|
perp --json wallet show # confirms configured exchanges
|
|
57
|
-
perp --json -e <
|
|
58
|
+
perp --json portfolio -e <venue-id> # per-exchange USDC available; full id (hyperliquid, not hl) — portfolio rejects aliases
|
|
58
59
|
```
|
|
59
60
|
|
|
60
61
|
If any required exchange is missing, register it (user supplies the key):
|
|
61
62
|
|
|
62
63
|
```bash
|
|
63
|
-
perp --json wallet set
|
|
64
|
-
perp --json wallet set
|
|
65
|
-
perp --json wallet set lt <EVM_HEX_KEY> # Lighter (auto-generates API key, default index 4)
|
|
66
|
-
perp --json wallet set aster <ASTER_API_KEY> # Aster (BNB Chain)
|
|
64
|
+
printf '%s' "$EVM_HEX_KEY" | OWS_PASSPHRASE=<pp> perp --json wallet set hl # Hyperliquid / Lighter / Aster (EVM)
|
|
65
|
+
printf '%s' "$SOLANA_BASE58_KEY" | OWS_PASSPHRASE=<pp> perp --json wallet set pac # Pacifica (Solana)
|
|
67
66
|
```
|
|
68
67
|
|
|
69
|
-
The same EVM key works for
|
|
68
|
+
The key is read from stdin (never argv — an argv key is rejected) and imported into the OWS vault; the imported wallet becomes `owsActiveWallet`, which serves every venue. The same EVM key works for Hyperliquid, Lighter and Aster. Lighter trading additionally needs `perp wallet agent approve lighter`.
|
|
69
|
+
|
|
70
|
+
Lighter RH / Ondo Perps / Arcus have no `wallet set` path — register an agent / API key (user runs it; Ondo reads key id + secret from stdin):
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
perp --json wallet agent approve lighter-rh
|
|
74
|
+
printf '%s\n%s\n' "$KEY_ID" "$SECRET" | perp --json wallet agent approve ondo
|
|
75
|
+
perp --json wallet agent approve arcus --master <ows-wallet> # address must be on the Arcus access whitelist
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**No master wallet on this computer?** The user can create the agent / API key on the exchange website and import it — key on stdin only, verified against the venue before it is stored (`verification.status` is `"unverified"` only for Pacifica, which lists bindings master-signed only):
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
printf '%s' "$AGENT_KEY" | perp --json wallet agent import hyperliquid # master read from HL
|
|
82
|
+
printf '%s' "$AGENT_KEY" | perp --json wallet agent import aster --master-address 0x… # also Aster testnet
|
|
83
|
+
printf '%s' "$AGENT_KEY" | perp --json wallet agent import pacifica --master-address <SOL>
|
|
84
|
+
printf '%s' "$API_KEY" | perp --json wallet agent import lighter --account-index <n> --api-key-index <slot>
|
|
85
|
+
printf '%s' "$ED25519_KEY" | perp --json wallet agent import arcus --master-address 0x…
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Imported keys trade; `funds deposit|withdraw|transfer|bridge`, `wallet manage referral set` and `wallet agent approve` need the master → `NO_SIGNER_AVAILABLE` (tell the user to do it on the website or `perp wallet import` the master). `wallet agent revoke` of an imported key needs `--local-only` and does NOT revoke it on the exchange; `rotate` is refused (new key on the website → `import --replace`).
|
|
89
|
+
|
|
90
|
+
**QFEX** (`-e qfex`, testnet = QFEX UAT): keys are created on the QFEX website and imported by the USER (`perp wallet agent import qfex [--account-id <uuid>]` — the resolved account UUID must be confirmed). Rules an agent must follow:
|
|
91
|
+
- Works: market / IOC reduce-only closes (`trade close/close-all/flatten/reduce`), reduce-only stop-market orders (`trade stop`, `trade tpsl` TP/SL legs, `--tp/--sl` as separate stops after the verified fill; cancel with `trade cancel <S> <id>` or `trade cancel-stop`), `trade edit` of a plain LIMIT / ALO (the venue assigns a new order id; the client id is kept).
|
|
92
|
+
- Refused with `CAPABILITY_UNSUPPORTED` (do not work around): resting reduce-only limits (GTC / ALO / FOK, `scale-tp`), stop-limit and opening stops, amend of a reduce-only order, `--client-id`, non-USD-quoted markets, unattended automation (bots / plans / TWAP / DCA / grid / background jobs), QFEX as a funding-arb / funding-bot leg.
|
|
93
|
+
- After a close, reduce-only / stop orders left on a now-flat symbol are listed as a WARNING (the venue does not cancel them) — cancel them, or use `trade flatten`, which cancels them.
|
|
94
|
+
- Limit GTC / ALO returns `status: accepted, finality: pending` after the ACK; `open` only via `perp --json trade status c:<id> --symbol <S> -e qfex`.
|
|
95
|
+
- `ORDER_PENDING` = outcome unknown: NEVER resubmit; check with the `c:<id>` in the remediation.
|
|
96
|
+
- Funding rates on QFEX are unverified: excluded everywhere unless `perp --json arb scan --rates --include-unverified` (display only).
|
|
97
|
+
- Withdrawals need `settings.withdraw.qfex` (allowlist + limits), which only the user can set in an interactive terminal — an agent cannot set or change it. `perp --json --dry-run funds withdraw qfex <amt> --to <addr>` shows the gate verdict.
|
|
98
|
+
|
|
99
|
+
Venue rules for these: `trade limit` defaults to `--tif GTC` on every venue (arcus maps it to GTT; ondo offers GTC|IOC|ALO; FOK is never emulated → `CAPABILITY_UNSUPPORTED` where not offered); market orders on every venue are bounded by `--slippage-bps <n>` → `settings.slippageBps.<venue>` → `settings.defaultSlippageBps` (shipped default 50). Ondo (US, PA) and Arcus (US, CA, GB) print a one-time restricted-region notice on stderr when used with credentials (warn only, never blocks).
|
|
70
100
|
|
|
71
101
|
### Step 3: Discover (read-only)
|
|
72
102
|
|
|
@@ -91,8 +121,8 @@ Common knobs: `--min <pct>`, `--top <n>`, `--hold-days <n>`, `--bridge-cost <usd
|
|
|
91
121
|
For arb:
|
|
92
122
|
|
|
93
123
|
```bash
|
|
94
|
-
perp --json -e <longEx>
|
|
95
|
-
perp --json -e <shortEx>
|
|
124
|
+
perp --json portfolio -e <longEx> # check available USDC (long leg)
|
|
125
|
+
perp --json portfolio -e <shortEx> # check available USDC (short leg)
|
|
96
126
|
perp --json --dry-run arb exec <SYM> <longEx> <shortEx> <USD>
|
|
97
127
|
```
|
|
98
128
|
|
|
@@ -104,6 +134,8 @@ perp --json --dry-run -e <ex> trade buy <SYM> <SIZE> --smart
|
|
|
104
134
|
```
|
|
105
135
|
|
|
106
136
|
> `trade check` does NOT read exchange-set leverage. Always pass `--leverage` explicitly.
|
|
137
|
+
>
|
|
138
|
+
> `--smart` (IOC at best bid/ask ± 1 tick) exists only on pacifica / hyperliquid / lighter / aster, and is refused (`CAPABILITY_UNSUPPORTED`) together with `--tp`/`--sl` or `--client-id`/`--auto-id`.
|
|
107
139
|
|
|
108
140
|
Show the dry-run output to the user. Wait for confirmation.
|
|
109
141
|
|
|
@@ -112,10 +144,12 @@ Show the dry-run output to the user. Wait for confirmation.
|
|
|
112
144
|
After explicit user confirmation:
|
|
113
145
|
|
|
114
146
|
```bash
|
|
115
|
-
# Perp-perp arb
|
|
116
|
-
|
|
147
|
+
# Perp-perp arb: legs are SEQUENTIAL — long first, then the short sized to the verified long fill;
|
|
148
|
+
# reconcile is always on (the long is trimmed reduce-only to the short's verified fill).
|
|
149
|
+
# An unconfirmed leg quarantines the symbol (see "Safety rules").
|
|
150
|
+
perp --json arb exec <SYM> <longEx> <shortEx> <USD> --smart
|
|
117
151
|
|
|
118
|
-
# Spot+perp arb (spot has 0 funding cost; spot
|
|
152
|
+
# Spot+perp arb (spot has 0 funding cost; spot:<venue> = hl, lt, lrh, aster, ondo)
|
|
119
153
|
perp --json arb exec <SYM> spot:hl hl <USD>
|
|
120
154
|
perp --json arb exec <SYM> spot:lt pac <USD>
|
|
121
155
|
|
|
@@ -147,6 +181,8 @@ perp --json arb close <SYM> # perp-perp arb
|
|
|
147
181
|
perp --json arb close <SYM> --pair <longEx>:<shortEx> # disambiguate
|
|
148
182
|
perp --json arb close <SYM> --spot-exch hl --perp-exch hl # spot+perp
|
|
149
183
|
perp --json arb close <SYM> --smart # IOC limits
|
|
184
|
+
perp --json arb close <SYM> --force # quarantined symbol — only after the user checked positions
|
|
185
|
+
perp --json arb close <SYM> --state-only --yes # drop a stale state entry (arb status staleStateEntries); sends no order
|
|
150
186
|
|
|
151
187
|
# Single trade
|
|
152
188
|
perp --json -e <ex> trade close <SYM> # close one symbol
|
|
@@ -164,27 +200,37 @@ perp --json funds deposit hyperliquid 100
|
|
|
164
200
|
perp --json funds deposit pacifica 100
|
|
165
201
|
perp --json funds deposit lighter ethereum 100 # L1 direct
|
|
166
202
|
perp --json funds deposit lighter cctp arbitrum 100 # via CCTP
|
|
167
|
-
perp --json funds withdraw hyperliquid 100
|
|
168
|
-
perp --json funds transfer 100 <ADDRESS> # HL internal (instant)
|
|
203
|
+
perp --json funds withdraw hyperliquid 100 [--chain arbitrum|ethereum|base] # CCTP to your own wallet
|
|
204
|
+
perp --json funds transfer 100 <ADDRESS> # HL internal (instant) — allowlisted destinations only
|
|
169
205
|
|
|
170
206
|
# Cross-chain bridge (auto-cheapest cctp/relay/debridge)
|
|
171
207
|
perp --json funds bridge quote --from solana --to arbitrum --amount 100
|
|
172
208
|
perp --json funds bridge send --from solana --to arbitrum --amount 100
|
|
173
209
|
perp --json funds bridge status <orderId> # poll until success
|
|
174
210
|
|
|
175
|
-
# Inter-exchange rebalance
|
|
211
|
+
# Inter-exchange rebalance
|
|
176
212
|
perp --json funds rebalance check
|
|
177
213
|
perp --json funds rebalance plan
|
|
178
|
-
perp --json funds rebalance execute --auto-bridge
|
|
214
|
+
perp --json --dry-run funds rebalance execute --auto-bridge # status "simulated" (moves[].status "dry_run"), or "balanced" (nothing to move)
|
|
215
|
+
perp --json funds rebalance execute --auto-bridge # withdraw → bridge ONLY; no deposit
|
|
179
216
|
```
|
|
180
217
|
|
|
181
218
|
Always run `funds bridge quote` before `funds bridge send` so the user sees fees + ETA.
|
|
182
219
|
|
|
220
|
+
- `funds rebalance execute` returns `ok:true` even when a move failed: check EVERY `moves[].status` (`withdrawn`, `bridged`, `same_chain`, `needs_bridge`, `withdraw_failed`, `bridge_failed`). It never deposits — after the bridge arrives, deposit manually (`funds deposit <venue> <amt>`).
|
|
221
|
+
- `funds transfer <amt> <addr>` (HL) and `funds withdraw hyperliquid --to <other address>` require the destination on the `settings withdraw.hyperliquid` allowlist (`POLICY_DENIED` otherwise). Only the user can set it, in an interactive terminal (`--json` / piped → `POLICY_DENIED`). NEVER try to set or change `withdraw.<venue>` yourself.
|
|
222
|
+
- HL withdraw goes over CCTP (native USDC); on Arbitrum a 0.2 USDC forwarding fee is deducted (an amount ≤ the fee → `SIZE_TOO_SMALL`).
|
|
223
|
+
- Bridges: exactly `--amount` leaves the wallet (fees come out of it); a deBridge `nativeFee` is shown separately and is paid in the source chain's native token. Solana-origin deBridge is refused (`NO_BRIDGE_ROUTE`) → `--provider cctp`. `--fast` = fast CCTP finality (higher fee).
|
|
224
|
+
- `funds bridge exchange --from <ex> --to <ex>` bridges the master wallet's OWN USDC between the venues' chains (pacifica → solana, lighter → arbitrum); it does NOT withdraw from / deposit into Pacifica or Lighter. Exception hyperliquid: `--from hyperliquid` spends HyperCore spot USDC, `--to hyperliquid` credits HyperCore perps. HyperCore → Solana is refused (`NO_BRIDGE_ROUTE`).
|
|
225
|
+
|
|
226
|
+
Relay swaps between assets (`--from-asset` / `--to-asset`, chains `robinhood`, `arbitrum`, `bsc`, `base`, destination `solana`): run `perp --json --dry-run funds bridge send ...` first — it prints the locally verified quote (amount in, expected out, protocol-guaranteed minimum, fees, ETA) and the min-out verdict without loading a key. Stable → native (e.g. USDG → SOL / ETH) needs `--min-out`. The recipient is always the master wallet's own address; an `ORDER_PENDING` result carries the Relay request id — never bridge again before checking it.
|
|
227
|
+
|
|
183
228
|
### Strategy engine (20 algorithms + scripted plans)
|
|
184
229
|
|
|
185
230
|
```bash
|
|
186
231
|
perp strategy list-strategies # 20 registered
|
|
187
|
-
perp strategy run <strategy> [symbol] # run any strategy
|
|
232
|
+
perp strategy run <strategy> [symbol] # run any strategy (multi-venue: --exchanges must include the -e venue)
|
|
233
|
+
perp --json --dry-run strategy run <strategy> [symbol] # simulate: actions logged, never sent
|
|
188
234
|
perp strategy apex [symbol] # APEX orchestrator
|
|
189
235
|
perp strategy reflect # performance analysis
|
|
190
236
|
perp --json strategy plan validate <FILE> # validate scripted plan
|
|
@@ -196,17 +242,22 @@ perp --json strategy plan execute <FILE> --dry-run # dry-run scripted
|
|
|
196
242
|
Background daemon (tmux):
|
|
197
243
|
|
|
198
244
|
```bash
|
|
245
|
+
perp --json --dry-run arb auto --min-spread 30 --size 100 # simulate first (--background inherits --dry-run)
|
|
199
246
|
perp --json arb auto --min-spread 30 --size 100 --background
|
|
200
247
|
perp --json background list
|
|
201
248
|
perp --json background logs <id> -f
|
|
202
|
-
perp --json background stop <id>
|
|
249
|
+
perp --json background stop <id> [--timeout 90] # graceful: SIGINT, job cancels its orders, waits, reports what is left on the venue
|
|
203
250
|
```
|
|
204
251
|
|
|
252
|
+
`strategy funding-arb` is monitor-only unless `--auto-execute`. Bots: `equity` is `null` when a balance read fails — arb strategies then skip new entries and the bot stops after 10 consecutive unknown ticks; `ordersPlaced` counts orders sent, `fills` only venue-reported fills — a resting order is placed, not filled.
|
|
253
|
+
|
|
254
|
+
Background jobs inherit the parent's `-n`, `--dry-run`, `-e`, `--ows`, `-w`, `--no-agent`, `--dex`, and never receive key material (argv/env): they resolve credentials from the OWS vault / agent keystores / `~/.perp/.env` themselves. `--background` with `-k`, `--passphrase`, `--ows-key` or a shell-exported key / `OWS_PASSPHRASE` → `INVALID_PARAMS` — register an agent (`perp wallet agent approve <venue>`), which signs without the master passphrase.
|
|
255
|
+
|
|
205
256
|
### Position sizing & safety
|
|
206
257
|
|
|
207
258
|
- Single position notional < **80%** of that exchange's available balance.
|
|
208
259
|
- Leverage 1–3x for arb; never above 5x for arb positions.
|
|
209
|
-
- `arb exec`
|
|
260
|
+
- `arb exec` sizes the short to the verified long fill and always reconciles; still check `arb status` (`unconfirmedPairs`, `staleStateEntries`) afterwards.
|
|
210
261
|
- ALWAYS follow `longExch`/`shortExch` from `arb scan` — NEVER reverse direction.
|
|
211
262
|
- NEVER enter if `netSpread <= 0` or `netSpread < estimated round-trip slippage`.
|
|
212
263
|
- Capital that's mid-bridge is "at risk" and unhedged — factor it in.
|
|
@@ -222,8 +273,8 @@ For deeper risk-management framework, read `references/strategies.md`.
|
|
|
222
273
|
perp --json arb scan --min 10 --top 10
|
|
223
274
|
# 2. Show top 3 to user; ask which to evaluate
|
|
224
275
|
# 3. Check balances on the two exchanges
|
|
225
|
-
perp --json -e <longEx>
|
|
226
|
-
perp --json -e <shortEx>
|
|
276
|
+
perp --json portfolio -e <longEx>
|
|
277
|
+
perp --json portfolio -e <shortEx>
|
|
227
278
|
# 4. Recommend size + dry-run
|
|
228
279
|
perp --json --dry-run arb exec BTC <longEx> <shortEx> 100
|
|
229
280
|
# 5. After user confirmation:
|
|
@@ -265,16 +316,13 @@ perp --json funds bridge status <orderId> # poll until completed
|
|
|
265
316
|
perp --json funds deposit hyperliquid 500
|
|
266
317
|
```
|
|
267
318
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
```bash
|
|
271
|
-
perp --json funds rebalance plan
|
|
272
|
-
perp --json funds rebalance execute --auto-bridge
|
|
273
|
-
```
|
|
319
|
+
`funds rebalance execute --auto-bridge` only withdraws and bridges — check every `moves[].status`, then deposit by hand (`funds deposit hyperliquid <amt>`) after the bridge arrives.
|
|
274
320
|
|
|
275
321
|
### Example 5: "Run a delta-neutral funding bot in background"
|
|
276
322
|
|
|
277
323
|
```bash
|
|
324
|
+
perp --json --dry-run arb auto --min-spread 30 --close-spread 5 --size 100 --max-positions 5
|
|
325
|
+
# → show the simulation, ask confirmation
|
|
278
326
|
perp --json arb auto --min-spread 30 --close-spread 5 --size 100 --max-positions 5 --background
|
|
279
327
|
perp --json background list
|
|
280
328
|
perp --json background logs <id> -f
|
|
@@ -284,17 +332,40 @@ perp --json background stop <id>
|
|
|
284
332
|
|
|
285
333
|
## Troubleshooting
|
|
286
334
|
|
|
287
|
-
Every response is `{ "ok": true, "data": ... }` or `{ "ok": false, "error": { "code": "...", "retryable": true|false } }
|
|
335
|
+
Every response is `{ "ok": true, "data": ... }` or `{ "ok": false, "error": { "code": "...", "retryable": true|false, "remediation"?: "..." } }`; `ok:false` exits 1. Always check `ok` first and follow `error.remediation`. `retryable: true` → wait and retry ONCE, and only for read-only commands — a write is never blindly retried.
|
|
288
336
|
|
|
289
337
|
| Error code | Meaning | Action |
|
|
290
338
|
|---|---|---|
|
|
291
|
-
| `
|
|
292
|
-
| `
|
|
293
|
-
| `
|
|
294
|
-
| `
|
|
295
|
-
| `
|
|
296
|
-
| `
|
|
297
|
-
| `
|
|
339
|
+
| `ORDER_PENDING` | A write was sent, outcome unknown | NEVER resubmit. See "Safety rules". |
|
|
340
|
+
| `ORDER_PARTIAL` | Part of a multi-leg / close succeeded | Don't retry; check positions per venue, close residuals by hand (may be quarantined). |
|
|
341
|
+
| `ORDER_REJECTED` / `ACTION_REJECTED` | Definitely not placed / not executed | Fix the cause from `error.message`; a new attempt is a new decision (ask the user). |
|
|
342
|
+
| `RISK_VIOLATION` | Local risk limit breached, or symbol quarantined | Report to the user. `--force` only with explicit user consent, and never bypasses quarantine. |
|
|
343
|
+
| `CAPABILITY_UNSUPPORTED` | Venue/feature combination not offered | Do NOT work around it (no emulation via other orders/venues); tell the user. |
|
|
344
|
+
| `INVALID_TICK` | Limit/trigger price off the venue grid (HL: ≤ 5 significant figures) | Refused, never rounded — re-price on the grid and confirm with the user. |
|
|
345
|
+
| `INVALID_PARAMS` | Bad argument (incl. strict sizes: `1,000` / `1e3` / `10abc` refused; `--dry-run` on a command without dry-run) | Fix the argument. |
|
|
346
|
+
| `CLI_ERROR` | Command parse error (unknown command / missing option) | Check `<cmd> --help`. |
|
|
347
|
+
| `NO_SIGNER_AVAILABLE` | No key that may sign this (e.g. imported agent key for a master-only action) | User does it on the website, or `perp wallet import`s the master. |
|
|
348
|
+
| `AGENT_NOT_REGISTERED` / `AGENT_EXPIRED` | Agent key missing, on the other network, or expired | Follow `remediation`: master on this computer → `perp wallet agent approve <venue> [--rotate]` (master-signed: user consent); imported key → new key on the website, `wallet agent import <venue> --replace`. |
|
|
349
|
+
| `POLICY_DENIED` | Local withdraw gate / OWS policy refused | Never change `withdraw.<venue>` — only the user can, in a terminal. |
|
|
350
|
+
| `PASSPHRASE_REQUIRED` | Vault passphrase needed | Ask the user to provide `OWS_PASSPHRASE` (or stdin); never put it on argv. |
|
|
351
|
+
| `LOCK_HELD` | Another perp process holds a state lock | Wait ~5s and retry once; check `background list`. |
|
|
352
|
+
| `NO_BRIDGE_ROUTE` | No supported bridge route (e.g. deBridge from Solana, HyperCore → Solana) | Use the route in `remediation` (e.g. `--provider cctp`). |
|
|
353
|
+
| `RATE_LIMITED` / `EXCHANGE_UNREACHABLE` | Throttled / API down (reads) | Wait 5–10s, retry once; then skip that venue. |
|
|
354
|
+
| `INSUFFICIENT_BALANCE` | Not enough collateral on that venue | Reduce size or move funds first (user-confirmed). |
|
|
355
|
+
| `SYMBOL_NOT_FOUND` | Not listed on this venue | `market list`. Don't add `-PERP`. |
|
|
356
|
+
| `SIZE_TOO_SMALL` | Below venue minimum (HL TWAP: $100 total) | Compute `size × price`; raise size. |
|
|
357
|
+
|
|
358
|
+
`--client-id` (`trade market/buy/sell/limit`): an id already recorded in `~/.perp/client-ids.jsonl` (and not marked failed) returns `ok:true` with `data.duplicate: true` and sends nothing — local tracking only, not a venue check (it is NOT a `DUPLICATE_ORDER` error). Formats: Pacifica a full UUID, Hyperliquid `0x` + 32 hex; QFEX refuses `--client-id` (use `--auto-id`); `--smart` + client id → `CAPABILITY_UNSUPPORTED`.
|
|
359
|
+
|
|
360
|
+
## Safety rules
|
|
361
|
+
|
|
362
|
+
- **Unknown outcome (`ORDER_PENDING`) on ANY write** — orders, cancels, edits, leverage, withdraw / deposit / bridge / transfer: do NOT resubmit. Check `perp --json -e <ex> trade status c:<id> --symbol <S>` (the id in `remediation`), `account orders` / `account positions` / `portfolio`, and the tx hash / request id in `error.details` (`funds bridge status <id>` for bridges). Report to the user.
|
|
363
|
+
- **Quarantine**: an unknown or unhedged outcome (arb, bots, `trade close`, `trade multi`) quarantines the symbol — global per symbol, scoped by network. It blocks opening orders, `arb exec`, `arb auto` and bots (`RISK_VIOLATION`); reduce-only orders pass. List: `perp --json strategy quarantine`. Clear only after the USER has verified the positions on the venues: `perp --json strategy quarantine-clear <SYM>`. `arb close` on a quarantined symbol needs `--force`.
|
|
364
|
+
- **Risk gate**: `trade market / buy / sell / limit / split / market --split / scale-in / twap / multi / stop --no-reduce-only` check `~/.perp/risk.json` (`perp risk limits ...`); reduce-only is exempt. `--force` bypasses the limits (never quarantine) — only with explicit user consent.
|
|
365
|
+
- **Stops** (`trade stop`, `tpsl`) are reduce-only by default; `--no-reduce-only` is refused on ondo and qfex. `trade tpsl <SYM> long|short` = the OPEN position's side; legs are sized to the live position.
|
|
366
|
+
- **Dry-run is default-deny**: commands that cannot simulate refuse `--dry-run` with `INVALID_PARAMS` (e.g. `trade twap`, `trade multi`, `trade cancel-stop`, `trade cancel-twap`, `strategy start / preset / grid / dca / quick-* / funding-arb`, `wallet agent approve`, `wallet rotate`). Simulate bots with `perp --json --dry-run strategy run <strategy>` / `perp --json --dry-run arb auto`.
|
|
367
|
+
- **A dry-run is not a full venue check**: it validates arguments, the risk gate and quarantine, but some venue rules are enforced only on the live send — e.g. an off-grid limit price (`INVALID_TICK`) or `--no-reduce-only` on ondo / qfex (`CAPABILITY_UNSUPPORTED`). Those refusals happen before anything is sent.
|
|
368
|
+
- **`wallet rotate`** creates a new wallet and transfers assets, with no dry-run — only on the user's explicit request.
|
|
298
369
|
|
|
299
370
|
### Common mistakes
|
|
300
371
|
|
|
@@ -311,16 +382,32 @@ For a full troubleshooting + non-interactive flow guide, read `references/agent-
|
|
|
311
382
|
## Referrals (optional, ask once per setup)
|
|
312
383
|
|
|
313
384
|
```bash
|
|
314
|
-
perp --json
|
|
315
|
-
perp --json
|
|
385
|
+
perp --json --dry-run -e hyperliquid wallet manage referral set # preview (nothing signed)
|
|
386
|
+
perp --json -e hyperliquid wallet manage referral set [code] # signs + sends ONE referral action
|
|
387
|
+
perp --json -e lighter wallet manage referral set [code] # Lighter (needs an agent key)
|
|
316
388
|
```
|
|
317
389
|
|
|
318
|
-
When the user first sets up a wallet, ask:
|
|
319
|
-
> "perp-cli development is supported by optional referrals.
|
|
390
|
+
Referral codes are never applied implicitly (adapter creation signs nothing). When the user first sets up a wallet, ask:
|
|
391
|
+
> "perp-cli development is supported by optional referrals. Apply the referral code? It signs one referral action on the venue; no extra fees — only exchange rebates are used."
|
|
392
|
+
|
|
393
|
+
## Builder fees (OFF by default — never enable on your own)
|
|
394
|
+
|
|
395
|
+
Builder fees are extra fees on the USER's perp orders, paid to a third-party builder. perp-cli attaches none unless the user explicitly set `settings builder.<venue>` AND the venue approval is confirmed. Do not configure or approve a builder unless the user asks for it.
|
|
396
|
+
|
|
397
|
+
```bash
|
|
398
|
+
perp --json wallet builder status [venue] # support, config, approval, attaches?
|
|
399
|
+
perp --json --dry-run wallet builder approve <venue> # plan only — show it to the user
|
|
400
|
+
perp --json wallet builder approve <venue> --yes # only after explicit user consent (master-signed)
|
|
401
|
+
perp --json --no-builder -e <ex> trade market BTC buy 0.1 # one run without the fee
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
qfex: `builder.qfex <uuid>` is a fee share (no extra fee, no approval; mainnet only). Unsupported: lighter, lighter-rh, arcus (`CAPABILITY_UNSUPPORTED`). An order whose approval is missing or unknown is sent without the fee (`execution.notes`); `execution.builderFee` records what was attached.
|
|
320
405
|
|
|
321
406
|
## MCP Server
|
|
322
407
|
|
|
323
|
-
The package also ships a
|
|
408
|
+
The package also ships a 22-tool MCP server (no API keys required for read-only market data — `get_markets`, `get_orderbook`, `get_funding_rates`, `get_prices`, `get_outcome_markets`, `get_outcome_view`, `get_outcome_book`, plus 15 account/advisor tools):
|
|
409
|
+
|
|
410
|
+
MCP network: `PERP_NETWORK=mainnet|testnet` (validated; unset = mainnet); every result's `meta.network` says which. The only write tools, `trade_execute` / `trade_close`, run the same local risk gate as `perp trade` (no override over MCP), refuse non-reduce-only orders on quarantined symbols, and log every order.
|
|
324
411
|
|
|
325
412
|
```json
|
|
326
413
|
{
|