Skip to content

Agents

A program can trade every Sagitta market from a wallet of its own. There are four ways in, from the most hands-on to the most automatic:

Tool What it is
@sagitta/sdk The TypeScript library the site itself uses: reads, local quotes and transaction builders
The trading API GET /api/arena for a wallet’s holdings, the market list and open upkeep; POST /api/arena for transactions to sign
sagitta.mjs A command-line client: one command per action, one JSON object per result
nash.mjs A player that runs on its own, explaining each trade it makes

Every one of them signs on your own machine with your own key. Your key never goes to a Sagitta server, and Sagitta’s keeper signs its upkeep with a key of its own. POST /api/arena answers with transactions for you to sign. The CLIs build and check every transaction themselves.

Every call to the API counts against a budget of calls per 60 seconds (see Limits):

Budget Who Calls per 60 seconds
Without a key Anyone else, counted per IP address (an IPv6 address by its /48) 2
With a key A free API key sent with the call, counted per key wherever the calls come from 30
The site sagitta.broker’s own pages, with a site token 300

A key belongs to a wallet address and costs a signature, nothing else. Signing sends no transaction and costs no gas. Getting a key takes two calls, which fit in the budget without one:

  1. GET /api/keys/challenge?address=<your address> answers with a message to sign. It names the API’s domain, the chain id (99901), your address, a single-use nonce and an expiry five minutes away, in the Sign-In with Ethereum format.
  2. Sign the message exactly as given with personal_sign (EIP-191), then send POST /api/keys with { "address": "0x…", "message": "<the message>", "signature": "0x…" }.

The answer holds the key, which starts sk_sag_, and it is shown this once: the API keeps only a SHA-256 hash of it. It also gives prefix (sk_sag_ and the next 8 characters, safe to show), address, tier (key), limit, window_s, created_at, and rotated, which is true when the address’s previous key stopped working just then.

With viem, the whole exchange is a few lines:

import { privateKeyToAccount } from "viem/accounts";
const API = "https://api.sagitta.broker";
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const challenge = await fetch(`${API}/api/keys/challenge?address=${account.address}`).then((r) => r.json());
const signature = await account.signMessage({ message: challenge.message }); // personal_sign
const issued = await fetch(`${API}/api/keys`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ address: account.address, message: challenge.message, signature }),
}).then((r) => r.json());
// issued.key is shown this once: keep it somewhere only you can read

Sending it. Pass the key with every call as Authorization: Bearer <key>, or as X-Api-Key: <key>:

Terminal window
curl -s -H "Authorization: Bearer $SAGITTA_API_KEY" "https://api.sagitta.broker/api/arena?keeper=1"
  • One key per address. Asking again rotates it: the new key works at once and the old one stops.
  • Revoking. Ask for a challenge with &purpose=revoke, sign it, and send the same body to DELETE /api/keys. The key stops working at once, and the answer is { address, revoked, prefix }.
  • A bad key is refused, not ignored. A key that was revoked, replaced or never issued gets 401 with the reason. Send a valid key, or none for the budget without one.
  • How many. At most 3 keys a day per IP address and 3 per wallet address; rotating a key counts.
  • Abuse. A key the operators revoke also stops its address getting a new one, until they lift it. Revoking your own key does not.
  • The key endpoints always count against the budget without a key, from your IP address, whatever else the call carries.

node sagitta.mjs key does all of this with the CLI’s wallet and keeps the key in ~/.sagitta/api-key. What the API stores for a key is listed under API keys on the privacy page.

The API reads the chain and builds transactions; it never signs them. Every answer below is JSON, and every transaction comes back unsigned for the wallet named as payer to sign and send through any Elysium endpoint. The reference has every field and an example of each.

GET /api/arena takes one query, which picks the view:

Query What it answers
?list=1 { markets }: every market, the same rows as /api/markets
?who=0x… One wallet’s book: hype, positions (each with its market, ticker, side, symbol, units and worth_hype, what a cash-out pays now), positions_hype, pending tickets, pending_hype, owed_hype (what claim pays out) and equity_hype
?keeper=1 Open upkeep: each market’s poke, execute (matured tickets and their bounty_hype), silent, retire, barrier, accrued_burn_hype and reclaim, then burn, and how, what each chore does in words

When several are given, list wins, then keeper and who. A pending ticket carries its id, kind (mint or redeem), hype or shares, committed_at and matured (anyone can execute it now).

Two more reads suit programs:

POST /api/arena takes a JSON body with a kind and the payer, the wallet that will sign and pay for the transaction. A market is named by its address, a side token’s address, its relayed feed’s address, its slug (tslax, sol-usd), a stock token’s symbol (TSLAx), its ticker or a side symbol such as TSLAUP. A stock market’s side symbols carry the underlying’s ticker, so every market on that ticker shares them, whichever issuer’s token it follows. When a name matches several markets, the error lists each one’s address, so you can name the one you mean. side is UP or DOWN in any case, and amounts may be numbers or decimal strings.

kind Body, beyond kind and payer What it builds
buy market, side, hype; optional recipient (who gets the shares) and referrer commitMint: the ticket fills at the side’s NAV at the first reading after the commit, less the 4% fee
sell market, side; optional pct of the holding (100 when left out) and recipient commitRedeem of the current-epoch shares, filled the same way, less 4%
execute market; optional max tickets (a call fills at most 64) and bounty_to execute(max, bounty_to): fills the tickets whose reading has arrived, for the executor bounty
poke market; optional bounty_to poke(), which applies the latest reading, or execute({P.pokeTickets}, bounty_to) when bounty_to is given
claim optional account (the payer when left out) Pays out the HYPE a market owes the account: bounties, referral fees, refunds
retire market retire(), once governance has sunset the market or its version: mints close at once, and it freezes at the first reading after the call

Each answer is { tx: { to, data, value, chainId }, summary }. value is wei as a decimal string, and summary.kind repeats the request’s kind:

kind summary, beyond kind
buy ticker, market, side, symbol, hype, fee_hype, expect_tokens and nav_hype (at the NAV now; the fill uses the NAV at the first reading after the commit), leverage, recipient, referrer, matures, risk
sell ticker, market, side, symbol, units, pct, expect_hype (at the NAV now, after the fee), fee_hype, recipient, matures
execute ticker, market, matured, bounty_hype
poke ticker, market, pending (the move it applies)
claim account, owed_hype
retire ticker, market, freezes

A buy, for example:

Terminal window
curl -s https://api.sagitta.broker/api/arena \
-H "Authorization: Bearer $SAGITTA_API_KEY" -H "content-type: application/json" \
-d '{ "kind": "buy", "payer": "0xa11ce00000000000000000000000000000000001", "market": "TSLAx", "side": "UP", "hype": 0.1 }'
{
"tx": { "to": "0x…", "data": "0x…", "value": "100000000000000000", "chainId": 99901 },
"summary": {
"kind": "buy",
"ticker": "TSLA",
"side": "UP",
"hype": 0.1,
"fee_hype": 0.004,
"expect_tokens": 96.2,
"matures": "fills at the first reading after this commit"
}
}

(The summary is shortened here.) Before it answers, the API checks every address the transaction pays against the chain, with the same payee guard the site uses. A request it can’t build gets 400 with the reason in words: not enough HYPE, nothing to sell, nothing owed, or a market that isn’t retirable.

Check before you sign. An API that answered wrongly could hand you a wrong transaction, so a program that trades for real checks what it signs: chainId is 99901, to is the market you meant, and value is what the summary says. Or it builds the same transaction locally with the SDK, whose verifyTx checks it against the chain, as the CLIs do.

?who= and every POST read the chain for the caller, so each costs more than one unit of a budget the API keeps per IP address for chain reads, inside the limits above. Past it the answer is 429 with Retry-After and { "error": "slow down" }.

The SDK reads markets, tickets and holdings in one batched call, quotes buys and cash-outs with the contracts’ own arithmetic, and builds every trading and upkeep call as a transaction for you to sign.

Each builder names every address the transaction pays, and refuses one that could never collect: another market, a side token of any epoch, or a Sagitta contract. verifyTx then checks the transaction against the chain before you sign it. See the payee guard.

One file, run by Node 18 or newer, with viem and the SDK’s builders, quotes and payee guard bundled inside: there is nothing to install.

Terminal window
mkdir -p ~/sagitta && cd ~/sagitta
curl -fsSLO https://sagitta.broker/cli/sagitta.mjs
curl -fsSLO https://sagitta.broker/cli/SHA256SUMS
shasum -a 256 -c --ignore-missing SHA256SUMS # must print "sagitta.mjs: OK"; if not, delete the file and don't run it
node sagitta.mjs wallet # creates ~/.sagitta/key.json and prints its address

Send a little HYPE on Elysium to the address it prints. The key file is the only copy of the key.

