Kungfu Trader Client Usage Guide

·

Introduction

Kungfu Trader's operating interface utilizes a modular free integration solution for enhanced flexibility and visibility, designed to be more intuitive and efficient. The system organizes functions into groups and adapts them to different panels. Users can flexibly use and adjust these panels according to their operating habits.

The modular system boasts more flexible statistical capabilities. For instance, the position panel can separately count holdings for strategies, accounts, and trading algorithms based on the selected content.

Trading Account Panel

Users can add new accounts, delete/edit existing accounts, create account groups, and individually start/stop specific account processes within this panel.

Adding an Account

  1. Click the "Add" button in the trading account panel.
  2. Select the counter to use for adding the account: CTP (futures counter), XTP (stock counter), or SIM (simulation counter).

    Note: SIM counter data is random and for reference only.
  3. Example: Adding a "CTP Account"

    • In the second step, select to add a CTP counter. After clicking confirm, an account setup pop-up window will appear.
    • Fill in the required fields (Account Name, Account ID, Password, etc.) as per the provided table.
    • After completion, click "OK" to finish the account configuration. You can then click the process switch button to run the account.
  4. Similar processes apply for adding "CTP Penetration", "XTP", and "Kungfu Simulation (SIM)" accounts, each with their specific field requirements detailed in the original tables.

Account Startup

Click the process button for the account to run it. A process status of "Ready" indicates a successful login.

Viewing/Editing Account Information

Click the "Account Settings" button. Users can view and modify the account's set information and parameters.

Note: Modifying account information while the process is running will not take effect immediately. A manual restart of the account process is required for new configurations to apply.

Account Logs

Logs help users monitor account operation and troubleshoot issues. Click the log button to display the account's real-time operation logs in a new window.

Deleting an Account

Click the delete button to close the account trading process, clear all account data, and delete the account.

Warning: Deleting an account will clear all associated data, including order records, trade records, and transaction logs. Please download any data you wish to keep before deletion.

Market Data Source Panel

The system retrieves market data through the market data address under the account. Therefore, for market data sources, please use the same account and password as the trading account.

Adding a Market Data Source

  1. Click the "Add" button in the upper right corner of the market data source panel.
  2. Select the counter API: CTP, XTP, CTP Penetration, OKX, BinanceFuture, or Kungfu Simulation (SIM).
  3. The setup process is similar to adding accounts, requiring specific details like Account ID, Password, Broker Code, Market Data Address, and Port, depending on the chosen counter (CTP, XTP, etc.).

Market Data Source Startup

Click the process button for the market data source to run it. A process status of "Ready" indicates successful market data connection.

Viewing/Editing Market Data Source Information

Click the "Market Data Source Settings" button. Users can view and modify the parameters. Changes made while the process is running require a manual restart to take effect.

Market Data Source Logs

Click the log button to open the real-time operation logs for the market data source in a new window.

Deleting a Market Data Source

Note: Deleting a market data source will stop its process and prevent receiving new data, which may affect order placement for operators, strategy processes, and trading tasks. Check if any processes depending on this source are running before closing.

Strategy Process Panel

This panel acts as a strategy pool, allowing users to import strategy files and edit code. Code modifications are saved in real-time.

Pro Tip: Combined with Kungfu's flexible multi-panel scheduling, selecting a strategy enables the system to display that strategy's holdings, order records, and trade records in their respective panels.

Adding a Strategy

  1. Click the "Add" button and fill in the strategy information (Strategy ID, Strategy Path to a local .py file).
  2. Click "OK" to complete the addition.
Note: The strategy file location must be on the same drive as the Kungfu system installation directory. Before starting a strategy, ensure the required Trading (TD) and Market Data (MD) process connections are ready, as their unavailability will cause strategy order placement to fail.

Starting a Strategy

Click the strategy process button to start it. Click again to stop a running strategy.

Viewing Strategy Logs

Click the log button to view the strategy's operation logs in a new window.

Real-Time Strategy Code Editing

The client features an embedded IDE for editing local strategies. Click the edit button to open the strategy editing pop-up; modifications are saved in real-time.

Deleting a Strategy

Click the delete button behind the strategy to delete it. The system will close the strategy process and stop its order placement before deletion.

Playback Tool

This tool helps users debug code and review strategies after market hours by simulating intraday trading conditions. It can add logs, use live data for simulated matching, and test different scenarios.

Playback - Adding More Detailed Logs

Without a matcher, the playback tool only supports adding logs (modifying log level/adding log print code).

Playback - Changing Strategy Logic Using Live Data Simulation

The matcher helps simulate trade matching using live market data. It is mandatory when users change the order placement logic and need to use playback.

