Skip to main content
This is the spine that ties the reference pages together. You’ll build a bot that watches a market, places a sized trade on a signal, verifies webhook events, tracks its positions, and claims its winnings after the market resolves. Everything here runs against staging (api-staging.kash.bot, Base Sepolia) — going live is the same code against api.kash.bot.
Use the @kashdao/sdk TypeScript client, not raw HTTP. It handles auth, retries, idempotency, typed errors, and webhook signature verification for you. Everything below is SDK-first; the one place you’ll drop to fetch is redemptions (not yet in the SDK — see step 8).Building on the self-orchestrated surface instead — you run your own signer / market-making infra? Use the Protocol SDK (and the Hummingbot connector). This tutorial is the managed REST path.

What you’ll build

A long-running loop that:
  1. Reads a market and quotes a position size.
  2. Places a trade with an idempotency key (safe to retry).
  3. Confirms the trade if it trips the high-value gate.
  4. Learns the outcome asynchronously via a signed webhook (or by polling).
  5. Tracks open positions.
  6. Redeems winnings once the market resolves.

1. Prerequisites

  • A Kash account — sign up at staging.kash.bot.
  • An API key with these scopes (see Authentication): markets:read, markets:quote, trades:read, trades:write, portfolio:read, webhooks:manage. Keys are created in the webapp (Settings → API Keys) and shown once — capture the plaintext. A kash_test_* key targets staging automatically.
  • Node 22+.

2. Construct the client

The SDK auto-routes to staging for a kash_test_ key and to production for a kash_live_ key — you don’t hard-code a base URL.

3. Read a market and quote

Pick a market, then quote before you trade so you size against real on-chain liquidity. amountUsdcAtomic is USDC in atomic units (6 decimals → 10_000_000 = 10 USDC).

4. Place a trade (idempotent)

Pass an idempotencyKey: if the request times out and your bot retries, you get the same trade back rather than a duplicate. The response carries idempotent: true when it’s a replay.
Reuse the same idempotencyKey for a given logical order across retries; generate a new one for each distinct order. See Idempotency.

5. Confirm high-value trades

Trades above your key’s per-trade threshold return a one-time confirmation token instead of executing immediately (the trade sits in pending_confirmation). Confirm it to release execution.

6. Learn the outcome — webhooks (preferred) or poll

Webhooks are the production path: Kash POSTs a signed event to your endpoint when the trade completes. Verify the signature with the SDK and dedupe on the event id — never trust an unverified body.
Prefer webhooks in production. For a script or a quick test, poll instead:
See Webhooks → Verifying for the full event catalog and signature scheme.

7. Track positions

positions is not paginated in v1 — it returns everything, filterable by marketId.

8. Claim winnings (redeem)

When a market resolves, your winning outcome tokens sit in your smart account until you claim them. Create a redemption for the (market, outcome) you hold; the existing payout pipeline settles it on-chain and your USDC balance increases.
Redemptions aren’t in @kashdao/sdk yet, so call the endpoint directly. It reuses your trades:write scope and is idempotent — one open claim per (market, outcome); a repeat returns the original with 200.
There is no redemption webhook. Detect settlement by polling GET /v1/portfolio until the USDC balance reflects the payout. See the POST /v1/redemptions reference and the POSITION_NOT_CLAIMABLE / REDEMPTIONS_NOT_ENABLED codes.

9. Handle errors and rate limits

Every failure is a typed KashError subclass — branch on the class, not the message.
See Rate limits and the Error catalogue.

10. Going live

  • Swap the key for a kash_live_* key — the SDK re-routes to api.kash.bot automatically.
  • Point webhook_url at your production endpoint and set the production KASH_WEBHOOK_SECRET.
  • Review rate limits for your tier and the webapp → REST migration notes.

See also

TypeScript SDK reference

Full @kashdao/sdk surface: clients, types, and error classes.

Endpoint reference

Every route, request/response shape, and status code.

Webhooks

Event catalog, signing scheme, retries, and secret rotation.

Protocol SDK (self-orchestrated)

Run your own signer / market-making infra instead of the managed REST path.