Case study · Personal project
AutoTrade
A Python paper trading bot, launched every weekday evening by a phone turned into a server.
Paper trading only. The bot places its orders on a simulated account: the money is virtual and no real order is sent. This project is not investment advice.
Context
AutoTrade brings together two projects: a trading bot written in Python, and the small server that runs it on its own. The interest is technical: making a program talk to a broker's API, handling network failures, scheduling a task, and keeping everything safe on a network that is not.
Goal
Launch, every weekday evening and without intervention, a bot that analyses the market, places or adjusts its positions on a paper trading account, then reports on what it did. All on an old Android phone, for minimal power and data consumption.
Working mock-up
- Phone-server (Android, Termux and Debian): a scheduled task wakes the bot at 5 pm, Monday to Friday.
- Market data: the bot fetches recent prices from the broker's API.
- Strategy: entry signals, then stop-loss (SL) and take-profit (TP) computed from the ATR, a measure of recent volatility.
- Paper trading orders: sent to a simulated account, with virtual money.
- Report and log: every analysis and decision is traced, and a daily summary is produced.
- Secure remote access: through a private encrypted tunnel and key-based authentication. No port is exposed to the Internet.
Approach
- A modular bot: configuration, data, strategy and execution are separated, using the official library of the broker Alpaca in paper trading mode.
- Stops adapted to volatility: instead of fixed percentages, the stop-loss and take-profit distance is proportional to each stock's ATR. The coefficients are calibrated by simulation on historical data.
- Safeguards: automatic cut-off if the daily loss is too large, a check that every position has its stops, retries on network errors.
- Tests: the strategy and execution are tested with a fake client replacing the API, so without placing any order.
- A pocket server: on the phone, the scheduler and the wake lock run in Termux, the bot in a Debian environment. A script restarts everything at boot.
- Security first: the network is treated as hostile. Credentials stay in a restricted-access file, outside the code and the logs. No service listens on the local network.
Stop computation at a glance
Entry
The bot records an entry price when the strategy gives a signal.
ATR
The average range of the latest sessions measures how nervous the stock is.
SL and TP
Stop-loss below the entry, take-profit above it, each at a distance proportional to the ATR.
Results
- The server is operational: it restarts on its own and launches the bot at the scheduled time, with the phone in standby.
- Each run leaves a log and a summary, viewable remotely.
- A code audit led to several fixes, for example keeping a position when a network error prevents knowing its state.
No performance figure is published here: the account is simulated and the strategy is still being calibrated.
Limitations
- Paper trading does not prove real performance: no fees, no slippage, no psychological pressure.
- A first run failed because of a missing state file. Loading was fixed and a test added.
- A phone is not a server: it depends on its battery, Wi-Fi and the system's sleep modes.
- The code is not published.