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.

You completed the Quickstart: a single predict function and trepa.bots.run around it. This page explains what Trepa does between rounds, what the optional second argument ctx is for on one account, how hooks work, and how to stop the loop cleanly.

What predict does

Trepa calls predict whenever a pool is ready. Return { value, stake } to submit (value is your forecast, stake is USDC). Return null to skip that round.
await trepa.bots.run({
  predict: (pool) => ({
    value: 65_000,
    stake: pool.min_stake,
  }),
})
Your function can be async when you need network or disk.
await trepa.bots.run({
  predict: async (pool) => {
    const res = await fetch(
      'https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT',
    )
    const { price } = (await res.json()) as { price: string }
    return { value: Number(price), stake: pool.min_stake }
  },
})
When predict throws, the error is logged and the loop continues.

The second argument (ctx)

You can write predict as (pool) only. Add ctx when you need the signed-in user or extra Trepa calls inside predict:
  • ctx.me is the Trepa user for this bot.
  • ctx.trepa is the Trepa client for that same user.
await trepa.bots.run({
  predict: async (pool, ctx) => {
    const stats = await ctx.trepa.users.statistics(ctx.me.id)
    return {
      value: 65_000,
      stake: pool.min_stake,
    }
  },
})

Optional hooks

Pass callbacks next to predict when you want your own logging or side effects. They are always optional.
HookWhen it runs
onStartRight after this bot signs in.
onPredictedAfter a forecast is submitted successfully.
onPoolSkippedWhen the bot does not submit for that turn.
onErrorWhen the loop recovers from a problem.
await trepa.bots.run({
  predict: (pool) => ({ value: 65_000, stake: pool.min_stake }),
  onPredicted: ({ pool, value }) => `${pool.title}: ${value}`,
})

Shutdown

Ctrl+C in the terminal stops the bot and signs sessions out.

Example in the repo

spot-bot: One bot submitting the current BTC spot price (from Binance) for every open Bitcoin pool. Next: Swarms.
Last modified on May 2, 2026