Quantstorm is a quant-centric platform for backtesting and live trading, providing a unified and trader-friendly interface for developing, backtesting, and deploying dependable trading strategies.
- Unified backtesting and live trading framework
- Stateful strategy abstraction
- Broker abstraction for multi-exchange compatibility
- K-line data abstraction
- Extensible indicator
This software is provided for educational and research purposes only. It is not intended as financial advice or an invitation to trade. Any use of this software for real-money trading is ENTIRELY AT YOUR OWN RISK.
You should NEVER RISK FUNDS YOU ARE NOT PREPARED TO LOSE. The authors, contributors, and any affiliated parties * make NO guarantees regarding the accuracy, reliability, or profitability of the software* and accept NO liability for any direct or indirect loss arising from its use.
Before deploying any trading strategy in live markets, YOU MUST FIRST BACKTEST IT AND RUN IT IN A SIMULATED ENVIRONMENT to understand its behavior, limitations, and potential outcomes.
It is strongly recommended that you possess solid programming and trading knowledge. You are encouraged to review and audit the source code to fully understand the underlying mechanisms.
Install pnpm, then run:
$ pnpm install
Copy .env.example
to .env
and fill in the configuration.
All strategies in Quantstorm are implemented by extending the StrategyAbstract
base class and must be explicitly
registered in the StrategyRegistry.
init(args: string)
is called once at the start of strategy execution. It is responsible for setting up the
strategy’s internal state and dependencies.
- The
args
parameter (a JSON string) allows for dynamic configuration. - Typical
args
include:- Trading pair (e.g.,
BTC/USDT
) - Order size
- Selected exchange/broker
- Any strategy-specific parameters or flags
- Trading pair (e.g.,
next()
contains the core trading logic and is executed at fixed intervals. It is used to react to new market data,
generate trading signals, and perform trading actions (e.g., long/short).
- The interval defines the period between two strategy executions
- Configurable interval for backtesting (e.g.,
1m
,15m
) - Defaults to 5 seconds for live trading
- Configurable interval for backtesting (e.g.,
- Create a mock
service: BacktestService
(see backtest.service.spec.ts) - Write a unit test:
it("should backtest the strategy", async () => {
const result: BacktestResult = await service.run(
strategyInstance, // A strategy object
strategyArgs, // Arguments to initialize the strategy
startTimestamp, // Backtest start timestamp
endTimstamp, // Backtest end timestamp
executionInterval // Backtest execution interval
);
});
- Run the test case and obtain backtesting result instance
result: BacktestResult
Modify and run the test case should build Binance K-line data set
in backtest.feeder.service.spec.ts
Backtest Demo strategy by running the test case
should backtest the demo strategy
in backtest.service.spec.ts
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
Call the endpoint /backtest/build/kline
with arguments:
- base: Base currency (e.g.,
BTC
) - quote: Quote currency (e.g.,
USDT
) - interval: Strategy execution interval (e.g.,
1m
,15m
) - start: Start date in
YYYY-MM-DD
format - end: End date in
YYYY-MM-DD
format
Access the endpoint /backtest/strategy/{name}
with arguments:
- {name}: Strategy name (e.g.,
Demo
) - start: Start timestamp (UNIX format)
- end: End timestamp (UNIX format)
- interval: Strategy execution interval (e.g.,
1m
,15m
) - base: Base currency (e.g.,
BTC
) used for visualization - quote: Quote currency (e.g.,
USDT
) used for visualization and balance calculation - args: Arguments to initialize the strategy
- Locally run Quantstorm on port
8888
- Backtest the Demo strategy via the URL below
http://localhost:8888/backtest/strategy/Demo?start=1722427200&end=1722454200&interval=15m&base=BTC"e=USDT&args={"base":"BTC","quote":"USDT","size":1,"interval":"30m"}
- Install Docker Compose
- In the root directory:
$ docker compose up -d
This launches:
- Quantstorm
- MariaDB
- Adminer
Call the endpoint /executor/execute/{name}/{id}
with arguments:
- {name}: Strategy name
- {id}: Custom unique identifier for the strategy instance
- args: Arguments to initialize the strategy
Access the endpoint /executor/stop/{id}
with arguments:
- {id}: Custom unique identifier for the strategy instance