$ show shinnytech/tqsdk-python
TqSdk is a Python SDK for quantitative trading in Chinese futures, options, and stock markets. It provides a unified async event-driven framework for real-time market data, historical data download, backtesting, simulation, and live trading through multiple broker gateways (CTP, SimNow, etc.). The core architecture centers on a TqApi class that manages WebSocket connections, diff-based data synchronization, and a wait_update() loop. It includes a comprehensive technical analysis library (tafunc/ta), target position management (TargetPosTask), risk management rules, and a web-based GUI. While primarily an application library for building trading strategies, it also contains data analysis components like technical indicators and backtest report generation, making it a hybrid tool with a strong application focus.
The LLM identified 3 files worth highlighting for reuse:
A self-contained module of 40+ technical analysis functions (MA, EMA, MACD, RSI, Bollinger Bands, etc.) and option Greeks calculations. It has no internal dependencies on the rest of TqSdk, making it easily extractable for any pandas-based analysis project. Each function follows a consistent signature (DataFrame in, DataFrame out) with clear docstrings and examples.
Implements a base Entity class that provides automatic attribute tracking and diff-based state management. All market data objects (Quote, Kline, Account, etc.) inherit from this class. The pattern enables efficient incremental updates from WebSocket diffs and supports is_changing() detection. Could be extracted as a lightweight state management utility for any real-time data application.
Implements TargetPosTask, a singleton per account-symbol that automatically adjusts positions to a target volume. It handles order splitting, price chasing, offset priority, and exchange minimum volume constraints. The pattern is reusable for any trading system needing automated position management with configurable execution logic.