Skip to main content
Here’s a complete trading bot in one Python file, standard library only, on the Aries API. The strategy is the small part: 12 lines. The rest keeps the bot from hurting you. On every pass it checks your positions and today’s loss against your limits, previews every order, and won’t place one until you turn placing on.

What Do You Need Before You Start?

  • An Aries account. Stock and options brokerage comes from RAM Financial LLC (DBA Aries), member FINRA and SIPC. The API and its market data are free with your account, and you can have a simulation account beside the live one.
  • A personal-token client (a client ID that starts with ARI-PERSONAL-TK.) and its secret. Create one in Client Center under the API tab. The Client Credentials guide explains this client type.
  • Python 3. Nothing to install. If you’d rather use the official SDK, try the Python SDK.

What Does a Complete Trading Bot Look Like in Python?

Here’s the whole bot. Save it as bot.py.
bot.py
We ran this file on a simulation account on the Aries API sandbox on Nov 29, 2026, with Python 3.15, in preview mode only. AAPL and the 10/30 moving-average crossover are examples, not a recommendation, and the strategy isn’t backtested. To run it, export your client ID and secret, then start the bot once without an account ID. It prints your simulation account’s ID and stops:
Set ARIES_ACCOUNT_ID to that ID and run it again. The bot checks the market every five minutes and prints what it decided.
Terminal output. python3 bot.py prints the simulation account ID. Run again with ARIES_ACCOUNT_ID set, it prints: AAPL: signal None, holding -1. A forced send_order BUY 1 AAPL prints a preview with estimatedCost, estimatedMargin, commission, buyingPowerImpact, fees, numDayTrades and warnRuleId.

One pass of the bot on the Aries sandbox (account IDs hidden). On a Sunday it found no signal, and a forced preview returned the order's costs without placing it.

How Does the Bot Get and Refresh Its Access Token?

The bot signs in with the Client Credentials grant: it sends its client ID and secret to POST /v1/oauth2/token and gets back a bearer token. That token lasts 15 minutes (expires_in is 900), so token() gets a new one a minute before it runs out. Send your own User-Agent header with every request. Leave it out and the very first call, the token request, fails: the API answers Python’s default Python-urllib User-Agent with a 403 and the body error code: 1010.

Why Does the Bot Trade on Finished Bars Only?

closes() asks /v1/chart/history for a week of 5-minute bars and drops the bar that’s still forming. A bar that’s still open keeps changing, so a crossover you see at 10:02 can be gone by 10:05. The same call gets you started on a backtest. signal() takes a plain list of closing prices, so you can feed it a longer range from /v1/chart/history and see where it would have traded.

Where Does the Trading Strategy Go?

In signal(). It returns BUY when the 10-bar average crosses above the 30-bar average, SELL when it crosses below, and None otherwise. It’s a placeholder. Swap in your own rules, keep the same return values, and nothing else in the bot has to change.
Line chart of AAPL 5-minute closes on Nov 25, 2026, between about $345 and $357, with the 10-bar and 30-bar averages. The 10-bar average crosses below the 30-bar at 09:35 (SELL), above it at 11:55 (BUY), and below it again at 15:25 (SELL).Line chart of AAPL 5-minute closes on Nov 25, 2026, between about $345 and $357, with the 10-bar and 30-bar averages. The 10-bar average crosses below the 30-bar at 09:35 (SELL), above it at 11:55 (BUY), and below it again at 15:25 (SELL).

The placeholder strategy on real AAPL bars from the Aries sandbox. Example only, not a recommendation. Each dot marks the 5-minute bar, by its start time, where the averages crossed.

How Do You Cap a Bot’s Position and Daily Loss?

Set the limits in the file and read the numbers from the account. On every pass, before it decides anything, the bot asks Aries for two numbers: The bot keeps no count of its own, so a restart, a crash or a trade you place by hand can’t throw it off. The run above shows this: the simulation account already held -1 AAPL, and the bot reported that, not zero.

How Do You Preview an Order Before the Bot Places It?

send_order() sends the order to POST /v1/orders/preview first. A preview takes the same body as a real order and returns what the order would do (estimatedCost, buyingPowerImpact, fees and numDayTrades, among others) without placing anything. Only when you start the bot with LIVE=1 does it send that same body to POST /v1/orders. Run it without LIVE=1 on your simulation account until the previews look right, then switch it on there before you try your live account. Once orders go out, fills arrive later, so watch them on the account updates WebSocket and don’t treat a sent order as filled. numDayTrades is worth logging: it’s the number of day trades the order would count toward, and a bot that trades every five minutes adds them up fast. FINRA replaced its pattern day trader rule, including the $25,000 minimum, with intraday margin standards that took effect June 4, 2026, and brokers can phase them in until October 20, 2027.

What Trading Rules Apply to Your Own Bot?

A bot is held to the same rules as any trader. Trading to create a false or misleading appearance of activity, like buying and selling to yourself, is unlawful under Section 9(a) of the Securities Exchange Act, whoever or whatever places the orders.

Can ChatGPT or Claude Build a Trading Bot?

They can write one, and through the Aries MCP server they can also place orders for you, no script needed. If you go that way, set it up so every order waits for your approval. Build a Safe AI Trading Agent With Claude Code shows how. What no AI can do is promise a profit: the SEC, FINRA and NASAA tell investors to “be wary of claims … that AI can guarantee amazing investment returns.” To build an app other people sign in to with their own Aries account, start with the Quick Start. It walks through the OAuth flow and your first API call.