Taiwan Futures Automated Trading System - Designed for PFCF (η΅±δΈζ貨) A distributed, event-driven futures trading platform built with Python and ZeroMQ
- Quick Start Guide - Get up and running with Taiwan Unified Futures (PFCF)
- Installation Guide - Detailed setup instructions
- First Trade Tutorial - Your first automated trade with support/resistance strategy
- Class Design Guide - SOLID principles and Clean Architecture implementation
- Detailed Flow Diagrams - Process flows and system interactions
- DLL Porting Guide - How to migrate from PFCF to other brokers
- Why ZeroMQ? - Message patterns and performance analysis
- Process Communication - IPC patterns explained
- High-Frequency Trading Concepts - What we borrowed from HFT
- AllInOne Controller Guide - Complete startup process and data flow
- Strategy Expansion Guide - How to add new trading strategies
- Backtesting Guide - Testing your strategies
- Monitoring Guide - System monitoring and alerts
- Design Decisions - Why we made the choices we did
- Lessons Learned - What worked and what didn't
- Configuration Guide - System configuration options
- Roadmap - Project evolution and future plans
- Architecture Decision Records - Key architectural choices
This is not a generic trading system. This platform is specifically designed for Taiwan Unified Futures (PFCF) and is tightly coupled to their proprietary Python DLL API.
We eliminated plaintext credential storage and centralized all exchange API access through a secure DLL Gateway - a pattern inspired by institutional trading systems.
Every market tick, every trading signal, every order - they're all events flowing through our system via ZeroMQ, enabling true parallelism and bypassing Python's GIL.
SOLID principles aren't just theory here. Our system demonstrates how proper separation of concerns transforms maintainability with clear boundaries between domain, application, and infrastructure layers.
From comprehensive test coverage to graceful error handling, this isn't just a prototype - it's a system designed for real trading with Taiwan futures markets.
# Clone the repository
git clone https://github.com/ttpss930141011/auto-futures-trading-machine.git
cd auto-futures-trading-machine
# Install dependencies
poetry install
# Configure your PFCF credentials
cp .env.example .env
# Edit .env with your Taiwan Unified Futures credentials
# Run the system
python app.pyImportant: You must be a Taiwan Unified Futures customer with API access. Follow our Quick Start Guide for detailed instructions.
graph TB
%% Main Process Components
subgraph MainProcess["π Main Process (app.py)"]
direction TB
subgraph Bootstrap["π Initialization"]
AB[ApplicationBootstrapper<br/>β’ ServiceContainer DI<br/>β’ Config Validation<br/>β’ Directory Creation]
SM[SystemManager<br/>β’ Component Lifecycle<br/>β’ Health Monitoring<br/>β’ Status Management]
end
subgraph Infrastructure["ποΈ Infrastructure Layer"]
CLI[CLI Interface<br/>User Commands]
subgraph DLLGateway["π DLL Gateway"]
DGS[DLL Gateway Server<br/>ZMQ REP Port: 5557<br/>β’ Order Execution<br/>β’ Position Query]
PFCFAPI[PFCF API<br/>β’ Login/Auth<br/>β’ Trading Functions<br/>β’ Market Data Callbacks]
end
subgraph MarketData["π Market Data"]
MDP[Market Data Publisher<br/>ZMQ PUB Port: 5555<br/>β’ Tick Broadcasting]
MDG[MarketDataGateway<br/>β’ Tick Processing<br/>β’ Event Handling]
end
end
subgraph Services["π οΈ Gateway Services"]
PC[PortCheckerService<br/>β’ Port Validation]
PM[ProcessManagerService<br/>β’ PID Management<br/>β’ Process Control]
SC[StatusChecker<br/>β’ Health Checks]
end
AB --> SM
SM --> Services
SM --> Infrastructure
PFCFAPI --> MDG
MDG --> MDP
CLI --> DGS
end
%% Strategy Process
subgraph StrategyProcess["π Strategy Process"]
direction LR
TS[Tick Subscriber<br/>ZMQ SUB :5555]
SRS[Support/Resistance<br/>Strategy Engine<br/>β’ Entry/Exit Logic<br/>β’ Signal Generation]
SP[Signal Publisher<br/>ZMQ PUSH :5556]
TS --> SRS
SRS --> SP
end
%% Order Executor Process
subgraph OrderExecutor["β‘ Order Executor Process"]
direction LR
SR[Signal Receiver<br/>ZMQ PULL :5556]
OEG[OrderExecutorGateway<br/>β’ Signal Processing<br/>β’ Order Creation]
DGC[DLL Gateway Client<br/>ZMQ REQ :5557]
SR --> OEG
OEG --> DGC
end
%% Data Flow Connections
MDP ===>|"π Market Ticks<br/>(Broadcast)"| TS
SP ===>|"π¨ Trading Signals<br/>(Push/Pull)"| SR
DGC -.->|"π Order Requests<br/>(Req/Reply)"| DGS
%% Process Management
PM -.->|"π§ Manages"| StrategyProcess
PM -.->|"π§ Manages"| OrderExecutor
%% Styling - ζΉει
θ²ζΉζ‘
classDef mainBox fill:#2c3e50,stroke:#34495e,stroke-width:3px,color:#fff
classDef bootstrap fill:#3498db,stroke:#2980b9,stroke-width:2px,color:#fff
classDef infrastructure fill:#8e44ad,stroke:#662d91,stroke-width:2px,color:#fff
classDef services fill:#27ae60,stroke:#229954,stroke-width:2px,color:#fff
classDef strategy fill:#f39c12,stroke:#d68910,stroke-width:2px,color:#fff
classDef executor fill:#e74c3c,stroke:#c0392b,stroke-width:2px,color:#fff
classDef dataflow stroke:#3498db,stroke-width:3px,stroke-dasharray: 5 5
class MainProcess mainBox
class AB,SM bootstrap
class CLI,DGS,PFCFAPI,MDP,MDG infrastructure
class PC,PM,SC services
class TS,SRS,SP strategy
class SR,OEG,DGC executor
- ποΈ Dependency Injection: ServiceContainer centralizes all dependencies
- π Component Status: Enum-based status tracking (STOPPED β STARTING β RUNNING β STOPPING β ERROR)
- π‘οΈ Gateway Services: Dedicated layer for infrastructure services (Port checking, Market data gateway, Process management)
- π PID Management: ProcessManagerService handles process lifecycle with PID files in tmp/pids/
- β‘ Health Monitoring: SystemManager provides real-time health checks and uptime tracking
- Tick Processing: < 1ms latency (ZeroMQ + msgpack serialization)
- Signal Generation: < 5ms from tick to trading decision
- Order Execution: < 10ms round-trip to exchange
- Test Coverage: 95%+ across critical components
Whether you're interested in:
- System Architecture: Start with Class Design Guide for complete system overview
- Detailed Flows: Explore Detailed Flow Diagrams for process flows
- AllInOne Controller: Understand AllInOne Controller Guide for startup process
- Strategy Development: Read Strategy Expansion Guide for adding new strategies
- Distributed Systems: Read Why ZeroMQ? for messaging patterns
- Broker Migration: Check DLL Porting Guide for migrating to other brokers
This documentation serves as both a technical reference and a learning resource for building production-grade trading systems.
Broker Dependency: This system is highly coupled to Taiwan Unified Futures (PFCF) DLL. If you need to migrate to other brokers like Yuanta Securities or Capital Futures, refer to our DLL Porting Guide.
Single Strategy: Currently supports only the right-side entry support/resistance strategy. See Strategy Expansion Guide to add more strategies.
This project is licensed under the MIT License - see the LICENSE file for details.
This project stands on the shoulders of giants:
- The ZeroMQ community for incredible messaging patterns
- Clean Architecture principles by Robert C. Martin
- High-frequency trading system designs that inspired our architecture
- Taiwan Unified Futures for providing the API access
This is the daily change in equity
"In trading, as in software, the best systems are those that are simple to understand, yet sophisticated in their execution."
Ready to dive in? Start with our Quick Start Guide β

