easytrader Documentation

repository·master·Indexed 27 days ago

https://github.com/shidenggui/easytrader

A Python-based quantitative trading library supporting various interfaces including Tonghuashun client simulation, the official miniqmt interface, and Xueqiu portfolio management. It enables stock quantitative trading, remote client operation, and the ability to track simulated trading signals from platforms like JoinQuant and RiceQuant.

Tokens
4.8K
Snippets
7
Records
38
Agent score
95%

What's inside easytrader

  1. Overview of easytrader capabilities

    master

    easytrader is a quantitative trading library that provides several automation and simulation capabilities:

    • Universal Tonghuashun (同花顺) Client Simulation: Automates operations on the Tonghuashun client.
    • Official Brokerage Interfaces: Supports the miniqmt official quantitative interface.
    • Snowball (雪球) Support: Supports portfolio rebalancing and tracking for Snowball portfolios.
    • Remote Control: Supports remote operation of the trading client.
    • Simulation Tracking: Supports tracking simulated trades from platforms like joinquant and ricequant.
  2. Overview of easytrader features

    master

    easytrader is a Python library designed for quantitative stock trading. Key capabilities include:

    • Stock Quantitative Trading: General framework for executing quantitative strategies.
    • Tonghuashun (同花顺) Client Simulation: Provides universal simulated operations for the Tonghuashun client.
    • miniqmt Support: Supports the official miniqmt quantitative interface provided by brokers.
    • Xueqiu (雪球) Portfolio Management: Supports rebalancing and tracking for Xueqiu portfolios.
    • Remote Client Operation: Supports controlling trading clients remotely.
    • Simulated Trading Tracking: Supports tracking simulated trading from platforms like joinquant and ricequant.
  3. Track JoinQuant or RiceQuant simulated trading

    master

    You can automate trading by following simulated trading signals from joinquant (jq) or ricequant (rq).

    1. Initialize the Trader: Set up the broker account that will execute the trades (e.g., Xueqiu xq).
    2. Initialize the Follower: Create a follower for the target platform and log in.
    3. Connect Follower and Trader: Use the .follow() method to link the signal source to the execution account.

    Key Parameters for JoinQuant:

    • trade_cmd_expire_seconds: Defines the window (in seconds) for processing signals. Default is 120s. Increase this for testing.
    • cmd_cache: A boolean to prevent duplicate execution. It uses a cmd_cache.pk file to store history. Set to False to ignore cache.

    Key Parameters for RiceQuant:

    • run_id: The ID from the PT list.
  4. Initialize easytrader client

    master

    Import the library and use easytrader.use() to select the appropriate client type for your broker or platform.

    Available client types:

    • universal_client: General Tongshanghun (THS) client for multiple brokers.
    • ths: Specific broker-provided THS-based client (e.g., Yinhe/Galaxy).
    • xq: Xueqiu (Snowball) portfolio.
    • gj_client: Gujin Securities client.
    • htzq_client: Haitong Securities client.
    • ht_client: Huatai Securities client.
    import easytrader
    
    # Example: Using the general THS client
    user = easytrader.use('universal_client')
  5. Connect to THS clients

    master

    Depending on the client type, connection methods vary:

    Broker-specific THS clients (ths)

    These do not support automatic login. You must manually log in to the client software first, then use connect() with the path to the executable.

    Universal THS client (universal_client)

    Manual login is required once to save credentials (account, password, captcha) within the client. After that, you can use prepare() for automatic login.

    Other clients

    Non-THS clients can use prepare() for automatic login via function arguments or a JSON configuration file.

  6. Configure Tonghuashun (THS) client settings

    master

    To prevent incorrect order prices and client timeout locks, you must configure the Tonghuashun client with the following settings:

    1. System Settings > Interface Settings: Set 'Idle Timeout' (界面不操作超时时间) to 0.
    2. System Settings > Trading Settings: Set 'Default Buy Price', 'Default Buy Quantity', 'Default Sell Price', and 'Default Sell Quantity' all to Empty (空).

    Note: The client must not be minimized and must not be in 'Simplified Mode' (精简模式).

  7. Start the easytrader Trading Server

    master
    In remote mode, the Trading Server runs on a machine (typically a cloud server with a fixed IP) and manages the actual trading software (e.g., Tonghuashun xiadan.exe or Xueqiu xq). You can start the server using easytrader.server.run() and specifying a port.