Write a Python script that automatically trades futures contracts based on a price spread between two contract months.
Backtest a candlestick-based trading strategy on historical Chinese futures data without setting up any database.
Run live trading on multiple accounts simultaneously in one Python script with a shared real-time data feed.
Requires a Shinnytech account for live market data and a Chinese futures broker account for live order placement.
TqSdk is an open-source Python library for building automated trading strategies in Chinese financial markets. It is developed and maintained by Shinnytech, a company that provides futures software and market data services in China. The library covers futures, options, and stocks, and it handles the full workflow from getting data to placing live orders. The library gives you real-time market prices and historical tick and candlestick data for all tradable contracts, going back to when each contract first listed. All of this data lives in memory, so there is no database to set up or maintain. It connects to Shinnytech's market gateway for live prices and to futures brokers through standard trading protocols, supporting about 90% of Chinese futures companies. For strategy development, TqSdk includes close to one hundred technical indicator functions, and you can use it alongside the pandas and numpy Python libraries for data analysis. There is no required framework structure, you write a Python loop and call the library's functions directly. The same code can run as a backtest on historical data, a simulation against live prices, or a live trading strategy with real money, with minimal changes between modes. Multiple accounts can run simultaneously in one script. The README includes an example showing a spread-trading strategy between two futures contract months. The strategy subscribes to both contracts, watches the price difference, and automatically adjusts positions using a target-position helper that handles the order details. The whole example is around 15 lines of Python. The library requires Python 3.8 or newer and can be installed with pip. Documentation is available in Chinese on Shinnytech's website, and there is a community QQ group for user discussion.
← shinnytech on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.