Building a Foundation for Automated Stock Trading — Architecture and Current Progress
Introduction
To achieve automated stock trading, you need a foundation that consistently handles “data acquisition,” “analysis,” “visualization,” and “order execution.” This article summarizes the concept and current implementation status of a project I am building from scratch using a multi-service separated architecture. It is intended for personal learning and verification, with the goal of documenting the journey toward production automated trading.
Architecture Concept
Overview
The foundation for automated trading is structured as follows:
| Layer | Role |
|---|---|
| Data Acquisition | Periodically or manually fetch stock prices, volume, futures, ADRs, etc., and store them in a DB |
| Analysis | Calculate market strength, industry rankings, abnormal volume, etc., from accumulated data |
| Visualization / API | Provide stock price charts and watchlist views, as well as APIs accessible from other systems |
| Order Execution | Integrate with brokerage APIs to place market/limit orders and synchronize holdings |
The architecture centers around TimescaleDB (PostgreSQL-based) as the database, with each service communicating via the DB or HTTP APIs. As a foundation for eventually hosting a strategy engine that automates “signal generation → order placement,” each capability—acquisition, analysis, display, and ordering—is implemented as an independent service for easy reconfiguration and expansion.
Technology Stack
- Language: Rust (prioritizing performance and type safety)
- Web Framework: Axum
- DB Access: SQLx
- Time-Series Data: Storing stock prices using TimescaleDB hypertables
Current Architecture (Service List)
| Service Name | Main Role | Notes |
|---|---|---|
| stock_get | Acquisition of stock prices, futures, and ADRs; watchlist management; scheduler | Dedicated to price acquisition; includes Web UI |
| stock_tran | Brokerage (Tachibana Securities) API integration, order submission, holdings sync | Supports Demo/Production mode switching; production orders disabled for safety |
| stock_view | Stock price chart display, watchlist, data visualization, external API | Read-only viewer + API server |
| stock_analyze | Market sentiment scenarios, industry rankings, abnormal volume alerts | Provides analysis results via REST API |
| mcp | Utilize APIs from MCP tools such as stock search and order book info | For agent integration |
Each service runs on a separate port and references other services’ APIs or the shared DB as needed.
Accessing via MCP from Chat
This foundation can also be accessed from chat (e.g., Cursor chat) via MCP (Model Context Protocol). The MCP server provides tools that call the stock_get and stock_view APIs, allowing you to request watchlists, search stocks, or check order book information in natural language right from the chat screen. In the future, order execution is also planned to be supported via MCP.
Implementation Status
1. stock_get (Stock Price Acquisition System)
Status: Core features implemented.
- Watchlist Management: Add, delete, and update stocks via Web UI. Supports multiple timeframes (daily, weekly, monthly).
- Stock Data Acquisition: Primarily uses the Stooq API (free, no authentication required). J-Quants API and Yahoo Finance API are specified for fallback/supplementation but not yet implemented.
- Data Coverage Management: Tracks continuous acquisition periods per stock and timeframe. Displayed as horizontal bar charts in the Web UI.
- Scheduler: Batch-fetches prices for all watched stocks at a scheduled time (default 19:00). Includes an option to run on weekdays only.
- Other: Includes scheduled periodic fetching for futures (Twelve Data), ADRs (Yahoo), and the Nikkei 225 index (Yahoo).
2. stock_tran (Order Execution & Holdings Sync)
Status: Basic Tachibana Securities API integration implemented. Orders are enabled only in the demo environment.
- Authentication & Session: Login and session persistence. Switches between Demo and Production via a test mode flag.
- Holdings Sync: Reflects the holdings list retrieved from the API into the DB and displays it in the Web UI.
- Order Submission: Supports market/limit and buy/sell orders via API. Order submission is intentionally disabled in the production environment and operates only in test mode.
- Order History: Records submitted orders in the DB and provides a list retrieval API.
For automated trading in production, a separate “strategy engine” is expected to call the order API, which first requires designing risk management and execution confirmation flows.
3. stock_view (Visualization & External API)
Status: Display features and external API implemented. Includes stock charts (multi-stock, timeframe, and period selection), watchlist, data acquisition status heatmap, and an external API with API key authentication and rate limiting (usable by MCP and other tools).
4. stock_analyze (Analysis)
Status: All 3 features implemented. Market sentiment scenarios (market strength from Nikkei futures), industry rankings (opening performance of industry leaders via ADRs), and abnormal volume alerts. All return results via REST API and are intended to serve as “signal” inputs for automated trading.
Future Plans (Concept)
- Strategy Engine: A component that generates signals using analysis results and stock price data as inputs and calls the
stock_tranorder API. Considering rule-based logic and backtesting. - Enabling Production Orders: To be decided after designing risk management, execution confirmation, and failure fallbacks.
- J-Quants / Yahoo Implementation: Implement as fallback/supplementary data sources for
stock_getto improve acquisition reliability.
Summary
| Item | Details |
|---|---|
| Objective | Building a foundation for automated stock trading by separating acquisition, analysis, display, and order execution |
| Current Status | Data acquisition, ordering, holdings sync, visualization, API, and analysis are all implemented. Ordering is active only in the demo environment |
| Next Steps | Design and implement the strategy engine, and decide whether to enable production orders |
It hasn’t reached the stage where “trades run automatically” yet; the foundation is still taking shape. I plan to update the article as progress continues.
Created: March 2026