Skip to content

The project is an entirely automated trading system based on the foundational concepts of support and resistance in technical analysis. Once the S&R indexes are entered, the program will automatically place and offset positions. Free your hands and mind.

Notifications You must be signed in to change notification settings

ttpss930141011/auto-futures-trading-machine

Repository files navigation

πŸš€ Auto Futures Trading Machine

Coverage Pylint CI Status Python Version License

Taiwan Futures Automated Trading System - Designed for PFCF (η΅±δΈ€ζœŸθ²¨) A distributed, event-driven futures trading platform built with Python and ZeroMQ

πŸ“– Table of Contents

🎯 Getting Started

πŸ—οΈ Architecture & Design

πŸ”§ Technical Deep Dives

πŸ“š Implementation Guides

πŸ” Developer Stories

πŸ“‹ Configuration & Reference


🎬 About This System

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.

πŸ† What Makes This Special?

πŸ” Security First

We eliminated plaintext credential storage and centralized all exchange API access through a secure DLL Gateway - a pattern inspired by institutional trading systems.

⚑ Event-Driven Architecture

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.

🧩 Clean Architecture

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.

πŸ“Š Production Ready

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.

πŸš€ Quick Start

# 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.py

Important: You must be a Taiwan Unified Futures customer with API access. Follow our Quick Start Guide for detailed instructions.

πŸ›οΈ System Architecture at a Glance

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
Loading

πŸ“Š Key Architectural Improvements

  • πŸ—οΈ 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

πŸ“ˆ Performance Metrics

  • 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

πŸŽ“ Learning Path

Whether you're interested in:

This documentation serves as both a technical reference and a learning resource for building production-grade trading systems.

⚠️ Important Limitations

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.

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

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

8. Equity Trend Chart

This is the daily change in equity

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 β†’

About

The project is an entirely automated trading system based on the foundational concepts of support and resistance in technical analysis. Once the S&R indexes are entered, the program will automatically place and offset positions. Free your hands and mind.

Topics

Resources

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •  

Languages