or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

cli-commands.mdconstants-enums.mddata-access.mddata-models.mdframework-core.mdindex.mdportfolio-management.mdstrategy-execution.mdtrading-api.md

cli-commands.mddocs/

0

# CLI Commands

1

2

Command line tools for strategy execution, data management, configuration generation, and system administration. The RQAlpha CLI provides comprehensive tooling for all aspects of algorithmic trading workflow from development to production.

3

4

## Capabilities

5

6

### Strategy Execution

7

8

Primary command for running trading strategies with various options and configurations.

9

10

```bash

11

# Run a strategy file

12

rqalpha run strategy.py

13

14

# Run with custom configuration

15

rqalpha run strategy.py --config config.yml

16

17

# Run with inline parameters

18

rqalpha run strategy.py --start-date 2020-01-01 --end-date 2020-12-31 --stock-starting-cash 100000

19

20

# Paper trading mode

21

rqalpha run strategy.py --run-type p

22

23

# Enable analysis and plotting

24

rqalpha run strategy.py --plot

25

```

26

27

### Data Bundle Management

28

29

Commands for managing market data bundles required for backtesting.

30

31

```bash

32

# Create data bundle using RQDatac

33

rqalpha create-bundle

34

35

# Update existing data bundle

36

rqalpha update-bundle

37

38

# Download pre-built data bundle

39

rqalpha download-bundle

40

41

# Check bundle integrity

42

rqalpha check-bundle

43

44

# Create bundle with specific parameters

45

rqalpha create-bundle --start-date 2015-01-01 --end-date 2023-12-31

46

```

47

48

### Configuration Management

49

50

Commands for generating and managing strategy configurations.

51

52

```bash

53

# Generate default configuration file

54

rqalpha generate-config

55

56

# Generate config with specific parameters

57

rqalpha generate-config --config-path my_config.yml

58

59

# Generate minimal configuration

60

rqalpha generate-config --minimal

61

```

62

63

### Example Generation

64

65

Commands for creating example strategies and learning materials.

66

67

```bash

68

# Generate example strategies

69

rqalpha generate-examples

70

71

# Generate examples in specific directory

72

rqalpha generate-examples --output-dir examples/

73

74

# Generate specific example type

75

rqalpha generate-examples --type buy_and_hold

76

```

77

78

### Mod Management

79

80

Commands for managing RQAlpha modules (plugins) and extensions.

81

82

```bash

83

# List available mods

84

rqalpha mod list

85

86

# Install mod from source

87

rqalpha mod install path/to/mod

88

89

# Install mod from git repository

90

rqalpha mod install git+https://github.com/user/rqalpha-mod.git

91

92

# Uninstall mod

93

rqalpha mod uninstall mod_name

94

95

# Enable mod

96

rqalpha mod enable mod_name

97

98

# Disable mod

99

rqalpha mod disable mod_name

100

101

# Show mod information

102

rqalpha mod show mod_name

103

```

104

105

### System Information

106

107

Commands for system information and version management.

108

109

```bash

110

# Show version information

111

rqalpha version

112

113

# Show detailed version and system info

114

rqalpha version --verbose

115

```

116

117

## Command Reference

118

119

### run Command

120

121

Execute trading strategies with comprehensive options:

122

123

```bash

124

rqalpha run [OPTIONS] STRATEGY_FILE

125

126

Options:

127

--config PATH Configuration file path

128

--start-date TEXT Backtest start date (YYYY-MM-DD)

129

--end-date TEXT Backtest end date (YYYY-MM-DD)

130

--stock-starting-cash FLOAT Initial stock account cash

131

--future-starting-cash FLOAT Initial futures account cash

132

--bond-starting-cash FLOAT Initial bond account cash

133

--benchmark TEXT Benchmark instrument ID

134

--frequency TEXT Data frequency (1d, 1m, 5m, etc.)

135

--run-type TEXT Run type (b=backtest, p=paper, r=live)

136

--matching-type TEXT Order matching type

137

--commission-multiplier FLOAT Commission multiplier

138

--margin-multiplier FLOAT Margin multiplier

139

--slippage FLOAT Slippage factor

140

--account TEXT Account configuration

141

--position TEXT Initial position

142

--plot Enable plotting

143

--progress Show progress bar

144

--log-level TEXT Log level (debug, info, warning, error)

145

--logger TEXT Logger configuration

146

--output-file PATH Output file for results

147

--report PATH Generate report file

148

--help Show help message

149

```

