Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.trepa.io/llms.txt

Use this file to discover all available pages before exploring further.

A swarm runs several bots together with one trepa.bots.run call. Each bot has its own Trepa login and wallet, but they share one script and stop together when you exit the process. The Writing bots page explains predict and ctx for a single account; here we wire up multiple accounts and per-bot behaviour. Typical reasons to use a swarm:
  • Several accounts, same pool: One prediction per wallet per pool; run many wallets from one program so they can all enter the same pool.
  • Outcome band: Different forecast per account around a band you choose (Different behaviour per bot, liquidity-bot).
  • Per-user levers: Separate stakes, streaks, near-close timing, or a canary account, coordinated in one run.
One Trepa account per bot. Trepa allows one prediction per account per pool. If several API keys all belong to the same Trepa user, only the first bot succeeds. The others hit a conflict and never land a prediction until you use separate Trepa accounts.For N parallel bots, create N Trepa accounts, create one API key per account, and pair each key with that account’s exported wallet private key.

Load several credential pairs

bots.run consumes one { apiKey, privateKey } object per bot. The usual pattern is numbered variables in .env, read by credentialsFromEnv():
TREPA_API_KEY_1=trp_…
TREPA_PRIVATE_KEY_1=
TREPA_API_KEY_2=trp_…
TREPA_PRIVATE_KEY_2=
import { credentialsFromEnv, Trepa } from '@trepa/sdk'

const trepa = new Trepa({ credentials: credentialsFromEnv() })
The helper loads _1, _2, _3, … until it hits a gap. A half pair (key without matching private key) throws at startup so you catch typos early. You can also build the array in code:
const trepa = new Trepa({
  credentials: [
    { apiKey: '...', privateKey: '...' },
    { apiKey: '...', privateKey: '...' },
  ],
})
Calls on the top-level trepa object (outside predict) use only the first credential in the list. Inside predict, use ctx.trepa when you need the client for that bot.

Different behaviour per bot

Pass a function into bots.run instead of a plain options object. The function receives index (which bot, starting at zero) and count (how many bots total). The snippet below assumes trepa already exists from the previous block.
await trepa.bots.run(({ index, count }) => ({
  predict: (pool) => {
    const fair = 96_000
    const spacing = 400
    return {
      value: fair + (index - (count - 1) / 2) * spacing,
      stake: pool.min_stake,
    }
  },
}))
Each index shifts the forecast along that ladder around fair. When every bot should behave the same, pass a normal options object instead of a function. Inside predict, ctx.slot repeats index and count if you prefer reading from ctx.

Per-bot Trepa client inside predict

The second argument ctx includes ctx.trepa scoped to that bot. Use it when a strategy needs that user’s prediction history, portfolio, or any other API call without mixing wallets.
await trepa.bots.run(() => ({
  predict: async (pool, ctx) => {
    const recent = await ctx.trepa.users.predictions(ctx.me.id, {
      limit: 1,
      sort_by: 'CREATION_DATE',
    })
    const last = recent[0]
    const value = last?.prediction ?? 90_000
    return {
      value,
      stake: pool.min_stake,
    }
  },
}))
Next: SDK reference.
Last modified on May 2, 2026