EC logoEliot Cornu

Case study · Personal project

AutoTrade

A Python paper trading bot, launched every weekday evening by a phone turned into a server.

  • Python
  • Linux
  • Automation
  • Security

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

Working mock-up of AutoTradeA phone-server triggers the bot at 5 pm on weekdays. The bot fetches market data, computes stops from the ATR, sends its orders to a paper trading account (virtual money), then writes a report. A computer reaches the phone remotely through an encrypted tunnel.TPSL17:00MON-FRIPAPER
The diagram shows the steps of one run. All computation runs on the phone; only prices and orders go through the broker's API.
  1. Phone-server (Android, Termux and Debian): a scheduled task wakes the bot at 5 pm, Monday to Friday.
  2. Market data: the bot fetches recent prices from the broker's API.
  3. Strategy: entry signals, then stop-loss (SL) and take-profit (TP) computed from the ATR, a measure of recent volatility.
  4. Paper trading orders: sent to a simulated account, with virtual money.
  5. Report and log: every analysis and decision is traced, and a daily summary is produced.
  6. Secure remote access: through a private encrypted tunnel and key-based authentication. No port is exposed to the Internet.

Approach

  1. A modular bot: configuration, data, strategy and execution are separated, using the official library of the broker Alpaca in paper trading mode.
  2. 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.
  3. Safeguards: automatic cut-off if the daily loss is too large, a check that every position has its stops, retries on network errors.
  4. Tests: the strategy and execution are tested with a fake client replacing the API, so without placing any order.
  5. 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.
  6. 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

No performance figure is published here: the account is simulated and the strategy is still being calibrated.

Limitations