150

151

### create-bundle Command

152

153

Create market data bundle:

154

155

```bash

156

rqalpha create-bundle [OPTIONS]

157

158

Options:

159

--start-date TEXT Bundle start date (YYYY-MM-DD)

160

--end-date TEXT Bundle end date (YYYY-MM-DD)

161

--bundle-path PATH Bundle output path

162

--adjust TEXT Price adjustment type (pre, post, none)

163

--frequency TEXT Data frequency

164

--help Show help message

165

```

166

167

### mod Command

168

169

Manage RQAlpha modules:

170

171

```bash

172

# List all mods

173

rqalpha mod list [OPTIONS]

174

175

Options:

176

--enabled-only Show only enabled mods

177

--disabled-only Show only disabled mods

178

179

# Install mod

180

rqalpha mod install [OPTIONS] SOURCE

181

182

Options:

183

--force Force reinstall

184

--editable Install in development mode

185

186

# Uninstall mod

187

rqalpha mod uninstall [OPTIONS] MOD_NAME

188

189

Options:

190

--force Force uninstall

191

192

# Enable/disable mod

193

rqalpha mod enable MOD_NAME

194

rqalpha mod disable MOD_NAME

195

196

# Show mod info

197

rqalpha mod show MOD_NAME

198

```

199

200

## Configuration File Structure

201

202

### Basic Configuration

203

204

```yaml

205

base:

206

start_date: 2020-01-01

207

end_date: 2020-12-31

208

frequency: 1d

209

accounts:

210

stock: 100000

211

benchmark: 000300.XSHG

212

strategy_file: strategy.py

213

214

extra:

215

log_level: info

216

context_vars:

217

my_var: value

218

219

mod:

220

sys_progress:

221

enabled: true

222

show: true

223

224

sys_analyser:

225

enabled: true

226

plot: true

227

output_file: results.pkl

228

report_save_path: report.html

229

230

sys_simulation:

231

enabled: true

232

matching_type: current_bar

233

slippage: 0.0001

234

commission_multiplier: 1.0

235

```

236

237

### Advanced Configuration

238

239

```yaml

240

base:

241

start_date: 2020-01-01

242

end_date: 2020-12-31

243

frequency: 1m

244

accounts:

245

stock: 1000000

246

future: 500000

247

bond: 200000

248

benchmark: 000300.XSHG

249

strategy_file: strategy.py

250

persist:

251

persist_mode: real_time

252

redis_url: redis://localhost:6379

253

254

extra:

255

log_level: debug

256

context_vars:

257

universe_size: 50

258

rebalance_frequency: 20

259

260

mod:

261

sys_progress:

262

enabled: true

263

show: true

264

265

sys_analyser:

266

enabled: true

267

plot: true

268

plot_save_file: plots.png

269

output_file: results.pkl

270

report_save_path: report.html

271

benchmark_save_path: benchmark.pkl

272

273

sys_simulation:

274

enabled: true

275

matching_type: next_bar

276

slippage: 0.0002

277

commission_multiplier: 1.5

278

margin_multiplier: 1.0

279

280

sys_transaction_cost:

281

enabled: true

282

stock_commission: 0.0003

283

stock_commission_min: 5

284

future_commission: 0.00003

285

286

sys_risk:

287

enabled: true

288

max_position_size: 0.1

289

max_drawdown: 0.2

290

```

291

292

## CLI Usage Examples

293

294

