$ show shidenggui/easytrader
easytrader is a Python library for automating Chinese stock trading. It supports multiple broker types through three parallel branches: (1) Windows desktop GUI automation using pywinauto for brokers like ιΆζ²³, εζ³°, ε½ι, etc.; (2) Web API trading for Xueqiu (ιͺη) portfolio rebalancing; (3) Official QMT SDK integration via miniqmt for θΏ ζ-based brokers. Additionally, it provides strategy following from JoinQuant, RiceQuant, and Xueqiu platforms, enabling mirroring of simulated trades into real accounts. The architecture uses a factory pattern (easytrader.use() and easytrader.follower()) to create broker-specific trader instances, with abstract base classes (ClientTrader, WebTrader, BaseFollower) implementing common operations like buy/sell/query. A Flask-based remote server mode allows separation of trading client and strategy execution machines. The code is well-structured with clear separation of concerns: config files define broker-specific UI control IDs, strategy patterns for grid data extraction (Copy, Xls) and data refresh (Switch, Toolbar) allow customization without changing core logic. The follower framework includes command expiration, slippage modeling, and multi-user/multi-strategy support. The miniqmt module wraps the proprietary xtquant SDK into the same easy-to-use interface. While the desktop GUI components are Windows-only and tightly coupled to specific broker client binaries, the web-based trader and follower modules are more portable. The library has been actively maintained for years with a large user base (10k+ stars), though some dependencies like pywinauto 0.6.6 and Python 3.6+ show signs of technical drift.
The LLM identified 4 files worth highlighting for reuse:
BaseFollower provides a reusable framework for tracking and executing trading strategies from platforms like JoinQuant, RiceQuant, and Xueqiu. It implements a thread-safe trade queue, command expiration via cached pickle file, slippage calculation, and multi-user/strategy support. The class is designed to be extended with platform-specific authentication and transaction parsing (e.g., JoinQuantFollower, XueQiuFollower). Its isolation from GUI/API specifics makes it a strong candidate for extraction into other trading automation projects.
IGridStrategy and its implementations (Copy, Xls, WMCopy) solve the common problem of extracting tabular data from Windows Win32 grid controls (CVirtualGridCtrl) used in Chinese trading clients. The Copy strategy uses clipboard and pandas parsing, Xls saves to temporary XLS file, and WMCopy uses direct window messages. This pattern is cleanly abstracted via an interface, and the strategies handle platform quirks like verification code popups. The module could be reused in any Windows GUI automation project that needs to scrape grid data.
IRefreshStrategy provides two implementations for refreshing data in the trading client: Switch simulates F5 key press, and Toolbar clicks a specified toolbar button. This small but well-factored component demonstrates the strategy pattern applied to a simple repetitive UI task. It can be extracted and adapted for other GUI automation scenarios where data refresh mechanisms vary.
A collection of standalone utility functions for Chinese stock market operations: get_stock_type() determines exchange (bj/sh/sz) from stock code, get_30_date() provides date range for query parameters, and get_today_ipo_data() scrapes Xueqiu for today's IPO listings. These functions have no internal dependencies and can be reused in any Python project dealing with Chinese stocks.