Playback - Testing Different Commission Cost Impacts

Users can test performance under different futures commission rates using live data.

Diagnostic Tool

Journal files record process behaviors in the system. The diagnostic tool allows browsing and locating this data via timestamp, message type filtering, and keyword search.

Hint: Use this tool to locate information, review strategy performance, and troubleshoot operational issues.

Viewing Strategy Order Performance via Diagnostic Tool

  1. Click the small eye icon behind the process to open the tool.
  2. Click "Enter Visualization".
  3. The visualization interface shows sessions, instruments, charts with signals, and detailed journal records.

Viewing a Single Process's Journal File

Trading accounts, market data sources, strategy processes, trading tasks, and operator panels all support viewing their journal data via the diagnostic tool.

Viewing All Processes' Journal Files

Click File (top left) -> Open Diagnostic Tool. A new window will display journal data for all processes.

Locating Journal Information

Supported filtering methods: filter by channel, filter by message type, jump by timestamp.

Diagnostic Tool - Keyword Search Function

Use Ctrl+F to bring up the search box. Use the Enter shortcut to jump to the next search result.

Operator Panel

Operators compute results that can be subscribed to by other operators or strategies, allowing for nested calculations. This reduces repetitive computations and improves strategy efficiency.

Operators are mainly divided into operator plugins (official, parameter-based) and operator files (user-written Python files).

Adding an Operator

  1. Click the "Add" button.
  2. Select the type of operator to add (File/Plugin).
  3. Follow the corresponding guide below based on the chosen type.

Adding a Bar Data Operator Plugin

  1. Select "Plugin" in the operator type window.
  2. Click "Confirm".
  3. Fill in parameters (Bar ID, Data Source, Instrument, Cycle in seconds).

Adding an Operator File

  1. Select "File" in the operator type window.
  2. Click "Confirm".
  3. Fill in the Operator ID, Remarks, and path to the local .py operator file.

Operator Code Example Reference

Refer to the Operator API Documentation for details.

Note:

  1. After a strategy subscribes to an operator, it still needs to subscribe to a market data source in the strategy code to execute orders normally.
  2. Ensure the startup order aligns with dependencies for nested operators.
  3. Strategies waiting for operator data will remain listening until the operator comes online; they won't error.
  4. Strategies using multiple data sources will continue using working sources if one fails.

Position Panel

Supports Search, Refresh, and Export functions. It allows flexible statistics: selecting an account/strategy in the trading account list/strategy list makes the position panel show holdings for that specific account/strategy.

Position Summary Panel

Groups and calculates the total holdings by instrument for all accounts started that day.

Order Record Panel

Supports viewing order details and operating on orders (cancel, modify, pre-cancel). Offers search, filtering for unfinished orders, export by trading/natural day, query non-current day records, real-time statistics, and actions like cancel/all cancel, modify, pre-cancel.

Order Status Correspondence Table

Lists statuses like Submitted, Pending, Trading, Pending Cancel, Fully Filled, Fully Cancelled, Partially Cancelled Partially Filled, Error, Lost.

Real-Time Statistics

Clearly displays the order placement situation per instrument.

Trade Record Panel

Supports Search, Export, and Query functions. Offers search, export by trading/natural day, query non-current day records, and real-time statistics (volume, system delay).

Trade Record - Real-Time Statistics

Quickly grasp the overall trade situation of an account/strategy.

Trading Task Panel

The system currently offers four trading tasks: "Conditional Order", "Excel Order", "Iceberg", and "TWAP" for automated order placement.

  1. Click the "Add" button in the "Trading Task" panel.
  2. Select the desired trading task and click OK.
Hint: Trading tasks support pause and restart functions. Upon restart, if the end time hasn't been reached, the system recalculates the single order quantity based on remaining time and uncompleted volume to continue the task.

Conditional Order

Allows setting price/time conditions. Triggers order placement based on these conditions.

Excel Order

Use for multi-instrument timed orders. Requires a specific Excel format.

Iceberg Order

Recommended for very large orders to disperse volume and minimize market impact. The next order is only triggered after the previous one is fully filled.

TWAP Remaining Cumulative & TWAP Remaining Average

Recommended for dispersing volume and improving fill probability (orders evenly over a set time range). They differ in how they handle uncompleted quantities and the final order.

Market Data Subscription Panel

Allows users to subscribe to instruments of interest, typically used with the "Depth Market Data" panel.

Depth Market Data Panel

Displays dynamic buy/sell ten-level quote information. Green is Ask, Red is Bid.

Pro Tip: Clicking a quote level in depth market data auto-fills the order panel for quick order placement. Clicking an instrument in other panels displays its quotes here.

Order Panel

Used for placing standard orders, split orders (into multiple simultaneous orders), and pre-placed orders (for futures).

Pro Tip: Clicking an instrument in Position/Market Data Subscription/Position Summary panels auto-fills the instrument code and price in the order panel.

Order Shortcuts

Supports keyboard shortcuts for the entire order process (e.g., focus panel, next field, confirm).

Pre-placed Order Record Panel

Supports batch pre-placed orders, single pre-placed orders, and pre-placed cancellations.

Adding a Pre-placed Order Panel

Add manually via the "Add" button -> "Pre-placed Order Record" to better track these orders.

Placing a Single Pre-placed Order

Placed during market break, becomes a standard order after opening.

Placing Batch Pre-placed Orders

Download a template, modify the CSV, import it, confirm, and place multiple pre-orders.

Note: Pre-placed Cancellation ≠ Cancelling a Pre-placed Order. Pre-placed cancellation cancels orders placed before the break. Cancelling a pre-placed order cancels the pre-placed order itself before it triggers.

Cancelling a Single Pre-placed Order

Can be done from the Order Record panel or the Pre-placed Order Record panel.

Placing a Single Pre-placed Cancellation

Done via the "Pre-cancel" button in the Order Record panel for orders placed before the break.

Cancelling a Single Pre-placed Cancellation

Can be done from the Order Record panel or the Pre-placed Order Record panel.

Global Settings

Access via the settings button (bottom left) or Ctrl+,.

System Settings

Includes local Home path, global log level, language, TD auto-restart, skip archiving settings.

Performance Settings

Includes ultra-fast mode, skip UI process calculation, pure monitoring mode, skip position market data subscription.

Strategy Settings

Allows using a local Python installation (must be version 3.9.x) if modules are missing in the built-in Python.

Currency Settings

Displays instrument currency in the position panel (only for OTC counters).

Trading Settings

Includes trade prompt sound, fat-finger threshold, close position threshold, skip order confirmation pop-up, trading limits, position table configuration, skip minute-position sync.

Code Editor Settings

Indentation type (TAB/Space) and length.

Version Update Settings

Enable/disable automatic update checks on startup.

Futures Commission Settings

Set manually for instruments not held in the account.

Scheduled Tasks Settings

Add tasks for daily automatic restart of TD/MD processes or automatic strategy start/stop without client restart.

Control Center

Monitor process statuses here. The font turns red if a system service is interrupted, prompting a restart.

Plugin Library

Kungfu offers various plugins (e.g., high-precision backtesting, counter plugins, algorithm plugins). Contact for these or custom plugins.

Frequently Asked Questions

How do I add a new futures trading account?
Navigate to the Trading Account Panel and click the 'Add' button. Select 'CTP' as the counter type, then fill in all the required fields provided by your broker, such as Broker ID, Account ID, and Password. Ensure the MD and TD addresses and ports are correct. Finally, click 'OK' to save the configuration and start the account process.

What should I do if my strategy fails to place orders?
First, check the strategy logs in the Strategy Process Panel for any error messages. Verify that the required Trading (TD) and Market Data (MD) processes linked to the strategy show a 'Ready' status. Also, confirm the strategy code has no syntax errors and correctly subscribes to necessary market data feeds for its logic.

Can I use custom Python libraries with my strategies?
Yes, you can use custom libraries by enabling the 'Use Local Python' option in Global Settings under the Strategy tab. You must direct the setting to a local Python 3.9.x installation where your required libraries are pre-installed using pip. Remember to install the Kungfu wheel file into this local environment as instructed.

What is the purpose of the Diagnostic Tool?
The Diagnostic Tool is essential for reviewing historical system performance and troubleshooting. It allows you to inspect journal files, which record all process activities like quote data and order messages. You can filter data by time, message type, or keyword to analyze strategy behavior, order delays, or pinpoint the cause of errors after they occur.

How does the Playback Tool help in strategy development?
The Playback Tool lets you simulate a trading session using historical market data. This is invaluable for backtesting logic changes without risking capital. You can replay a past session, see how a modified strategy would have performed, add debug logs for deeper analysis, and test different commission structures to understand their impact on profitability.

What's the difference between TWAP Remaining Cumulative and Average?
Both TWAP types aim to execute orders evenly over time. The key difference is in handling partially filled orders. 'Remaining Cumulative' adds the unfilled amount directly to the next order, potentially creating larger subsequent orders. 'Remaining Average' spreads the unfilled amount evenly across all remaining orders, maintaining a more consistent order size but recalculating the volume for each step.