Spending limits vs private keys vs exchange API keys for trading bots
There are three common ways to let a bot or an AI agent trade for you. They differ in who holds your funds, how much the bot can lose and how quickly you can stop it.
The comparison
| Private key in the bot | Exchange API key | On-chain spending limit | |
|---|---|---|---|
| Who holds the funds | You, but the bot can take everything | The exchange | You |
| Maximum loss | The whole wallet | Everything on the exchange account, unless withdrawals are disabled | The daily cap per allowed token |
| Scope | None | Trading on / withdrawals off, sometimes per market | Per token, per day, until a date |
| Revocation | Move all funds to a new wallet | Delete the key in the exchange's settings | One transaction |
| Where the output goes | Anywhere the bot decides | The exchange account | Only your wallet |
| Counterparty risk | None | The exchange itself | None beyond the exchanges the contract already uses |
| Works with | Any bot | Bots written for that exchange | Any bot that can call a contract or use the Hopivia API |
When each makes sense
A private key is acceptable only for a throwaway wallet that holds exactly the amount you are willing to lose. That is in effect a manual spending limit, with the inconvenience of topping it up.
An exchange API key is the norm for centralized trading. It is well understood, but it keeps your funds on the exchange, and the exchange can freeze, limit or lose them.
An on-chain spending limit keeps the funds in your own wallet and lets a contract enforce the rules. The agent trades at the best available price across decentralized exchanges, the output always returns to you, and revocation is a single transaction. The cost is that the agent pays gas for every trade and the strategy is limited to the tokens and networks where the contract is deployed.
How Hopivia implements limits
The wallet owner allows an agent's address for specific tokens with a daily cap and an expiry. The agent calls the contract's swap function with its own wallet; the contract pulls the input from the owner's wallet, swaps on one of the exchanges in its fixed list and sends the output to the owner. The contract has no owner or admin functions. Details are in the guide on limited access for AI agents and in the API documentation.
FAQ
Is an on-chain limit safer than an exchange API key with withdrawals disabled?
They protect against different things. The exchange key protects against withdrawals but not against the exchange itself. The on-chain limit protects against the bot and keeps the funds in your wallet, but a careless bot can still lose up to the cap through bad trades.
Can I combine approaches?
Yes. Many people keep a small on-chain budget for an AI agent to experiment with and leave the main holdings untouched.
Does a spending limit cost anything to set up?
Two transactions on the network: a token allowance and the limit itself. Afterwards the agent pays the gas of each trade.
Updated: