A separate Unseen Money Vault account for your bot. Its key can trade and withdraw this account, and nothing else.
API account
Your API account
A separate Unseen Money Vault account for your bot. It opens with your alias, from the same signature.
bot.mts
TypeScript, viem only
It buys the pool's smallest order at the market, stores a take-profit and a stop as a pair, cancels both and closes the position. MARKET=1 picks another market (0 is BTC). For stocks, set RELAYER and POOL to the stock relayer and pool under Endpoints, and MARKET=<stock id> from its /v2/markets.
// bot.mts: buys at the market, stores a take-profit and a stop as a pair, reads them back, cancels them and// closes the position, through Unseen Money Vault's relayer.// npm i viem, then: API_KEY=0x... node bot.mts (Node 22.18 or later, or npx tsx bot.mts)// MARKET=1 node bot.mts trades another market. GET /v2/markets lists them by id.import { formatUnits, type Hex } from "viem";import { privateKeyToAccount } from "viem/accounts";const RELAYER = "https://pool-production-964782a3.up.railway.app";const POOL = "0xdB793f57d351595072296b59A2fCD66e7f56532B"; // a signature is good for this pool only (checksummed: the signed read names it so)const MARKET = Number(process.env.MARKET ?? 0); // 0 is BTCconst account = privateKeyToAccount(process.env.API_KEY as Hex); // your API account's key// The pool's EIP-712 domain and types, exactly as the contract checks them.const domain = { name: "Unseen Perps", version: "2", chainId: 999, verifyingContract: POOL } as const;const orderTypes = { Order: [ { name: "account", type: "address" }, { name: "market", type: "uint32" }, { name: "isBuy", type: "bool" }, { name: "size", type: "uint64" }, { name: "limitPx", type: "uint64" }, { name: "reduceOnly", type: "bool" }, { name: "triggerPx", type: "uint64" }, { name: "triggerAbove", type: "bool" }, { name: "nonce", type: "uint64" }, { name: "deadline", type: "uint64" }, { name: "relayerFee", type: "uint256" }, { name: "relayer", type: "address" }, ],} as const;const cancelTypes = { CancelOrder: [ { name: "account", type: "address" }, { name: "nonce", type: "uint64" }, ],} as const;// JSON in and out. Every integer goes as a decimal string.async function get(path: string, headers: Record<string, string> = {}) { return (await fetch(RELAYER + path, { headers })).json();}async function post(path: string, body: object) { const res = await fetch(RELAYER + path, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body, (_, v) => (typeof v === "bigint" ? v.toString() : v)), }); const answer = await res.json(); if (!res.ok) throw new Error(res.status + " " + (answer.errorName ?? "") + " " + answer.error); return answer;}// Your stored orders are shown only to you: a read signed by your key, good for 5 minutes, in the x-unseen-read header.async function readHeader() { const at = Math.floor(Date.now() / 1000); const message = "Unseen Money relayer: read my orders\nchain 999\npool " + POOL + "\naccount " + account.address + "\nat " + at; return { "x-unseen-read": at + "." + (await account.signMessage({ message })) };}const now = () => BigInt(Math.floor(Date.now() / 1000));const nonce = () => crypto.getRandomValues(new BigUint64Array(1))[0]; // random, never used twice// The keeper sends every order to the pool. Each order names it as its relayer, so it alone can submit it.const { keeper } = await get("/v2/health");// The market as the keeper read it this second. A size is in lots (size × 10^szDecimals), a price in px// (price × 10^(6 - szDecimals)), so lots × px is a notional in usd6 (millionths of a dollar).async function quote() { const { params, markets } = await get("/v2/markets"); const m = markets.find((x: { asset: number }) => x.asset === MARKET); if (!m) throw new Error("Market " + MARKET + " is not listed on this pool."); return { params, szDecimals: m.market.szDecimals as number, mark: BigInt(m.markPx), bid: BigInt(m.bid), ask: BigInt(m.ask) };}// A market order's limit must allow twice the pool's band past the book (2 × bandBps), or the pool refuses it// (LimitNotMet). `extra` bps more cover the book moving before the order is in. The fill stays within one band of the// book, never past the limit.function marketLimit(q: Awaited<ReturnType<typeof quote>>, isBuy: boolean, extra = 25n): bigint { const room = 2n * BigInt(q.params.bandBps) + extra; if (isBuy) return ((q.ask > q.mark ? q.ask : q.mark) * (10_000n + room) + 9_999n) / 10_000n; return ((q.bid < q.mark ? q.bid : q.mark) * (10_000n - room)) / 10_000n;}// Signs an order and hands it to the relayer. With triggerPx 0 it goes now; with a trigger the relayer stores it// and sends it once Hyperliquid's mark reaches it.async function order(o: { isBuy: boolean; size: bigint; limitPx: bigint; reduceOnly?: boolean; triggerPx?: bigint; triggerAbove?: boolean; life?: bigint; group?: string }) { const message = { account: account.address, market: MARKET, isBuy: o.isBuy, size: o.size, limitPx: o.limitPx, reduceOnly: o.reduceOnly ?? false, triggerPx: o.triggerPx ?? 0n, triggerAbove: o.triggerAbove ?? false, nonce: nonce(), deadline: now() + (o.life ?? 300n), // at least 90 s after the pool takes it relayerFee: 0n, relayer: keeper, }; const signature = await account.signTypedData({ domain, types: orderTypes, primaryType: "Order", message }); const link = o.group ? { group: o.group } : undefined; return { ...(await post("/v2/orders", { order: message, signature, link })), nonce: message.nonce };}// The account: equity, free margin, positions and its pending order. One order is pending at a time: once// order.pending is false the last order is done, and the position shows its fill.async function settled() { for (;;) { const { state } = await get("/v2/account/" + account.address); if (state && !state.order.pending) return state; await new Promise((r) => setTimeout(r, 1_000)); }}const held = (state: { positions: { market: number; size: string }[] }) => BigInt(state.positions.find((p) => p.market === MARKET)?.size ?? 0);// 1. A size worth the pool's minimum order (minOrderUsd) at the mark and a quarter more, rounded up to a whole lot.let q = await quote();const size = (BigInt(q.params.minOrderUsd) * 125n / 100n + q.mark - 1n) / q.mark;const coins = (lots: bigint) => formatUnits(lots, q.szDecimals);const before = held(await settled());// 2. Buy at the market: { status: "submitted", hash }. It fills in the market's next batch, within seconds.console.log(await order({ isBuy: true, size, limitPx: marketLimit(q, true) }));const after = await settled();const bought = held(after) - before;if (bought <= 0n) throw new Error("Not filled: the book moved past the limit. Run it again.");console.log("bought " + coins(bought) + ", equity " + after.equity + " usd6, free " + after.free + " usd6");// 3. A take-profit 5% above the mark and a stop 5% below, each selling what was bought, reduce-only. The relayer stores// them until the mark gets there: { status: "stored" }. One group: once one of them fills, the other is dropped.const group = "bot-" + Date.now();const tpPx = (q.mark * 105n) / 100n;const slPx = (q.mark * 95n) / 100n;const tp = await order({ isBuy: false, size: bought, reduceOnly: true, triggerPx: tpPx, triggerAbove: true, limitPx: (tpPx * 95n) / 100n, life: 30n * 86_400n, group });const sl = await order({ isBuy: false, size: bought, reduceOnly: true, triggerPx: slPx, triggerAbove: false, limitPx: (slPx * 95n) / 100n, life: 30n * 86_400n, group });console.log(tp, sl);// 4. Read them back. Only a read signed by your key sees them, under triggers, with their tries and last error.const mine = await get("/v2/account/" + account.address, await readHeader());console.log("stored orders:", mine.triggers.length);// 5. Cancel both by nonce. Only cancelled: true means it can never run. ran: it ran first (see the account's history).// sent: a submit of it is out and may still fill until its deadline, so place no replacement before that is over.async function cancel(nonce: bigint) { const message = { account: account.address, nonce }; const signature = await account.signTypedData({ domain, types: cancelTypes, primaryType: "CancelOrder", message }); const answer = await post("/v2/orders/cancel", { ...message, signature }); if (answer.cancelled) return "cancelled"; if (answer.ran) return "it ran before the cancel"; if (answer.sent) return "a submit of it is out: it may still fill"; return "not stored: it ran, was dropped or expired";}console.log("take-profit:", await cancel(tp.nonce), "/ stop:", await cancel(sl.nonce));// 6. Close: the other side, reduce-only, priced from the book as it is now. A close needs no margin, so its limit can// leave more room (1.5%) at no cost.q = await quote();console.log(await order({ isBuy: false, size: bought, limitPx: marketLimit(q, false, 150n), reduceOnly: true }));const left = held(await settled());console.log(left === before ? "closed" : "still holding " + coins(left) + ": the close was not filled, run it again");
Set up your bot
1
Fund the account
Opens with your alias.
2
Copy the key
0x••••••••••••••••••••••••
It can trade and withdraw the API account. It can't reach your alias or your private balance.
Opens with your alias. The same wallet always opens the same key.
3
Run the quickstart
npm i viem, then API_KEY=0x… node bot.mts (Node 22.18 or later).
Every write is signed by the account. The relayer pays the gas.
Programmatic Execution & Deterministic API Signing Keys — Unseen Money
Automate private perpetual strategies on Unseen Money using deterministic API sub-keys, TypeScript SDK snippets, and low-latency signing. Built for traders who require institutional confidentiality on public decentralized order books, Unseen Money separates custody from trade execution through zero-knowledge note commitments and pooled smart-contract routing at https://unseenmoney.fun/api-trading.
How Unseen Money Protects Execution Privacy
Conventional decentralized perpetual exchanges expose every limit order, leverage ratio, liquidation price, and historical transfer on public block explorers. By anchoring collateral in an encrypted zero-knowledge vault and routing perpetual orders through a shared non-custodial execution pool, Unseen Money ensures market depth and settlement remain verifiable while personal wallet history stays decoupled from active market positions. All privacy keys and API signing credentials are derived deterministically inside your browser without server-side key custody. Collateral transfers pass through ephemeral one-time settlement addresses and verifiable zero-knowledge commitments, preventing balance clustering, wallet fingerprinting, and order-flow front-running while maintaining transparent smart-contract solvency and 48-hour public governance timelocks.
Frequently Asked Questions
How does Unseen Money prevent wallet tracking on perpetual markets?
Funds enter the shielded vault as cryptographic commitments spendable only with zero-knowledge nullifier proofs. When allocating margin to crypto or equity perpetual pools, a one-time bridge address transfers collateral so your original wallet never signs exchange orders.
Can operators move or freeze shielded collateral on Unseen Money?
No. Unseen Money smart contracts are non-custodial, source-verified, and governed by a transparent 48-hour public timelock. Only signatures derived from your local browser keys can authorize note transfers, trades, or withdrawals.
What assets and perpetual markets are supported?
Participants can shield HYPE and USDC collateral to trade high-liquidity crypto perpetuals (BTC, ETH, SOL, HYPE) as well as synthetic equity and index perpetual contracts from one unified private reserve.