This guide provides a comprehensive overview of the Kungfu Quant trading system's client interface, designed for modularity, flexibility, and enhanced visibility to streamline your quantitative trading operations.
Core Concepts and Interface Overview
The system organizes functionality into distinct panels, allowing users to customize their workspace according to individual preferences. The modular architecture offers powerful statistical capabilities. For instance, the positions panel can display holdings aggregated by strategy, account, or trading algorithm based on your selection.
Trading Account Panel
This panel serves as the central hub for managing all your connected trading accounts. Here, you can add new accounts, delete or edit existing ones, create account groups, and individually start or stop an account's connection process.
Adding a New Trading Account
Initiate the process by clicking the "Add" button within the Trading Account panel.
You will then select the broker counter (API) you wish to connect to. The supported counters are:
- CTP: For futures trading.
- XTP: For stock trading.
- CTP Mini (Penetration): Dedicated for futures penetration testing. Do not use with live trading accounts.
- OKX: For cryptocurrency trading (OKX exchange).
- BinanceFuture: For cryptocurrency futures trading (Binance exchange).
- Kungfu Sim: A simulated counter using randomized data for testing purposes.
Example: Adding a CTP Account
After selecting the CTP counter, a configuration window will appear. Key fields include:
- Account Name: A custom remark for your reference.
- Account ID: Your broker-provided trading account ID (e.g., 089270).
- Password: Your broker-provided trading password.
- Broker ID: The code provided by your futures broker (e.g., 9999).
- Auth Code: The authorization code (for live accounts) or
0000000000000000for sim. - Client Name: Set this to
KUNGFU. - Client ID: For live accounts, use
TAURUS_KUNGFU_2.0; for sim, usesimnow_client_test. - Trade IP/Port: The address and port of the trading server.
- Sync External Orders: When enabled, orders placed outside Kungfu will be synced and marked as "External".
- Restore Today's Orders: Retrieves the day's order history from the broker upon startup.
👉 Explore more strategies for account configuration
Example: Adding an OKX Account
For connecting to OKX, the required fields are:
- Account Alias: A custom name for the account.
- Account: Can be any arbitrary name.
- Password: Your OKX trading password.
- API Key & Secret: Your OKX API credentials.
- Sync External Orders: Toggle for order syncing.
- Simulated Trading: Enable this for testnet/simulated accounts; disable for live trading.
Fill in the details and click "OK" to complete the setup. You can then toggle the process switch to start the account.
Managing Accounts
- Starting an Account: Click the process button. A "Ready" status indicates a successful login.
- Viewing/Editing: Click the "Account Settings" button to view or modify parameters. Note: Changes require a manual process restart to take effect if the account is running.
- Logs: Click the log button to open a real-time monitor for troubleshooting.
- Deletion: Click the delete button to remove the account. Warning: This action permanently erases all associated data, including order history and logs. Export any needed data beforehand.
Market Data Panel
This panel manages the connections to market data feeds.
Important Note: Kungfu retrieves market data through the connected trading accounts. Therefore, the login credentials for a market data source typically must match those of its corresponding trading account.
Adding a Market Data Source
Click the "Add" button in the Market Data panel and select the desired counter API (CTP, XTP, OKX, BinanceFuture, Sim).
The configuration fields for each counter (like CTP or XTP) will mirror the information used in their respective trading account setup. For counters like OKX and BinanceFuture, you can toggle specific data streams (Ticker, Transaction, Rate data), keeping in mind their potential memory usage.
Managing Market Data Sources
Operations for market data sources are similar to trading accounts: start/stop the connection, view/edit settings (requires restart), check logs, and delete sources. Caution: Deleting an active market data source will stop the feed and may impact strategies and trading tasks that depend on it.
Strategy Process Panel
This panel acts as your strategy pool, allowing you to import Python strategy files (*.py), edit code in real-time (with an embedded IDE), and manage their execution.
Pro Tip: Select a specific strategy in this panel to filter and view its holdings, orders, and trades in their respective panels.
Adding a Strategy
Click "Add", provide a unique Strategy ID, and select the local .py file.
- Note: The strategy file must be located on the same drive as the Kungfu installation directory. Ensure the required Trading (TD) and Market Data (MD) processes are "Ready" before starting a strategy, or it may fail to send orders.
Managing Strategies
- Start/Stop: Use the process toggle button.
- Logs: View real-time execution logs in a new window.
- Edit Code: Click the edit button to modify the strategy file; changes are saved automatically.
- Delete: Removes the strategy and stops its process.
Playback Tool
The playback tool is essential for post-market analysis, debugging, and strategy复盘 (review). It allows you to replay historical trading sessions under different conditions.
Key Use Cases:
- Enhanced Logging: Replay a session with a lower log level (e.g., Debug) to see more detailed information than was captured during live trading.
- Strategy Logic Simulation: Modify your strategy's code (e.g., change an entry condition) and use the built-in matcher to simulate how it would have performed using real historical market data.
- Commission Testing: Adjust futures commission rates in the Global Settings and replay a session to see the impact on trading costs and performance.
Diagnostic Tool
Journal files contain rich, detailed records of process activities, including full market depth quotes. The Diagnostic Tool allows you to browse and analyze these journals.
Features:
- Visualization: View a graphical timeline of orders, cancellations, and market data signals for a strategy, helping you analyze order placement timing and latency.
- Multi-Process View: Analyze journal data from individual processes (accounts, strategies, etc.) or view a consolidated log of all system activity.
- Advanced Filtering: Locate specific information using timestamp jumps, message type filters, and keyword search (Ctrl+F).
Operator Panel
Operators are computational units that process data. They can be used to offload intensive calculations (e.g., machine learning models) from strategies or to create reusable components like synthetic K-line data or factors that multiple strategies can subscribe to.
Types of Operators:
- Plugins: Pre-built operators (e.g., Bar data synthesizer) that can be configured with parameters.
- Files: Custom operators written by users in Python.
Adding an Operator
Click "Add" and choose the type. For a Plugin, configure its ID, data source, instruments, and calculation period. For a File, specify its ID and select the local Python file.
Subscribing to Operator Data
Strategies or other operators can subscribe to the synthetic data published by an operator. This promotes code reusability and improves system efficiency by avoiding redundant calculations.
Monitoring Panels: Positions, Orders, and Trades
Kungfu provides detailed panels to monitor your trading activity.
- Positions Panel: View current holdings. You can search, refresh from the broker, and export data. Select a specific account or strategy to see filtered holdings.
- Order Panel: Monitor all order records. Features include search, filtering for active orders, export by date, detailed order statistics (avg. cancel ratio, system latency), and actions like cancel, modify, or pre-cancel orders.
- Trade Panel: Review all trade executions. Search, export, and view trade statistics.
Trading Tasks Panel
Automate your order execution with predefined trading algorithms. Kungfu offers several types:
- Conditional Orders: Trigger orders based on price conditions, time conditions, or both.
- Excel Orders: Execute bulk orders defined in a CSV/Excel spreadsheet at specified times.
- Iceberg: For large orders; breaks a large order into smaller hidden "iceberg" parts to minimize market impact.
- TWAP (Time-Weighted Average Price): Splits a large order into smaller chunks executed at regular intervals over a specified time window to achieve an average price and reduce market impact. Two variants are available (Remaining Cumulative and Remaining Average) with different handling for unfilled portions.
Frequently Asked Questions (FAQ)
Q: What should I do if my strategy fails to send orders?
A: First, check the status lights in the Trading Account and Market Data panels. Ensure both the relevant TD (Trading) and MD (Market Data) processes show a "Ready" status before starting your strategy. Also, verify your strategy code has correctly subscribed to the necessary market data and/or operator feeds.
Q: How can I test a change to my strategy without risking live capital?
A: Use the Simulated Trading account (sim) for initial logic testing with random data. For rigorous backtesting against real historical data, use the Playback Tool with the matcher enabled. This allows you to modify your code and simulate its performance using actual past market conditions.
Q: My journal files are very large. How can I manage them?
A: You can enable "Skip Archiving" in the Global Settings under the System tab. This will delete older journal files on startup, freeing up disk space and improving startup speed. Use this option if you do not need historical journal data for analysis.
Q: What is the difference between an Operator and a Strategy?
A: An Operator is designed for data processing and computation (e.g., calculating indicators, synthesizing K-lines). A Strategy primarily focuses on making trading decisions (e.g., based on operator data) and sending orders. Operators help keep strategies lean and efficient.
Q: Can I cancel a single order from a large TWAP task?
A: Yes. You can navigate to the Order Record panel, find the specific child order generated by the TWAP task, and cancel it individually. The TWAP algorithm will typically account for this change in its subsequent orders.
Q: Where can I get help with custom plugins or advanced features?
A: Kungfu offers a library of plugins for advanced backtesting, additional brokers, and algorithms. For custom requirements or support, you will need to contact the Kungfu development team directly through their official channels. 👉 Get advanced methods for system optimization