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 asbot.py.
bot.py
ARIES_ACCOUNT_ID to that ID and run it again. The bot checks the market every five minutes and prints what it decided.

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 toPOST /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?
Insignal(). 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.
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:- Shares held, from
/v1/accounts/{id}/positions. The bot won’t buy pastMAX_POSITIONor sell shares it doesn’t hold. - Today’s profit and loss, the
dayTotalPnlfield from/v2/accounts/{id}/balance. Below-MAX_DAILY_LOSS, the bot stops trading for the day.
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.