How to Build an AI Trading Bot (Code, No-Code and Agent Routes)
A trading bot follows rules written before the session. An AI trading bot either drafts those rules with a model or is an AI agent that calls tools for data and orders. This guide compares code, a no-code platform and an agent through the Model Context Protocol (MCP). It names tools and stays off platform scores and dollar results. Some bots lose money.
How to build a trading bot
To build a trading bot, write your strategy as exact rules, connect a market data source, backtest the rules on past data, connect an execution API that can place orders, and add risk limits that cap size and losses. You can code it, use a no-code platform, or run an AI agent through MCP.
The rest of this page follows those six steps.
- Choose a market and write the strategy as rules.
- Get market data.
- Backtest before you risk money.
- Connect execution.
- Add risk limits outside the strategy.
- Deploy, monitor and review.
The four parts of every trading bot
Every bot is four parts. The route changes the tool. A missing feed, a missing order path, or a missing cap means the bot is not finished.
| Part | What it does | Coded bot | No-code bot | AI agent + MCP |
|---|---|---|---|---|
| Data | Prices, order books, onchain flows, news | Exchange APIs or CCXT; RPC and indexers onchain | Feeds the platform includes | Data MCP servers the host calls |
| Strategy | Entry, exit and sizing rules | Functions you write and maintain | A template the platform offers | Plain-language rules you give the agent |
| Execution | Places and manages orders | Exchange, broker or onchain swap API | Hosted execution on the platform | Trading tools on an MCP server |
| Risk | Caps, stops, kill switch, logs | Checks in your process, plus the venue | Limits the platform enforces | Caps at the execution service, plus orders the agent places |
The six steps below fill the column for the route you pick.
Step 1: Choose a market and write the strategy as rules
Pick the market before the library. Crypto on a centralized exchange trades through most of the week. Onchain tokens, including tokenized stocks such as NVDAx, TSLAx and SPYx, trade when the chain produces blocks. Tokenized stocks and crypto trade on different hours and venues than listed equities, which have sessions, halts and a broker in the middle. Write that clock into the rules. A closing-auction rule will fire at the wrong time on a market that never closes.
Most first bots use one of four shapes:
- Trend following. Buy strength, and exit when the move fails or a stop hits.
- Mean reversion. Buy a stretch from a recent average, and exit on the return or a stop.
- DCA. Buy a fixed size on a schedule, with the exit written in advance.
- Breakout. Buy through a price set beforehand, and stop back inside the range.
Here is one trend-following strategy as rules a stranger could follow. It is illustrative.
- Clock. Closed 1-hour candles only.
- Entry, with no position open. Latest close above the highest close of the prior 20 closed candles, and volume above the average of those 20.
- Size. The smaller of a risk budget and a max position, both set before the session.
- Stop. On the fill, set a stop under the fill price and leave it there.
- Other exit. Sell if the close falls under the lowest close of the prior 10 closed candles.
- Otherwise. Do nothing.
An LLM can draft those sentences. See how to use ChatGPT for trading. ChatGPT there drafts text and is not a host that places orders.
Pseudo-code of the same rules. highest, average and lowest mean indicator math on closed candles. No order is placed, and no key appears.
# closes_before_last excludes the bar being judged.
# After a buy fill: stop_price = fill_price * (1 - stop_fraction)
prior_high = highest(closes_before_last, 20)
prior_avg_volume = average(volumes_before_last, 20)
if not in_position and last_close > prior_high and last_volume > prior_avg_volume:
size = min(risk_budget, max_position)
signal = "buy"
elif in_position and (last_close <= stop_price or last_close < lowest(closes_before_last, 10)):
signal = "sell"
else:
signal = "hold"
stop_fraction is chosen when the order fills, then left alone. A missing size line means the strategy is not finished.
Step 2: Get market data
Store each candle's open time, open, high, low, close, volume and venue. Keep the fetch time separate from the candle time. If a rule uses headlines, store the publish time. Stamping news at download time makes a backtest read the future.
Centralized exchanges. Each exchange publishes an API for candles, trades and order books. The open-source CCXT library wraps many exchange APIs in one interface. CCXT describes itself as a unified trading API for more than 100 crypto exchanges, with a Python library among its ports. You still create a key at each exchange. Step 4 is where that key lives. A top-of-book quote is enough unless the rule uses depth.
Onchain markets. Read chain state through an RPC node and history through an indexer. Helius is one example of a Solana RPC and data provider. Token data APIs add price, liquidity and holders. Match the mint, not the ticker, because copycat tokens reuse symbols.
Data for an agent. The host calls MCP servers as tools. Three marketplace listings cover the jobs above:
- Helius MCP for Solana wallet and transaction reads.
- Birdeye MCP for Solana prices, candles and trending lists.
- CoinGecko MCP for market-wide prices, categories and trending coins.
Prefer one primary feed, check a second source before a large order, and log which feed the signal used.
Step 3: Backtest before you risk money
A backtest replays the rules on past candles and records the fills. It catches unclear rules, look-ahead and tests that only work when trading is free. Past fills do not predict live results. For Python, one of these is enough:
- backtesting.py calls itself a Python framework for testing strategies on historical data (docs). One rule on one series fits.
- vectorbt calls itself a Python package for quantitative analysis on pandas and NumPy, which suits a parameter sweep (docs).
- TA-Lib computes indicators such as a rolling high, a moving average or an oscillator.
Traps that make a backtest lie
- Look-ahead bias. The signal uses a value nobody knew yet, such as a ranking built on later data, or a fill at the open of a bar whose close you already used.
- Overfitting. Knobs get tuned until the past looks smooth. Freeze the rules, then run a stretch you did not use to pick the numbers.
- Fees and slippage left out. Put the venue fee and a slippage estimate in the test. A mid-price fill with no fee will not match the live book.
- Dropped names. A test of only the tokens that still trade ignores the ones that went to zero.
Run the rules once, with costs. After you change a parameter because of the test, that run is no longer evidence.
Step 4: Connect execution
Execution turns a buy, sell or hold from Step 1 into an order, in a separate step so a risk check can refuse the buy.
Coded route. On a centralized exchange, send orders through that exchange's API or through CCXT. Check CCXT's docs for which order methods that exchange implements. For an onchain swap on Solana, Jupiter's developer docs describe DeFi infrastructure on Solana for swaps, including a swap API. You choose the mint, sign with a wallet and set a slippage bound. Those docs also describe a developer platform key. Keep it in an environment variable.
Key handling. Never hard-code API keys or wallet private keys in source files, notebooks or chats. Load them from environment variables, and keep that file out of version control. EXCHANGE_API_KEY is a name, not a value to commit. Prefer a scoped key that can trade and cannot withdraw, where the venue offers that split. A bot wallet should hold only what it trades.
Paper trade first where the venue supports it, and confirm an order, a cancel, a reject and a restart. With no paper mode, start at the venue's smallest size, with the Step 5 kill switch already tested and no position open.
Step 5: Add risk limits outside the strategy
Limits that sit in the execution layer still apply when the strategy code or the model makes a mistake. The order path checks them after the signal.
- Max position size, chosen before the session.
- A daily loss cap or a daily volume cap that stops new trades. Reducing a position can stay allowed.
- Stop-loss and take-profit orders at the venue, so an exit can fire while your process is offline.
- A maximum number of trades per period, so a loop cannot burst orders.
- An asset allowlist of mints or symbols.
- A kill switch that cancels open orders and blocks new ones. Test it before you fund the bot.
- A log of every signal, order, reject and fill, with timestamps.
On Solana, run a rug check before the first buy in a new mint. More on the same controls: risk management for AI trading.
Step 6: Deploy, monitor and review
Run the process somewhere that stays up for the session you wrote into the rules:
- Your own machine, for a paper run or a small live test you are watching.
- A server you control, when it has to stay up overnight.
- A scheduler, when the strategy only wakes on a timer.
Alert when the process stops, when the last data fetch goes stale, when an order is rejected, when you near the daily cap, and when the balance the bot can sign for drifts from the max position.
Once a week, compare live fills with the backtest: fees, slippage, skipped signals and any order you overrode. Explain a gap before you add a feature.
Code, no-code or AI agent: which route fits?
The six steps stay the same. Setup time below is qualitative only: hours, days or weeks. Your time and the venue's fees are the cost, and both change, so this page quotes neither.
| Route | Skills needed | Setup time | Flexibility | Where risk is enforced | Good for |
|---|---|---|---|---|---|
| Coded bot (Python) | Programming, APIs, and keeping a process running | Weeks | Full control of every part | Your process and the venue | People who will maintain the system |
| No-code platform bot | Configuring a template | Hours to days | Limited to the platform | The platform, where it offers caps | People who want hosted execution |
| AI agent + MCP | Writing rules in plain language | Hours to days | Broad research, bounded by the tools | The execution service, outside the model | People who want a host AI to follow written rules |
Skip the code: see the agent route.
Coded bot (Python). You maintain every part. Python is common here because CCXT, backtesting.py and vectorbt are available. Budget weeks.
No-code platform bot. A template and hosted execution, limited to that platform's markets, order types and caps. This guide does not name or rate platforms. Use the platform's own docs for fees and order types.
AI agent + MCP. A host calls a trading MCP server. You write rules in plain language. Orders stop at the tools you connected. A prompt is not a cap.
The Model Context Protocol is an open-source standard for connecting AI applications to external systems, so a host can call tools on a server without a custom integration for each one. Hosts in this guide are Codex, Claude Code (the CLI) and Grok. See Claude trading bot for the Claude Code walkthrough, and agentic trading for the wider pattern of an agent that researches and then proposes or places trades inside limits you set.
Further reading, not a required step: TradingAgents, whose repository calls itself a Multi-Agents LLM Financial Trading Framework (source), and AI Hedge Fund, whose repository calls itself an AI Hedge Fund Team (source). For Solana frameworks such as ElizaOS and the Solana Agent Kit, see Solana AI agents.
The no-code execution path: an AI agent with Moby MCP
One way to skip the data plumbing in Step 2 and the order plumbing in Step 4, for Solana, is an AI agent connected through Moby MCP. Codex, Claude Code (CLI) or Grok stays the host and calls Moby as a tool server. You still write the Step 1 rules, backtest with the Step 3 tools if you want a historical test, set the Step 5 limits, and do the Step 6 review.
Data. Moby MCP gives the agent token overviews, safety signals, and whale, KOL and smart-money flows. get_token_trade_brief is the one-call pre-buy read.
Execution. The agent can place market buys and sells, plus take-profit, stop-loss and DCA orders through create_order. Moby attaches no exit orders to a buy, so the agent places its own stop-loss and take-profit.
Risk. You set your agent's limits on max per trade, daily buy volume and market-cap range from the Moby app, and Moby checks them server-side on every buy your agent makes. The agent wallet has no withdraw, transfer or send tool. There is one agent per user, with its own wallet, separate from the main in-app wallet.
Scope. Agents trade Solana tokens only, funded with USDC. That includes tokenized stocks such as NVDAx, TSLAx and SPYx, and pump.fun coins before and after graduation. Agent trading on Base, BNB Chain and Robinhood Chain is coming soon.
Strategy. Paste the Step 1 rules, or start from Moby Starter Strategies, which ship with the connector. Set up a Moby Agent collects the connection steps. The short version is next.
Try it with a Moby Agent
- Download Moby and open the Agent tab. One agent per user, with its own wallet.
- Set max per trade, daily buy volume and market-cap range in the app.
- Tap Connect, create a key, and add the Moby MCP server to Codex, Claude Code or Grok. The key is created in the app. It is an agent API key, not a wallet private key. Do not paste it into a chat, and do not hard-code it in a file.
- Fund the agent wallet with USDC.
- Paste your Step 1 rules and ask the agent to propose trades for your approval.
A 0.75% swap fee (minimum $0.90 per swap), plus onchain fees.
10% of the Moby fee back in $MOBY on every swap, 20% after your first swap, up to 30% as you climb tiers.
How this sits next to trading you place yourself is covered on agentic trading. Host-by-host steps are on Set up a Moby Agent.
FAQ
Can I build a trading bot without coding?
Yes. Use a no-code bot platform, or an AI agent connected to a trading service through MCP, where you write rules in plain language.
What programming language is best for a trading bot?
Python is the most common choice because of libraries for data, backtesting and exchange access, such as CCXT, backtesting.py and vectorbt.
Can AI build a trading bot for me?
An AI coding assistant can write bot code, and an AI agent can act as the bot itself through an MCP server. You still own the strategy and the risk limits.
How do I test a trading bot before using real money?
Backtest on historical data, then paper trade or trade very small size, and compare live fills with the backtest.
Are trading bots profitable?
Some lose money. Results depend on the strategy, costs and market conditions. Be wary of anyone promising returns. The CFTC customer advisory on AI trading bots and FINRA both warn against automated-trading pitches that promise results.
How do I keep a trading bot from losing too much?
Cap position size and daily volume, place stop-loss orders, keep a kill switch, and enforce limits in the execution layer.
What does an AI trading bot need to trade on Solana?
A wallet, a data source, a swap route such as Jupiter, and risk limits. An agent with Moby MCP gets data, execution and server-side caps in one connection.
Set up a Moby Agent
Set up a Moby Agent with its own wallet and your spending guardrails, then connect it to the AI you use.
Published November 2, 2026 by Moby. Rules and pseudo-code are illustrative. A bot can lose what it is allowed to trade. Not financial, legal or tax advice.