### Basic Strategy Execution

295

296

```bash

297

# Simple backtest

298

rqalpha run my_strategy.py \

299

--start-date 2020-01-01 \

300

--end-date 2020-12-31 \

301

--stock-starting-cash 100000

302

303

# With plotting and analysis

304

rqalpha run my_strategy.py \

305

--start-date 2020-01-01 \

306

--end-date 2020-12-31 \

307

--stock-starting-cash 100000 \

308

--plot \

309

--output-file results.pkl

310

311

# Paper trading

312

rqalpha run my_strategy.py \

313

--run-type p \

314

--stock-starting-cash 50000 \

315

--log-level debug

316

```

317

318

### Data Management Workflow

319

320

```bash

321

# Initial setup - create data bundle

322

rqalpha create-bundle \

323

--start-date 2015-01-01 \

324

--end-date 2023-12-31

325

326

# Regular updates

327

rqalpha update-bundle

328

329

# Verify data integrity

330

rqalpha check-bundle

331

332

# Alternative: download pre-built bundle

333

rqalpha download-bundle

334

```

335

336

### Configuration Workflow

337

338

```bash

339

# Generate default configuration

340

rqalpha generate-config --config-path my_config.yml

341

342

# Edit configuration file

343

vim my_config.yml

344

345

# Run strategy with configuration

346

rqalpha run my_strategy.py --config my_config.yml

347

```

348

349

### Development Workflow

350

351

```bash

352

# Create example strategies for learning

353

rqalpha generate-examples --output-dir examples/

354

355

# Run example strategy

356

rqalpha run examples/buy_and_hold.py \

357

--start-date 2020-01-01 \

358

--end-date 2020-12-31 \

359

--stock-starting-cash 100000

360

361

# Install development mod

362

rqalpha mod install git+https://github.com/user/my-rqalpha-mod.git

363

364

# Enable the mod

365

rqalpha mod enable my_mod

366

367

# Test strategy with mod

368

rqalpha run my_strategy.py --config config_with_mod.yml

369

```

370

371

### Production Workflow

372

373

```bash

374

# Test strategy thoroughly

375

rqalpha run production_strategy.py \

376

--config production_config.yml \

377

--output-file backtest_results.pkl \

378

--report production_report.html

379

380

# Switch to paper trading

381

rqalpha run production_strategy.py \

382

--config production_config.yml \

383

--run-type p \

384

--log-level info

385

386

# Deploy to live trading (with proper safeguards)

387

rqalpha run production_strategy.py \

388

--config live_config.yml \

389

--run-type r \

390

--log-level warning

391

```

392

393

### Multi-Strategy Management

394

395

```bash

396

# Run multiple strategies with different configs

397

rqalpha run strategy1.py --config config1.yml --output-file results1.pkl &

398

rqalpha run strategy2.py --config config2.yml --output-file results2.pkl &

399

rqalpha run strategy3.py --config config3.yml --output-file results3.pkl &

400

401

# Wait for completion

402

wait

403

404

# Analyze results

405

python analyze_results.py results1.pkl results2.pkl results3.pkl

406

```

407

408

### System Administration

409

410

```bash

411

# Check system status

412

rqalpha version --verbose

413

414

# List all installed mods

415

rqalpha mod list

416

417

# Update data bundle weekly

418

crontab -e

419

# Add: 0 6 * * 1 /usr/local/bin/rqalpha update-bundle

420

421

# Clean old result files

422

find . -name "*.pkl" -mtime +30 -delete

423

```

424

425

### Integration with External Tools

426

427

```bash

428

# Generate configuration programmatically

429

python generate_config.py | rqalpha run strategy.py --config -

430

431

# Pipe results to analysis tool

432

rqalpha run strategy.py --output-file - | analysis_tool

433

434

# Use with Docker

435

docker run -v $(pwd):/workspace rqalpha/rqalpha \

436

run /workspace/strategy.py --config /workspace/config.yml

437

```