vnpy_ctp

repository·main·Indexed 42 days ago

https://github.com/vnpy/vnpy_ctp

A CTP (Comprehensive Terminals Program) gateway wrapper for the VeighNa quant trading framework. It provides access to CTP market data and trading capabilities via the CtpGateway class for integration into a MainEngine.

Tokens
918
Snippets
7
Records
7
Agent score
4%

What's inside vnpy_ctp

  1. Install vnpy_ctp in developer mode

    main

    To install the package in editable (developer) mode into your current Python environment, use the following command. This is useful when you are modifying the source code.

    pip install -e . --no-build-isolation --config-settings=build-dir=.\vnpy_ctp\api
  2. Install vnpy_ctp from source

    main

    To install from the source code, download/clone the repository and run the install command from the root directory.

    Note: Source installation requires a C++ compiler. Ensure you have installed:

    • Windows: Visual Studio
    • Linux: GCC
    • Mac: XCode
    pip install .
  3. Install vnpy_ctp on macOS

    main

    Due to changes in the CTP Mac system API structure (using a framework directory), pre-compiled wheel binaries are not available on PyPI for macOS. You must compile from source.

    Requirements:

    • You must have the XCode development tools (specifically the C++ compiler) installed.

    Installation Steps:

    1. Clone the repository.
    2. Navigate to the directory.
    3. Install using pip3.
    git clone https://github.com/vnpy/vnpy_ctp.git
    cd vnpy_ctp
    pip3 install .
  4. Use CtpGateway in a VeighNa application

    main

    To use the CTP gateway, import CtpGateway from vnpy_ctp and add it to your MainEngine using add_gateway(). Below is a complete script example to initialize the engines and start the UI.

    from vnpy.event import EventEngine
    from vnpy.trader.engine import MainEngine
    from vnpy.trader.ui import MainWindow, create_qapp
    
    from vnpy_ctp import CtpGateway
    
    
    def main():
        """主入口函数"""
        qapp = create_qapp()
    
        event_engine = EventEngine()
        main_engine = MainEngine(event_engine)
        main_engine.add_gateway(CtpGateway)
        
        main_window = MainWindow(main_engine, event_engine)
        main_window.showMaximized()
    
        qapp.exec()
    
    
    if __name__ == "__main__":
        main()
  5. Use the CtpGateway class for VeighNa integration

    main

    The CtpGateway class is the primary entry point for interacting with the CTP (Comprehensive Trading Platform) interface within the VeighNa framework. It is exported from the vnpy_ctp package and is intended to be used as a gateway component within the VeighNa engine to handle market data and order execution via CTP.

    from vnpy_ctp import CtpGateway
    
    # The CtpGateway instance can then be used within the VeighNa engine
    # to manage CTP connections, subscriptions, and trading.
  6. Check the vnpy_ctp version

    main

    The current version of the vnpy_ctp package can be accessed via the __version__ attribute. If the package is not installed in a way that allows metadata retrieval, it defaults to "dev".

    import vnpy_ctp
    print(vnpy_ctp.__version__)