explaingit

shinnytech/tqsdk-python

4,696PythonAudience · dataComplexity · 3/5Setup · moderate

TLDR

TqSdk is a Python library for building automated trading strategies in Chinese financial markets, covering futures, options, and stocks, with real-time data, backtesting, and live order placement in the same codebase.

Mindmap

mindmap
  root((TqSdk))
    What it does
      Algorithmic trading
      Chinese markets
      Real time data
    Data
      Historical ticks
      Candlestick bars
      In memory storage
    Modes
      Backtest
      Simulation
      Live trading
    Tech Stack
      Python
      pandas
      numpy
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Write a Python script that automatically trades futures contracts based on a price spread between two contract months.

USE CASE 2

Backtest a candlestick-based trading strategy on historical Chinese futures data without setting up any database.

USE CASE 3

Run live trading on multiple accounts simultaneously in one Python script with a shared real-time data feed.

Tech stack

Pythonpandasnumpy

Getting it running

Difficulty · moderate Time to first run · 30min

Requires a Shinnytech account for live market data and a Chinese futures broker account for live order placement.

In plain English

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.

Copy-paste prompts

Prompt 1
Using TqSdk, write a Python strategy that monitors the price spread between two futures contracts and places orders when the spread exceeds a threshold.
Prompt 2
How do I backtest a moving-average crossover strategy on historical Chinese futures data using TqSdk?
Prompt 3
Show me how to use TqSdk's target-position API to manage a futures position without handling individual order details.
Prompt 4
Connect TqSdk to a simulated trading account and run a paper-trading test of my strategy before using real money.
Open on GitHub → Explain another repo

← shinnytech on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.