Skip to main content
This page gives you a bot to copy. It reads the chain, quotes a trade, opens it, waits for the fill, closes it and prints what it was paid. It runs as a dry run until you tell it to send.

Set up

You need Node 20 or later, a Solana keypair file, a little SOL for fees, and USDC in the wallet.
The SDK is not on npm yet, so the install command below works from the first publish. The pages in this section describe its interface.
1. Make a project. The SDK is ESM-only, so the project needs "type": "module".
2. Make a keypair. Save this as keypair.ts and run npx tsx keypair.ts. It writes the secret key to keypair.json and prints only the public address. Keep that file out of version control and out of every prompt and log.
keypair.ts
3. Fund the address. Send about 0.01 SOL for fees, and USDC on Solana for the stake. Buy USDC at an exchange and withdraw it to that address on the Solana network, or swap SOL for USDC in a wallet and send it over. The first USDC deposit creates the token account the bot uses. The smallest stake is $0.20. See Fees and limits.

The bot

Save this as bot.ts.
bot.ts

Run it

Keep the RPC endpoint in an environment variable and out of your source and your logs. Endpoints from a provider carry a key in the URL.

What each step does

  1. Read the protocol. The config, the vault and the market are decoded from the chain. Nothing here is cached: every parameter is governed and can move.
  2. Quote. sizeForTotal turns the budget you hand the venue into a stake. openPreview says what it costs, the gross payout at the target (before the exit fee and the share of the gain the terms withhold) and what you receive at the barrier, which is nothing. Show the barrier line next to the button in anything a person uses.
  3. Open. The open is an order. The stake is taken when it lands, and the venue’s next price after a short delay fills it. A first trade creates your book in the same transaction. min_collateral_out is your floor on the stake, so a fee change in between reverts the open and never shrinks it.
  4. Wait for the fill. The order is filled, or it is returned and your whole stake comes back. A returned order is a normal outcome. The bot reads your book until it knows which. The handle of a position is its seq. A slot index is not a handle, because slots are reused.
  5. Close. A close is a request that carries no price. You cannot ask in the first slots after the entry, and closableFromSlotOf says which slot is the first. The venue’s keepers complete the close. Anyone may.
  6. Read the payout. Part of a win can be paid later, in order. The bot prints what was paid now. See how a win is paid.

When something is refused

The bot simulates before it sends, so a refusal costs nothing. It prints the name of the refusal and its retry class. Branch on the class and not on the name or the text: Error handling lists every refusal a client sees. Reading gates predicts them before you send.

Next

Orders and closes

The contract a bot builds against: fills, returns, close requests and the events for each.

Read the protocol

The read path on its own, with the oracle shape and the gate report.

Fees and limits

What a trade costs and the limits it meets. Dated, and they can change.

Build with an AI agent

The docs as an MCP server, llms.txt, and a skill file an agent can load.