Running a crypto trading bot with a daily spending limit
A trading bot does not need unlimited access to a wallet. Most strategies touch a few tokens and a predictable amount per day. This guide shows how to run such a bot through Hopivia so that the limit is enforced by a smart contract rather than by the bot's own good behaviour.
Three strategies that fit a daily limit
Dollar-cost averaging. The bot buys a fixed amount of an asset every day or every hour. Allow the stablecoin it sells and the asset it buys, set the daily cap to the daily budget, and the bot physically cannot buy more.
Rebalancing. An assistant checks the portfolio once a week and moves a few percent between assets. Allow the assets involved and set the cap to the largest expected move.
Take-profit or stop orders. The bot sells an asset when the price reaches a level. Allow that asset and the stablecoin, and cap the daily amount at the position size you want to sell per day.
Sizing the limit
- Daily cap is the most the bot can sell of a token in one UTC day. Treat it as the most you are prepared to lose in one day if the bot goes wrong.
- Expiry is the end of the experiment. One month for a new strategy is a reasonable default; extending is one transaction.
- Allowance is set automatically to "daily cap × days until expiry", so the total exposure over the whole period is bounded too.
- Tokens are per agent. Two bots with different strategies get two separate limits on two separate addresses.
What the bot does on every run
- Asks the Hopivia API for a quote:
GET /quotereturns the best exchange, the route and the minimum output after slippage. - Checks the remaining daily budget with the contract's
limitOfview. If the budget is used up, it waits for the reset at 00:00 UTC. - Calls the contract's
swapfunction with its own wallet, passing the route from the quote and the minimum output. The contract pulls the input from your wallet, executes the trade and sends the output to you.
The same flow is available as tools in the Hopivia MCP server, so an assistant such as Claude or Cursor can run it without custom code.
Monitoring
The AI agents page shows every agent you allowed, each token's cap, how much was spent today and when the limit expires. Every swap emits an on-chain event with the agent, the tokens and the amounts, so you can also watch the contract in a block explorer or subscribe to events from your own scripts.
Stopping the bot
- Remove one token from the agent's limits, and that token stops immediately.
- Revoke the agent, and every limit for that address is deleted in one transaction.
- Let the limit expire, and the bot stops on its own on that date.
None of these require moving funds, changing wallets or contacting anyone.
FAQ
Does the bot need my funds in its own wallet?
No. The funds stay in your wallet until the moment of the swap. The bot's wallet only needs enough of the network coin to pay gas.
Can the bot trade on any exchange?
Only on the exchanges in the contract's fixed list. The quote from the Hopivia API tells the bot which routes are eligible.
What if the price moves against the bot?
The bot passes a minimum output with every swap. If the exchange cannot deliver at least that amount, the transaction reverts and nothing is spent.
Can I run the bot on several networks?
Each network has its own deployment of the contract and its own limits. Set them up separately on each network where the contract is live.
Updated: