Skip to content

CJTrade

CJTrade is a Python framework for trading stocks on the Taiwan Stock Exchange (TWSE). A strategy is a single Python file, and the same file runs unchanged in three modes:

  1. Backtest: replayed over historical prices.
  2. Paper trading: against ArenaX, a simulated broker that runs locally, with no money at risk.
  3. Live: against a Sinopac (永豐金證券) brokerage account.

No brokerage account is required for any of Get started; it runs locally on free price data.

Not investment advice

CJTrade can place real orders on a real account, and you are responsible for every order it sends. Run a strategy on ArenaX first, then on Sinopac's sandbox, before it touches real money.

Architecture

  your strategy file  ─┐
  (on_bar → buy/sell)  │
                       ▼
               ┌───────────────┐   orders, account    ┌──────────────────────┐
               │  CJTrade code │ ───────────────────▶ │ a broker             │
               │ (AccountClient│ ◀─────────────────── │  · ArenaX (pretend)  │
               │  or the engine)   fills, balance     │  · Sinopac (real)    │
               └───────────────┘                      └──────────────────────┘
                       ▲
                       │ prices (bars, quotes)
               ┌───────────────┐
               │ market data   │  Sinopac · FinMind · Yahoo · a local file
               └───────────────┘
  • Broker: receives orders and holds cash and positions. ArenaX is the simulated broker bundled with CJTrade: a local server that accepts orders and fills them against real historical prices.
  • Market data: the price source, independent of the broker. You can, for example, trade on ArenaX with prices from Yahoo Finance.
  • AccountClient: the single object your code uses to talk to a broker. The same calls work on ArenaX and on Sinopac.

Key ideas defines CJTrade's terms and conventions.

Choose your path

Goal Start here Time
Install CJTrade and verify the install Install 5 min
CJTrade terms and conventions Key ideas 10 min
Place a first order on ArenaX from Python Connect to a broker, then Account and orders 15 min
Fetch prices and compute an indicator Market data 10 min
Write a strategy and backtest it over a year Write a strategy, then Backtesting 20 min
Run several bots minute by minute, as in live trading Run the trading engine 15 min
Use the interactive shell or the web UI CJShell and FinHub 10 min
Fix an error Troubleshooting

Each Get started page builds on the previous one; read them in order the first time.

Lookup

Look up Page
Every command, its options and ports Commands
Settings files and environment variables Configuration and paths
A class or function API reference

Note

The API is not stable yet; names may change before 1.0.