A Go framework for building, backtesting, and running automated trading strategies against real broker APIs. It works for stocks, forex, and crypto, and any broker can be plugged in behind a small interface.
This is a framework, not a ready-made trading bot. The bundled strategies are illustrative examples, not profitable systems.
ticks / candles decision orders
───────────────▶ Strategy ────────▶ Trader ───────▶ Broker
(Trader) (your logic) (this repo) (IG, Coinbase, …)
- Plug-in architecture — brokers, strategies, and indicators are all small interfaces. Implement one, wire it in, done.
- Backtest before you risk money — replay historical prices with configurable spreads and trading fees, then print a performance summary and equity curve.
- Paperwallet — simulate fills for brokers without a sandbox, so you can dry-run against live prices.
Runs a full backtest with no external data source or account — a small sample EUR/USD dataset ships in examples/sample-data/.
# 1. Import the sample tick data into a local SQLite DB (creates ./data/EURUSD.db)
IMPORT_HISTDATA_CSV_FILES="examples/sample-data/EURUSD-2021-01.csv" \
INSTRUMENT="EURUSD" \
go run ./cmd/import-histdata
# 2. Backtest the RSI strategy against it
PRICE_SOURCE="LOCAL_DB" \
PRICE_DB_FILE="./data/EURUSD.db" \
INSTRUMENT="EURUSD" \
STRATEGY="rsi" \
CANDLE_DURATION="1m" \
YEAR_FROM=2021 MONTH_FROM=1 YEAR_TO=2021 MONTH_TO=1 \
go run ./cmd/backtestingThe backtest prints a trade-by-trade log and a summary (positions, win rate, performance in pips), writes results/backtesting_result.csv, and serves an interactive chart at http://localhost:8080/chart.
See .env.example for every configuration variable and its default.
| Broker | Demo account | Paperwallet trading | Real trading | Backtesting |
|---|---|---|---|---|
| IG.com | ✅ | ❌ | ✅ | ✅ |
| Coinbase | ❌ | ✅ | ❌ | ✅ |
The Trader is the nerve center: it receives prices from a broker, forwards them to your strategy, and executes the orders the strategy returns.
- The trader sends closed candles (what is a candlestick?) and the current tick to the strategy.
- The strategy optionally feeds indicators and reads their latest values.
- The strategy decides which positions to open and which to close.
- The trader executes those orders and closes positions through the broker API.
internal/broker— theBrokerinterface plus IG and Coinbase implementations.internal/paperwalletsimulates fills for brokers without a sandbox.internal/strategy— theStrategyinterface and example strategies:rsi,rsiadx,sma10,stochrsi,doji,engulfing,harami,lowcandle,scalper,heikinashi.pkg/indicator— theIndicatorinterface and implementations (SMA, RSI, ADX, Stoch, StochRSI) wrapping go-talib.pkg/eo— environment overlays that adapt a strategy to market volatility (e.g. require a stronger signal in dangerous conditions).pkg/chart— renders the equity curve and price chart as HTML.
New to the code? Start with the Strategy interface, then read internal/strategy/rsi as a worked example.
The backtest module replays historical prices through your strategy. Configure trading fees and spreads to approximate real conditions.
It can also render an equity curve:
Price data comes from a local SQLite database. Import your own histdata.com CSV files with cmd/import-histdata — the same tool used in the quick start.
Contributions are welcome. See CONTRIBUTING.md for how to build, test, lint, and add a new strategy or indicator.
The developers are not liable for any losses arising from buying or selling securities. All included strategies are examples and are in no case ready trading systems. Trade at your own risk.