Terminal window
node sagitta.mjs key # a free API key for that address, kept in ~/.sagitta/api-key

key signs a challenge from the API with the same wallet and stores the API key it gets back, readable by you alone; both CLIs pass it with every API call from then on. Running it again replaces the key, and node sagitta.mjs key revoke stops it working. SAGITTA_API_KEY names another key, or a file holding one; no key is ever printed.

Terminal window
node sagitta.mjs markets # every board, stocks first
node sagitta.mjs buy TSLAx UP 0.1 # put 0.1 HYPE on TSLAx rising
node sagitta.mjs sell TSLAx UP 50 # cash out half of it
node sagitta.mjs balance # HYPE, holdings, open tickets, unclaimed HYPE
node sagitta.mjs claim # collect bounties and referral fees owed to you

How a trade travels:

  1. The CLI asks the API for the market list, then reads the market on chain through an RPC of its own (Elysium’s public RPC, or SAGITTA_RPC), and only keeps it if the pinned Sagitta Registry confirms it.
  2. It builds the commit with the SDK, checks every payee against the chain, simulates it, checks the chain id and keeps the fees and gas under their caps, then signs it with the local key and sends it to that RPC. Only the signed bytes leave the machine.
  3. The ticket fills at the first reading after the commit. The CLI waits for it; when the reading is in and nobody has executed the ticket after a few seconds, it executes it from your wallet and keeps the bounty.
  4. It prints the fill as a single JSON object on stdout. Progress lines go to stderr, so | jq works directly.

--no-wait returns as soon as the commit is mined, --to delivers the result to another wallet, and --ref credits a referrer. SAGITTA_KEY is a key file or the key itself (never printed), SAGITTA_API the API for lists and views, and SAGITTA_RPC the RPC for everything on chain. The Registry is pinned when the file is built; another chain or deployment takes an explicit SAGITTA_CHAIN with SAGITTA_RPC and SAGITTA_REGISTRY, and is announced on every run.

Without a key, each command makes at most two API calls, so it fits the budget, and a 429 from that budget is waited out for its Retry-After rather than treated as a failure. A key the API refuses stops the command with the reason: run key again, or unset SAGITTA_API_KEY to go without.

Upkeep is open to any wallet and pays a bounty (see Keepers):

Terminal window
node sagitta.mjs work # markets with tickets ready or a reading waiting
node sagitta.mjs execute TSLAx # fill the tickets whose reading has arrived
node sagitta.mjs poke TSLAx # apply the latest reading

The full command list, options and output fields are in sagitta.broker/cli/README.md.

nash.mjs uses the same key, RPC, pinned Registry and payee checks, and decides for itself. Download it next to sagitta.mjs:

Terminal window
curl -fsSLO https://sagitta.broker/cli/nash.mjs
curl -fsSLO https://sagitta.broker/cli/SHA256SUMS
shasum -a 256 -c --ignore-missing SHA256SUMS # must print "nash.mjs: OK"; if not, delete the file and don't run it
node nash.mjs # report what it would do, and trade nothing
node nash.mjs --loop 300 --live # trade, every five minutes

Each pass:

  1. Exits. Holdings it opened (and, with --adopt, any others) are sold when the pots have evened out, the opposing pot is almost empty, a profit or loss threshold is crossed, or a holding period runs out.
  2. The smaller pot. On each open market it looks at the side with less HYPE behind it, which earns the larger multiple. If the gap and the opposing pot are big enough, it enters and logs the expected value per HYPE: the chance of winning times the slice of the opposing pot it would collect, less the chance of losing times what its own stake would give up, less the 8% round trip. A move d hands over the fraction 1 − (1+d)^−100 of the losing pot (63% at 1%); NASH.md has the formula. Because a ticket fills after any move the market already has pending, the estimate uses the pots as they will stand once that move is applied.
  3. Upkeep. It executes ready tickets, applies readings and collects unclaimed HYPE, starting with markets it holds.

Each pass makes two API calls (one with --no-keeper); your HYPE, holdings and tickets are read from the chain. Without a key that allows a pass every 60 seconds (30 with --no-keeper), so a faster --loop is refused until node sagitta.mjs key has made one.

By default it favours turnover: full-size entries, and a rotation after --hold-min minutes. --no-volume sizes strictly and skips entries below an EV floor. It never takes the side with more HYPE behind it, and never holds both sides of a market. The details are in sagitta.broker/cli/NASH.md.