├── .appveyor.yml ├── .github └── workflows │ ├── build.yaml │ └── deploy.yaml ├── .gitignore ├── LICENSE ├── MANIFEST.in ├── README.md ├── ctp ├── header │ ├── DataCollect.h │ ├── ThostFtdcMdApi.h │ ├── ThostFtdcTraderApi.h │ ├── ThostFtdcUserApiDataType.h │ ├── ThostFtdcUserApiStruct.h │ ├── error.dtd │ └── error.xml ├── linux │ ├── libLinuxDataCollect.so │ ├── libthostmduserapi_se.so │ └── libthosttraderapi_se.so ├── version.txt └── win │ ├── WinDataCollect.dll │ ├── WinDataCollect.lib │ ├── thostmduserapi_se.dll │ ├── thostmduserapi_se.lib │ ├── thosttraderapi_se.dll │ └── thosttraderapi_se.lib ├── ctpwrapper ├── ApiStructure.py ├── Md.py ├── MdApi.pyx ├── Trader.py ├── TraderApi.pyx ├── __init__.py ├── base.py ├── cppheader │ ├── CMdAPI.h │ └── CTraderAPI.h ├── datacollect.pyx └── headers │ ├── DataCollect.pxd │ ├── ThostFtdcUserApiDataType.pxd │ ├── ThostFtdcUserApiStruct.pxd │ ├── __init__.pxd │ ├── cMdAPI.pxd │ └── cTraderApi.pxd ├── doc └── ctp │ └── 6.7.0.chm ├── docker ├── Dockerfile └── pypy3-Dockerfile ├── extra └── appveyor │ └── compiler.cmd ├── generate.py ├── generate_structure.py ├── images ├── alipay.png └── wechat.jpg ├── makefile ├── pytest.ini ├── requirements.txt ├── samples ├── config.json ├── md_main.py └── trader_main.py ├── setup.cfg ├── setup.py └── tests ├── __init__.py ├── server_check.py ├── test_api.py ├── test_datacollect.py └── test_structure.py /.appveyor.yml: -------------------------------------------------------------------------------- 1 | # https://www.appveyor.com/docs/build-configuration/ 2 | # https://packaging.python.org/guides/supporting-windows-using-appveyor/ 3 | 4 | platform: 5 | - x64 6 | 7 | init: 8 | # If there is a newer build queued for the same PR, cancel this one. 9 | # The AppVeyor 'rollout builds' option is supposed to serve the same 10 | # purpose but it is problematic because it tends to cancel builds pushed 11 | # directly to master instead of just PR builds (or the converse). 12 | # credits: JuliaLang developers. 13 | - ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod ` 14 | https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | ` 15 | Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { ` 16 | throw "There are newer queued builds for this pull request, failing early." } 17 | 18 | clone_folder: C:\projects\ctpwrapper 19 | 20 | cache: 21 | # Use the appveyor cache to avoid re-downloading large archives such 22 | # the MKL numpy and scipy wheels mirrored on a rackspace cloud 23 | # container, speed up the appveyor jobs and reduce bandwidth 24 | # usage on our rackspace account. 25 | - '%LocalAppData%\pip\Cache' 26 | 27 | image: 28 | - Visual Studio 2019 29 | 30 | environment: 31 | 32 | global: 33 | # SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the 34 | # /E:ON and /V:ON options are not enabled in the batch script intepreter 35 | # See: http://stackoverflow.com/a/13751649/163740 36 | CMD_IN_ENV: 'cmd /E:ON /V:ON /C .\extra\appveyor\compiler.cmd' 37 | matrix: 38 | 39 | - PYTHON_DIR: "C:\\Python39-x64" 40 | PYTHON: "C:\\Python39-x64\\python" 41 | PYTHON_VERSION: "3.9" 42 | PYTHON_ARCH: "64" 43 | 44 | - PYTHON_DIR: "C:\\Python310-x64" 45 | PYTHON: "C:\\Python310-x64\\python" 46 | PYTHON_VERSION: "3.10" 47 | PYTHON_ARCH: "64" 48 | 49 | - PYTHON_DIR: "C:\\Python311-x64" 50 | PYTHON: "C:\\Python311-x64\\python" 51 | PYTHON_VERSION: "3.11" 52 | PYTHON_ARCH: "64" 53 | 54 | - PYTHON_DIR: "C:\\Python312-x64" 55 | PYTHON: "C:\\Python312-x64\\python" 56 | PYTHON_VERSION: "3.12" 57 | PYTHON_ARCH: "64" 58 | 59 | - PYTHON_DIR: "C:\\Python313-x64" 60 | PYTHON: "C:\\Python313-x64\\python" 61 | PYTHON_VERSION: "3.13" 62 | PYTHON_ARCH: "64" 63 | 64 | - PYTHON_DIR: "C:\\pypy3" 65 | PYTHON: "C:\\pypy3\\pypy" 66 | PYTHON_ARCH: "64" 67 | PYTHON_PYPY: "pypy3" 68 | PYTHON_VERSION: "3.10" 69 | PYTHON_PYPY_VERSION: "7.3.19" 70 | 71 | 72 | matrix: 73 | allow_failures: 74 | - PYTHON_PYPY: "pypy3" 75 | 76 | build: off 77 | 78 | skip_commits: 79 | files: 80 | - ctp/* 81 | - doc/* 82 | - samples/* 83 | - makefile 84 | - docker/* 85 | 86 | install: 87 | # https://downloads.python.org/pypy/pypy3.10-v7.3.19-win64.zip 88 | - ps: If(($env:PYTHON).Contains("pypy3")) { (New-Object Net.WebClient).DownloadFile('https://downloads.python.org/pypy/pypy3.10-v7.3.19-win64.zip', "$env:appveyor_build_folder\pypy3.zip"); 7z x pypy3.zip | Out-Null; move pypy3.10-v7.3.19-win64 C:\pypy3; } 89 | 90 | - "SET PATH=%PYTHON_DIR%;%PYTHON_DIR%\\bin;%PYTHON_DIR%\\Scripts;%PATH%" 91 | 92 | - ps: If(($env:PYTHON).Contains("pypy3")) { (New-Object Net.WebClient).DownloadFile('https://bootstrap.pypa.io/get-pip.py', "$env:appveyor_build_folder\get-pip.py"); pypy.exe get-pip.py } 93 | 94 | # Check that we have the expected version and architecture for Python 95 | - cmd: "%PYTHON% --version" 96 | 97 | - "%PYTHON% -c \"import struct; print(struct.calcsize('P') * 8)\"" # show python version 98 | 99 | - "%PYTHON% -m pip install -U pip setuptools wheel" 100 | - "%PYTHON% -m pip install -r requirements.txt" 101 | 102 | - "%PYTHON% -m pip install pytest" 103 | 104 | test_script: 105 | - SET VS90COMNTOOLS=%VS140COMNTOOLS% 106 | - SET VS90COMNTOOLS=%VS150COMNTOOLS% 107 | - "%CMD_IN_ENV% %PYTHON% setup.py build_ext --inplace" 108 | - "%PYTHON% -m pytest -v -s" 109 | 110 | # ignore auto publish to pypi. 111 | 112 | #build_script: 113 | # - "%CMD_IN_ENV% python setup.py bdist_wheel" 114 | # 115 | #artifacts: 116 | # # bdist_wheel puts your built wheel in the dist directory 117 | # - path: 'dist\*.whl' 118 | # name: wheel 119 | 120 | #deploy_script: 121 | # # This step builds your wheels. 122 | # # Again, you only need build.cmd if you're building C extensions for 123 | # # 64-bit Python 3.3/3.4. And you need to use %PYTHON% to get the correct 124 | # # interpreter 125 | # - "echo [pypi] > %USERPROFILE%\\.pypirc" 126 | # - "echo username: nooperpudd >> %USERPROFILE%\\.pypirc" 127 | # - "echo password: %password% >> %USERPROFILE%\\.pypirc" 128 | # - "%CMD_IN_ENV% python setup.py upload" 129 | 130 | -------------------------------------------------------------------------------- /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: build action 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - master 7 | paths-ignore: 8 | - makefile 9 | - doc/* 10 | - extra/* 11 | - images/* 12 | - samples/* 13 | - docker/* 14 | - README.md 15 | 16 | jobs: 17 | build: 18 | name: python build 19 | runs-on: ubuntu-latest 20 | strategy: 21 | matrix: 22 | python-version: [ "3.9", "3.10", "3.11", "3.12","3.13", "pypy3.10", "pypy3.11" ] 23 | steps: 24 | - name: checkout repo 25 | uses: actions/checkout@v3 26 | 27 | - name: Set up Python ${{ matrix.python-version }} 28 | uses: actions/setup-python@v4 29 | with: 30 | python-version: ${{ matrix.python-version }} 31 | 32 | - name: Install dependencies 33 | run: | 34 | python -m pip install pip setuptools pytest --upgrade 35 | pip install -r requirements.txt --upgrade 36 | 37 | - name: build packages 38 | run: | 39 | python setup.py build_ext --inplace 40 | pytest -v -s 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yaml: -------------------------------------------------------------------------------- 1 | name: deploy pypi packages 2 | on: 3 | release: 4 | tags: 5 | - "v*" 6 | 7 | concurrency: 8 | group: ${{ github.workflow }}-${{ github.ref }} 9 | cancel-in-progress: true 10 | 11 | jobs: 12 | deploy: 13 | name: python build 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: checkout repo 17 | uses: actions/checkout@v3 18 | 19 | - name: Set up Python 3.12 20 | uses: actions/setup-python@v4 21 | with: 22 | python-version: 3.12 23 | 24 | - name: Install dependencies 25 | run: | 26 | python -m pip install pip setuptools pytest --upgrade 27 | pip install -r requirements.txt --upgrade 28 | 29 | - name: Build sdist 30 | run: python setup.py sdist 31 | 32 | - name: Publish a Python distribution to PyPI 33 | uses: pypa/gh-action-pypi-publish@release/v1 34 | with: 35 | password: ${{ secrets.PYPI_API_TOKEN }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | *.cpp 6 | *.con 7 | ctpwrapper/*.so 8 | 9 | 10 | # Distribution / packaging 11 | .Python 12 | env/ 13 | build/ 14 | develop-eggs/ 15 | dist/ 16 | downloads/ 17 | eggs/ 18 | .eggs/ 19 | lib/ 20 | lib64/ 21 | parts/ 22 | sdist/ 23 | var/ 24 | wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .coverage 43 | .coverage.* 44 | .cache 45 | nosetests.xml 46 | coverage.xml 47 | *.cover 48 | .hypothesis/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | 58 | # Flask stuff: 59 | instance/ 60 | .webassets-cache 61 | 62 | # Scrapy stuff: 63 | .scrapy 64 | 65 | # Sphinx documentation 66 | docs/_build/ 67 | 68 | # PyBuilder 69 | target/ 70 | 71 | # Jupyter Notebook 72 | .ipynb_checkpoints 73 | 74 | # pyenv 75 | .python-version 76 | 77 | # celery beat schedule file 78 | celerybeat-schedule 79 | 80 | # SageMath parsed files 81 | *.sage.py 82 | 83 | # dotenv 84 | .env 85 | 86 | # virtualenv 87 | .venv 88 | venv/ 89 | ENV/ 90 | 91 | # Spyder project settings 92 | .spyderproject 93 | .spyproject 94 | 95 | # Rope project settings 96 | .ropeproject 97 | 98 | # mkdocs documentation 99 | /site 100 | 101 | # mypy 102 | .mypy_cache/ 103 | 104 | .idea/ 105 | MdApi.cpp 106 | TraderApi.cpp 107 | 108 | ctpwrapper/error.dtd 109 | ctpwrapper/error.xml 110 | .pytest_cache/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | 167 | Copyright - Winton Wang 365504029@qq.com -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.md 3 | recursive-include ctp * 4 | recursive-include ctpwrapper *.h *.pyx *.pxd 5 | recursive-exclude ctpwrapper *.cpp *.xml *.dtd *.so 6 | recursive-exclude tests * 7 | recursive-exclude README.md 8 | global-exclude __pycache__ *.pyc *.pyo 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CTP期货 API Python Wrapper 2 | 3 | [![build action](https://github.com/nooperpudd/ctpwrapper/actions/workflows/build.yaml/badge.svg?branch=master)](https://github.com/nooperpudd/ctpwrapper/actions/workflows/build.yaml) 4 | [![Build status](https://ci.appveyor.com/api/projects/status/gvvtcqsjo9nsw0ct/branch/master?svg=true)](https://ci.appveyor.com/project/nooperpudd/ctpwrapper) 5 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/9ed5d0e55ed84dfeba30a7630ab5c160)](https://www.codacy.com/app/nooperpudd/ctpwrapper?utm_source=github.com&utm_medium=referral&utm_content=nooperpudd/ctpwrapper&utm_campaign=Badge_Grade) 6 | [![pypi](https://img.shields.io/pypi/v/ctpwrapper.svg)](https://pypi.python.org/pypi/ctpwrapper) 7 | [![status](https://img.shields.io/pypi/status/ctpwrapper.svg)](https://pypi.python.org/pypi/ctpwrapper) 8 | [![pyversion](https://img.shields.io/pypi/pyversions/ctpwrapper.svg)](https://pypi.python.org/pypi/ctpwrapper) 9 | [![implementation](https://img.shields.io/pypi/implementation/ctpwrapper.svg)](https://pypi.python.org/pypi/ctpwrapper) 10 | [![Downloads](https://pepy.tech/badge/ctpwrapper)](https://pepy.tech/project/ctpwrapper) 11 | 12 | [CTP Website](http://www.sfit.com.cn/5_2_DocumentDown_1.htm) 13 | 14 | Version: v6.7.9 15 | 16 | Platform: Linux 64bit, Windows 64bit 17 | 18 | Python Requirement: x86-64 19 | 20 | **Especially Support PyPy3-3.6 Linux 64bit** 21 | 22 | Inspire By lovelylain 23 | 24 | # Install 25 | 26 | Before you install ctpwrapper package, you need to make sure you have 27 | already install cython package. 28 | 29 | >>>pip install cython --upgrade 30 | >>>pip install ctpwrapper --upgrade 31 | 32 | 33 | # Donate [捐助] 34 | 35 | 36 | 37 | ## ⚠️⚠️ notice ⚠️⚠️ 38 | sometimes quote the market futures data, but there is no trading data from the API stream, 39 | better just add `time.sleep(2)` func call after `Init()` method invoked, this could help to solve no data response issue. 40 | 41 | ## Demo 42 | sample code [samples](samples/) 43 | 44 | ## issues 45 | https://github.com/nooperpudd/ctpwrapper/issues/62 46 | this is a temporary solution for the UnicodeDecodeError issue. 47 | ``` 48 | Traceback (most recent call last): 49 | File "ctpwrapper/TraderApi.pyx", line 1402, in ctpwrapper.TraderApi.TraderSpi_OnRspQrySettlementInfo 50 | File "/root/python/futures/trader_main.py", line 149, in OnRspQrySettlementInfo 51 | print(pSettlementInfo.Content) 52 | File "/root/python/futures/.venv/lib/python3.9/site-packages/ctpwrapper/base.py", line 28, in __getattribute__ 53 | return value.decode("gbk") 54 | UnicodeDecodeError: 'gbk' codec can't decode byte 0xd2 in position 499: incomplete multibyte sequence 55 | ``` 56 | ```python 57 | 58 | error_message = "" 59 | 60 | def OnRspQryTradingAccount(self, pTradingAccount, pRspInfo, nRequestID, bIsLast): 61 | print("OnRspQryTradingAccount") 62 | print("nRequestID:", nRequestID) 63 | print("bIsLast:", bIsLast) 64 | print("pRspInfo:", pRspInfo) 65 | print("pTradingAccount:", pTradingAccount) 66 | # need to check is last message from the server. 67 | global error_message 68 | if not bIsLast: 69 | error_message+=pRspInfo.ErrorMsg 70 | else: 71 | error_message+=pRspInfo.ErrorMsg 72 | if isinstance(error_message,bytes): 73 | error_message.decode("gbk") 74 | ``` 75 | 76 | # Documentation 77 | CTP documentation can be found in the [docs](doc/ctp/) 78 | 79 | # Contact 80 | 81 | If you have any question about the ctpwrapper API, contact 365504029@qq.com 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /ctp/header/DataCollect.h: -------------------------------------------------------------------------------- 1 | #ifndef DATA_COLLECT_H 2 | #define DATA_COLLECT_H 3 | 4 | #define DLL_EXPORT __declspec(dllexport) 5 | 6 | #if defined(IS_WINCOLLECT_LIB) && defined(WIN32) 7 | #ifdef LIB_DATA_COLLECT_API_EXPORT 8 | #define DATA_COLLECT_API_EXPORT __declspec(dllexport) 9 | #else 10 | #define DATA_COLLECT_API_EXPORT __declspec(dllimport) 11 | #endif 12 | #else 13 | #define DATA_COLLECT_API_EXPORT 14 | #endif 15 | 16 | 17 | 18 | ///获取AES加密和RSA加密的终端信息 pSystemInfo的空间需要调用者自己分配 至少270个字节 19 | /// windows返回值定义 20 | /* 返回的int值 不为0 表示采集信息有误 具体哪个采集项有问题需要做如下判断 21 | 从低位开始分别标示 终端信息 ->系统盘分区信息 22 | 返回值 & (0x01 << 0) 不为0 表示终端类型未采集到 23 | 返回值 & (0x01 << 1) 不为0 表示 信息采集时间获取异常 24 | 返回值 & (0x01 << 2) 不为0 表示ip 获取失败 (采集多个相同类型信息的场景有一个采集到 即表示采集成功) 25 | 返回值 & (0x01 << 3) 不为0 表示mac 获取失败 26 | 返回值 & (0x01 << 4) 不为0 表示 设备名 获取失败 27 | 返回值 & (0x01 << 5) 不为0 表示 操作系统版本 获取失败 28 | 返回值 & (0x01 << 6) 不为0 表示 硬盘序列号 获取失败 29 | 返回值 & (0x01 << 7) 不为0 表示 CPU序列号 获取失败 30 | 返回值 & (0x01 << 8) 不为0 表示 BIOS 获取失败 31 | 返回值 & (0x01 << 9) 不为0 表示 系统盘分区信息 获取失败 32 | */ 33 | 34 | /// linux返回值定义 35 | /* 返回的int值 不为0 表示采集信息有误 具体哪个采集项有问题需要做如下判断 36 | 从低位开始分别标示 终端信息 -> BIOS信息 37 | 返回值 & (0x01 << 0) 不为0 表示终端类型未采集到 38 | 返回值 & (0x01 << 1) 不为0 表示 信息采集时间获取异常 39 | 返回值 & (0x01 << 2) 不为0 表示ip 获取失败 (采集多个相同类型信息的场景有一个采集到 即表示采集成功) 40 | 返回值 & (0x01 << 3) 不为0 表示mac 获取失败 41 | 返回值 & (0x01 << 4) 不为0 表示 设备名 获取失败 42 | 返回值 & (0x01 << 5) 不为0 表示 操作系统版本 获取失败 43 | 返回值 & (0x01 << 6) 不为0 表示 硬盘序列号 获取失败 44 | 返回值 & (0x01 << 7) 不为0 表示 CPU序列号 获取失败 45 | 返回值 & (0x01 << 8) 不为0 表示 BIOS 获取失败 46 | */ 47 | 48 | DATA_COLLECT_API_EXPORT int CTP_GetSystemInfo(char* pSystemInfo, int& nLen); 49 | 50 | 51 | //版本号格式 52 | //Sfit + 生产还是测试秘钥(pro/tst) + 秘钥版本 + 编译时间 + 版本(内部) 53 | 54 | DATA_COLLECT_API_EXPORT const char * CTP_GetDataCollectApiVersion(void); 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /ctp/header/ThostFtdcMdApi.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | ///@system 新一代交易所系统 3 | ///@company 上海期货信息技术有限公司 4 | ///@file ThostFtdcMdApi.h 5 | ///@brief 定义了客户端接口 6 | ///@history 7 | ///20060106 赵鸿昊 创建该文件 8 | ///////////////////////////////////////////////////////////////////////// 9 | 10 | #if !defined(THOST_FTDCMDAPI_H) 11 | #define THOST_FTDCMDAPI_H 12 | 13 | #if _MSC_VER > 1000 14 | #pragma once 15 | #endif // _MSC_VER > 1000 16 | 17 | #include "ThostFtdcUserApiStruct.h" 18 | 19 | #if defined(ISLIB) && defined(WIN32) 20 | #ifdef LIB_MD_API_EXPORT 21 | #define MD_API_EXPORT __declspec(dllexport) 22 | #else 23 | #define MD_API_EXPORT __declspec(dllimport) 24 | #endif 25 | #else 26 | #define MD_API_EXPORT 27 | #endif 28 | 29 | class CThostFtdcMdSpi { 30 | public: 31 | ///当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。 32 | virtual void OnFrontConnected() {}; 33 | 34 | ///当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。 35 | ///@param nReason 错误原因 36 | /// 0x1001 网络读失败 37 | /// 0x1002 网络写失败 38 | /// 0x2001 接收心跳超时 39 | /// 0x2002 发送心跳失败 40 | /// 0x2003 收到错误报文 41 | virtual void OnFrontDisconnected(int nReason) {}; 42 | 43 | ///心跳超时警告。当长时间未收到报文时,该方法被调用。 44 | ///@param nTimeLapse 距离上次接收报文的时间 45 | virtual void OnHeartBeatWarning(int nTimeLapse) {}; 46 | 47 | 48 | ///登录请求响应 49 | virtual void OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; 50 | 51 | ///登出请求响应 52 | virtual void OnRspUserLogout(CThostFtdcUserLogoutField *pUserLogout, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; 53 | 54 | ///请求查询组播合约响应 55 | virtual void OnRspQryMulticastInstrument(CThostFtdcMulticastInstrumentField *pMulticastInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; 56 | 57 | ///错误应答 58 | virtual void OnRspError(CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; 59 | 60 | ///订阅行情应答 61 | virtual void OnRspSubMarketData(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; 62 | 63 | ///取消订阅行情应答 64 | virtual void OnRspUnSubMarketData(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; 65 | 66 | ///订阅询价应答 67 | virtual void OnRspSubForQuoteRsp(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; 68 | 69 | ///取消订阅询价应答 70 | virtual void OnRspUnSubForQuoteRsp(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; 71 | 72 | ///深度行情通知 73 | virtual void OnRtnDepthMarketData(CThostFtdcDepthMarketDataField *pDepthMarketData) {}; 74 | 75 | ///询价通知 76 | virtual void OnRtnForQuoteRsp(CThostFtdcForQuoteRspField *pForQuoteRsp) {}; 77 | }; 78 | 79 | class MD_API_EXPORT CThostFtdcMdApi { 80 | public: 81 | ///创建MdApi 82 | ///@param pszFlowPath 存贮订阅信息文件的目录,默认为当前目录 83 | ///@return 创建出的UserApi 84 | ///modify for udp marketdata 85 | static CThostFtdcMdApi *CreateFtdcMdApi(const char *pszFlowPath = "", const bool bIsUsingUdp = false, const bool bIsMulticast = false); 86 | 87 | ///获取API的版本信息 88 | ///@retrun 获取到的版本号 89 | static const char *GetApiVersion(); 90 | 91 | ///删除接口对象本身 92 | ///@remark 不再使用本接口对象时,调用该函数删除接口对象 93 | virtual void Release() = 0; 94 | 95 | ///初始化 96 | ///@remark 初始化运行环境,只有调用后,接口才开始工作 97 | virtual void Init() = 0; 98 | 99 | ///等待接口线程结束运行 100 | ///@return 线程退出代码 101 | virtual int Join() = 0; 102 | 103 | ///获取当前交易日 104 | ///@retrun 获取到的交易日 105 | ///@remark 只有登录成功后,才能得到正确的交易日 106 | virtual const char *GetTradingDay() = 0; 107 | 108 | ///注册前置机网络地址 109 | ///@param pszFrontAddress:前置机网络地址。 110 | ///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。 111 | ///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。 112 | virtual void RegisterFront(char *pszFrontAddress) = 0; 113 | 114 | ///注册名字服务器网络地址 115 | ///@param pszNsAddress:名字服务器网络地址。 116 | ///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:12001”。 117 | ///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”12001”代表服务器端口号。 118 | ///@remark RegisterNameServer优先于RegisterFront 119 | virtual void RegisterNameServer(char *pszNsAddress) = 0; 120 | 121 | ///注册名字服务器用户信息 122 | ///@param pFensUserInfo:用户信息。 123 | virtual void RegisterFensUserInfo(CThostFtdcFensUserInfoField *pFensUserInfo) = 0; 124 | 125 | ///注册回调接口 126 | ///@param pSpi 派生自回调接口类的实例 127 | virtual void RegisterSpi(CThostFtdcMdSpi *pSpi) = 0; 128 | 129 | ///订阅行情。 130 | ///@param ppInstrumentID 合约ID 131 | ///@param nCount 要订阅/退订行情的合约个数 132 | ///@remark 133 | virtual int SubscribeMarketData(char *ppInstrumentID[], int nCount) = 0; 134 | 135 | ///退订行情。 136 | ///@param ppInstrumentID 合约ID 137 | ///@param nCount 要订阅/退订行情的合约个数 138 | ///@remark 139 | virtual int UnSubscribeMarketData(char *ppInstrumentID[], int nCount) = 0; 140 | 141 | ///订阅询价。 142 | ///@param ppInstrumentID 合约ID 143 | ///@param nCount 要订阅/退订行情的合约个数 144 | ///@remark 145 | virtual int SubscribeForQuoteRsp(char *ppInstrumentID[], int nCount) = 0; 146 | 147 | ///退订询价。 148 | ///@param ppInstrumentID 合约ID 149 | ///@param nCount 要订阅/退订行情的合约个数 150 | ///@remark 151 | virtual int UnSubscribeForQuoteRsp(char *ppInstrumentID[], int nCount) = 0; 152 | 153 | ///用户登录请求 154 | virtual int ReqUserLogin(CThostFtdcReqUserLoginField *pReqUserLoginField, int nRequestID) = 0; 155 | 156 | ///登出请求 157 | virtual int ReqUserLogout(CThostFtdcUserLogoutField *pUserLogout, int nRequestID) = 0; 158 | 159 | ///请求查询组播合约 160 | virtual int ReqQryMulticastInstrument(CThostFtdcQryMulticastInstrumentField *pQryMulticastInstrument, int nRequestID) = 0; 161 | 162 | protected: 163 | ~CThostFtdcMdApi() {}; 164 | }; 165 | 166 | #endif 167 | -------------------------------------------------------------------------------- /ctp/header/error.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /ctp/header/error.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | -------------------------------------------------------------------------------- /ctp/linux/libLinuxDataCollect.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nooperpudd/ctpwrapper/58c13e0e3a3473ebfac57138ffca4d5926fefb37/ctp/linux/libLinuxDataCollect.so -------------------------------------------------------------------------------- /ctp/linux/libthostmduserapi_se.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nooperpudd/ctpwrapper/58c13e0e3a3473ebfac57138ffca4d5926fefb37/ctp/linux/libthostmduserapi_se.so -------------------------------------------------------------------------------- /ctp/linux/libthosttraderapi_se.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nooperpudd/ctpwrapper/58c13e0e3a3473ebfac57138ffca4d5926fefb37/ctp/linux/libthosttraderapi_se.so -------------------------------------------------------------------------------- /ctp/version.txt: -------------------------------------------------------------------------------- 1 | V6.7.9 2 | windows-64x 3 | linux-64x -------------------------------------------------------------------------------- /ctp/win/WinDataCollect.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nooperpudd/ctpwrapper/58c13e0e3a3473ebfac57138ffca4d5926fefb37/ctp/win/WinDataCollect.dll -------------------------------------------------------------------------------- /ctp/win/WinDataCollect.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nooperpudd/ctpwrapper/58c13e0e3a3473ebfac57138ffca4d5926fefb37/ctp/win/WinDataCollect.lib -------------------------------------------------------------------------------- /ctp/win/thostmduserapi_se.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nooperpudd/ctpwrapper/58c13e0e3a3473ebfac57138ffca4d5926fefb37/ctp/win/thostmduserapi_se.dll -------------------------------------------------------------------------------- /ctp/win/thostmduserapi_se.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nooperpudd/ctpwrapper/58c13e0e3a3473ebfac57138ffca4d5926fefb37/ctp/win/thostmduserapi_se.lib -------------------------------------------------------------------------------- /ctp/win/thosttraderapi_se.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nooperpudd/ctpwrapper/58c13e0e3a3473ebfac57138ffca4d5926fefb37/ctp/win/thosttraderapi_se.dll -------------------------------------------------------------------------------- /ctp/win/thosttraderapi_se.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nooperpudd/ctpwrapper/58c13e0e3a3473ebfac57138ffca4d5926fefb37/ctp/win/thosttraderapi_se.lib -------------------------------------------------------------------------------- /ctpwrapper/Md.py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | """ 3 | (Copyright) 2018, Winton Wang <365504029@qq.com> 4 | 5 | ctpwrapper is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU LGPLv3 as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with ctpwrapper. If not, see . 17 | 18 | """ 19 | import time 20 | import typing 21 | from typing import Optional 22 | 23 | from ctpwrapper.ApiStructure import (FensUserInfoField, UserLogoutField, 24 | ReqUserLoginField, QryMulticastInstrumentField) 25 | from ctpwrapper.MdApi import MdApiWrapper 26 | 27 | 28 | class MdApiPy(MdApiWrapper): 29 | 30 | def Create(self, pszFlowPath: Optional[str] = "", 31 | bIsUsingUdp: Optional[bool] = False, 32 | bIsMulticast: Optional[bool] = False) -> None: 33 | """ 34 | 创建MdApi 35 | :param pszFlowPath: 存贮订阅信息文件的目录,默认为当前目录 36 | :param bIsUsingUdp: 37 | :param bIsMulticast: 38 | """ 39 | super(MdApiPy, self).Create(pszFlowPath.encode(), bIsUsingUdp, bIsMulticast) 40 | 41 | def Init(self) -> None: 42 | """ 43 | 初始化运行环境,只有调用后,接口才开始工作 44 | """ 45 | super(MdApiPy, self).Init() 46 | time.sleep(1) # wait for c++ init 47 | 48 | def Join(self) -> int: 49 | """ 50 | 等待接口线程结束运行 51 | @return 线程退出代码 52 | """ 53 | return super(MdApiPy, self).Join() 54 | 55 | def Release(self) -> None: 56 | super(MdApiPy, self).Release() 57 | 58 | def ReqUserLogin(self, pReqUserLogin: "ReqUserLoginField", nRequestID: int) -> int: 59 | """ 60 | 用户登录请求 61 | """ 62 | return super(MdApiPy, self).ReqUserLogin(pReqUserLogin, nRequestID) 63 | 64 | def ReqUserLogout(self, pUserLogout: "UserLogoutField", nRequestID: int) -> int: 65 | """ 66 | 登出请求 67 | """ 68 | return super(MdApiPy, self).ReqUserLogout(pUserLogout, nRequestID) 69 | 70 | def ReqQryMulticastInstrument(self, pQryMulticastInstrument: "QryMulticastInstrumentField", nRequestID: int) -> int: 71 | """ 72 | 请求查询组播合约 73 | """ 74 | return super(MdApiPy, self).ReqQryMulticastInstrument(pQryMulticastInstrument, nRequestID) 75 | 76 | def GetTradingDay(self) -> str: 77 | """ 78 | 获取当前交易日 79 | @retrun 获取到的交易日 80 | @remark 只有登录成功后,才能得到正确的交易日 81 | :return: 82 | """ 83 | day = super(MdApiPy, self).GetTradingDay() 84 | return day.decode() 85 | 86 | def RegisterFront(self, pszFrontAddress: str) -> None: 87 | """ 88 | 注册前置机网络地址 89 | @param pszFrontAddress:前置机网络地址。 90 | @remark 网络地址的格式为:“protocol:# ipaddress:port”,如:”tcp:# 127.0.0.1:17001”。 91 | @remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。 92 | """ 93 | super(MdApiPy, self).RegisterFront(pszFrontAddress.encode()) 94 | 95 | def RegisterNameServer(self, pszNsAddress: str) -> None: 96 | """ 97 | 注册名字服务器网络地址 98 | @param pszNsAddress:名字服务器网络地址。 99 | @remark 网络地址的格式为:“protocol:# ipaddress:port”,如:”tcp:# 127.0.0.1:12001”。 100 | @remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”12001”代表服务器端口号。 101 | @remark RegisterNameServer优先于RegisterFront 102 | """ 103 | super(MdApiPy, self).RegisterNameServer(pszNsAddress.encode()) 104 | 105 | def RegisterFensUserInfo(self, pFensUserInfo: "FensUserInfoField") -> None: 106 | """ 107 | 注册名字服务器用户信息 108 | @param pFensUserInfo:用户信息。 109 | """ 110 | super(MdApiPy, self).RegisterFensUserInfo(pFensUserInfo) 111 | 112 | def SubscribeMarketData(self, pInstrumentID: typing.List[str]) -> int: 113 | """ 114 | 订阅行情。 115 | @param pInstrumentID 合约ID 116 | :return: int 117 | """ 118 | ids = [bytes(item, encoding="utf-8") for item in pInstrumentID] 119 | return super(MdApiPy, self).SubscribeMarketData(ids) 120 | 121 | def UnSubscribeMarketData(self, pInstrumentID: typing.List[str]) -> int: 122 | """ 123 | 退订行情。 124 | @param pInstrumentID 合约ID 125 | :return: int 126 | """ 127 | ids = [bytes(item, encoding="utf-8") for item in pInstrumentID] 128 | 129 | return super(MdApiPy, self).UnSubscribeMarketData(ids) 130 | 131 | def SubscribeForQuoteRsp(self, pInstrumentID: typing.List[str]) -> int: 132 | """ 133 | 订阅询价。 134 | :param pInstrumentID: 合约ID list 135 | :return: int 136 | """ 137 | ids = [bytes(item, encoding="utf-8") for item in pInstrumentID] 138 | 139 | return super(MdApiPy, self).SubscribeForQuoteRsp(ids) 140 | 141 | def UnSubscribeForQuoteRsp(self, pInstrumentID: typing.List[str]) -> int: 142 | """ 143 | 退订询价。 144 | :param pInstrumentID: 合约ID list 145 | :return: int 146 | """ 147 | ids = [bytes(item, encoding="utf-8") for item in pInstrumentID] 148 | 149 | return super(MdApiPy, self).UnSubscribeForQuoteRsp(ids) 150 | 151 | # for receive message 152 | def OnFrontConnected(self) -> None: 153 | """ 154 | 当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。 155 | :return: 156 | """ 157 | pass 158 | 159 | def OnFrontDisconnected(self, nReason) -> None: 160 | """ 161 | 当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。 162 | @param nReason 错误原因 163 | 4097 0x1001 网络读失败 164 | 4098 0x1002 网络写失败 165 | 8193 0x2001 读心跳超时 166 | 8194 0x2002 发送心跳超时 167 | 8195 0x2003 收到不能识别的错误消息 168 | 客户端与服务端的连接断开有两种情况: 169 | 网络原因导致连接断开 170 | 服务端主动断开连接 171 | 服务器主动断开连接有两种可能: 172 | 客户端长时间没有从服务端接收报文,时间超时 173 | 客户端建立的连接数超过限制 174 | :param nReason: 175 | """ 176 | pass 177 | 178 | def OnHeartBeatWarning(self, nTimeLapse) -> None: 179 | """ 180 | 心跳超时警告。当长时间未收到报文时,该方法被调用。 181 | 182 | :param nTimeLapse: 距离上次接收报文的时间 183 | :return: 184 | """ 185 | pass 186 | 187 | def OnRspUserLogin(self, pRspUserLogin, pRspInfo, nRequestID, bIsLast) -> None: 188 | """ 189 | 登录请求响应 190 | :param pRspUserLogin: 191 | :param pRspInfo: 192 | :param nRequestID: 193 | :param bIsLast: 194 | :return: 195 | """ 196 | pass 197 | 198 | def OnRspUserLogout(self, pUserLogout, pRspInfo, nRequestID, bIsLast) -> None: 199 | """ 200 | 登出请求响应 201 | :param pUserLogout: 202 | :param pRspInfo: 203 | :param nRequestID: 204 | :param bIsLast: 205 | :return: 206 | """ 207 | pass 208 | 209 | def OnRspQryMulticastInstrument(self, pMulticastInstrument, pRspInfo, nRequestID, bIsLast) -> None: 210 | """ 211 | 请求查询组播合约响应 212 | :param pMulticastInstrument: 213 | :param pRspInfo: 214 | :param nRequestID: 215 | :param bIsLast: 216 | :return: 217 | """ 218 | pass 219 | 220 | def OnRspError(self, pRspInfo, nRequestID, bIsLast) -> None: 221 | """ 222 | 错误应答 223 | :param pRspInfo: 224 | :param nRequestID: 225 | :param bIsLast: 226 | :return: 227 | """ 228 | pass 229 | 230 | def OnRspSubMarketData(self, pSpecificInstrument, pRspInfo, nRequestID, bIsLast) -> None: 231 | """ 232 | 订阅行情应答 233 | :param pSpecificInstrument: 234 | :param pRspInfo: 235 | :param nRequestID: 236 | :param bIsLast: 237 | :return: 238 | """ 239 | pass 240 | 241 | def OnRspUnSubMarketData(self, pSpecificInstrument, pRspInfo, nRequestID, bIsLast) -> None: 242 | """ 243 | 取消订阅行情应答 244 | :param pSpecificInstrument: 245 | :param pRspInfo: 246 | :param nRequestID: 247 | :param bIsLast: 248 | :return: 249 | """ 250 | pass 251 | 252 | def OnRspSubForQuoteRsp(self, pSpecificInstrument, pRspInfo, nRequestID, bIsLast) -> None: 253 | """ 254 | 订阅询价应答 255 | :param pSpecificInstrument: 256 | :param pRspInfo: 257 | :param nRequestID: 258 | :param bIsLast: 259 | :return: 260 | """ 261 | pass 262 | 263 | def OnRspUnSubForQuoteRsp(self, pSpecificInstrument, pRspInfo, nRequestID, bIsLast) -> None: 264 | """ 265 | 取消订阅询价应答 266 | :param pSpecificInstrument: 267 | :param pRspInfo: 268 | :param nRequestID: 269 | :param bIsLast: 270 | :return: 271 | """ 272 | pass 273 | 274 | def OnRtnDepthMarketData(self, pDepthMarketData) -> None: 275 | """ 276 | 深度行情通知 277 | :param pDepthMarketData: 278 | :return: 279 | """ 280 | pass 281 | 282 | def OnRtnForQuoteRsp(self, pForQuoteRsp) -> None: 283 | """ 284 | 询价通知 285 | :param pForQuoteRsp: 286 | :return: 287 | """ 288 | pass 289 | -------------------------------------------------------------------------------- /ctpwrapper/MdApi.pyx: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | # distutils: language=c++ 3 | 4 | """ 5 | (Copyright) 2018, Winton Wang <365504029@qq.com> 6 | 7 | ctpwrapper is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU LGPLv3 as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with ctpwrapper. If not, see . 19 | 20 | """ 21 | 22 | from cpython cimport PyObject 23 | from libc.stdlib cimport malloc, free 24 | from libc.string cimport const_char 25 | from libcpp cimport bool as cbool 26 | 27 | from ctpwrapper.headers.ThostFtdcUserApiStruct cimport ( 28 | CThostFtdcRspUserLoginField, 29 | CThostFtdcRspInfoField, 30 | CThostFtdcUserLogoutField, 31 | CThostFtdcSpecificInstrumentField, 32 | CThostFtdcDepthMarketDataField, 33 | CThostFtdcFensUserInfoField, 34 | CThostFtdcReqUserLoginField, 35 | CThostFtdcForQuoteRspField, 36 | CThostFtdcQryMulticastInstrumentField, 37 | CThostFtdcMulticastInstrumentField 38 | ) 39 | from ctpwrapper.headers.cMdAPI cimport CMdSpi, CMdApi, CreateFtdcMdApi 40 | 41 | import ctypes 42 | 43 | from . import ApiStructure 44 | 45 | # from libcpp.memory cimport shared_ptr,make_shared 46 | 47 | 48 | cdef class MdApiWrapper: 49 | cdef CMdApi *_api 50 | cdef CMdSpi *_spi 51 | 52 | def __cinit__(self): 53 | 54 | self._api = NULL 55 | self._spi = NULL 56 | 57 | def __dealloc__(self): 58 | self.Release() 59 | 60 | def Release(self): 61 | 62 | if self._api is not NULL: 63 | self._api.RegisterSpi(NULL) 64 | self._api.Release() 65 | self._api = NULL 66 | self._spi = NULL 67 | 68 | def Create(self, const_char *pszFlowPath, cbool bIsUsingUdp, cbool bIsMulticast): 69 | 70 | with nogil: 71 | self._api = CreateFtdcMdApi(pszFlowPath, bIsUsingUdp, bIsMulticast) 72 | 73 | if not self._api: 74 | raise MemoryError() 75 | 76 | @staticmethod 77 | def GetApiVersion(): 78 | return CMdApi.GetApiVersion() 79 | 80 | def Init(self): 81 | 82 | if self._api is not NULL: 83 | self._spi = new CMdSpi( self) 84 | 85 | if self._spi is not NULL: 86 | with nogil: 87 | self._api.RegisterSpi(self._spi) 88 | self._api.Init() 89 | else: 90 | raise MemoryError() 91 | 92 | def Join(self): 93 | 94 | cdef int result 95 | if self._spi is not NULL: 96 | with nogil: 97 | result = self._api.Join() 98 | return result 99 | 100 | def ReqUserLogin(self, pReqUserLoginField, int nRequestID): 101 | """ 102 | 用户登录请求 103 | :return: 104 | """ 105 | 106 | cdef int result 107 | cdef size_t address 108 | if self._spi is not NULL: 109 | address = ctypes.addressof(pReqUserLoginField) 110 | with nogil: 111 | result = self._api.ReqUserLogin( address, nRequestID) 112 | return result 113 | 114 | def ReqUserLogout(self, pUserLogout, int nRequestID): 115 | """ 116 | 登出请求 117 | :return: 118 | """ 119 | cdef int result 120 | cdef size_t address 121 | if self._spi is not NULL: 122 | address = ctypes.addressof(pUserLogout) 123 | with nogil: 124 | result = self._api.ReqUserLogout( address, nRequestID) 125 | 126 | return result 127 | 128 | def ReqQryMulticastInstrument(self, pQryMulticastInstrument, int nRequestID): 129 | """ 130 | 请求查询组播合约 131 | :param pQryMulticastInstrument: 132 | :param nRequestID: 133 | :return: 134 | """ 135 | cdef int result 136 | cdef size_t address 137 | if self._spi is not NULL: 138 | address = ctypes.addressof(pQryMulticastInstrument) 139 | with nogil: 140 | result = self._api.ReqQryMulticastInstrument( address, nRequestID) 141 | return result 142 | 143 | def GetTradingDay(self): 144 | """ 145 | 获取当前交易日 146 | @retrun 获取到的交易日 147 | @remark 只有登录成功后,才能得到正确的交易日 148 | :return: 149 | """ 150 | cdef const_char *result 151 | 152 | if self._spi is not NULL: 153 | with nogil: 154 | result = self._api.GetTradingDay() 155 | return result 156 | 157 | def RegisterFront(self, char *pszFrontAddress): 158 | """ 159 | 注册前置机网络地址 160 | @param pszFrontAddress:前置机网络地址。 161 | @remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。 162 | @remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。 163 | :return: 164 | """ 165 | if self._api is not NULL: 166 | with nogil: 167 | self._api.RegisterFront(pszFrontAddress) 168 | 169 | def RegisterNameServer(self, char *pszNsAddress): 170 | """ 171 | 注册名字服务器网络地址 172 | @param pszNsAddress:名字服务器网络地址。 173 | @remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:12001”。 174 | @remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”12001”代表服务器端口号。 175 | @remark RegisterNameServer优先于RegisterFront 176 | :return: 177 | """ 178 | if self._api is not NULL: 179 | with nogil: 180 | self._api.RegisterNameServer(pszNsAddress) 181 | 182 | def RegisterFensUserInfo(self, pFensUserInfo): 183 | """ 184 | 注册名字服务器用户信息 185 | @param pFensUserInfo:用户信息。 186 | :return: 187 | """ 188 | cdef size_t address 189 | if self._api is not NULL: 190 | address = ctypes.addressof(pFensUserInfo) 191 | with nogil: 192 | self._api.RegisterFensUserInfo( address) 193 | 194 | def SubscribeMarketData(self, pInstrumentID): 195 | """ 196 | 订阅行情。 197 | @param ppInstrumentID 合约ID 198 | @param nCount 要订阅/退订行情的合约个数 199 | 200 | # https://www.quora.com/How-do-char-array-pointers-work-in-C++ 201 | # http://docs.cython.org/en/latest/src/userguide/language_basics.html#integer-for-loops 202 | # https://stackoverflow.com/questions/15686890/how-to-allocate-array-of-pointers-for-strings-by-malloc-in-c 203 | 204 | :return: 205 | """ 206 | cdef Py_ssize_t count, i 207 | cdef int result 208 | cdef char ** InstrumentIDs 209 | 210 | if self._spi is not NULL: 211 | 212 | count = len(pInstrumentID) 213 | InstrumentIDs = malloc(sizeof(char*) * count) 214 | 215 | try: 216 | for i from 0 <= i < count: 217 | InstrumentIDs[i] = pInstrumentID[i] 218 | with nogil: 219 | result = self._api.SubscribeMarketData(InstrumentIDs, count) 220 | finally: 221 | free(InstrumentIDs) 222 | return result 223 | 224 | def UnSubscribeMarketData(self, pInstrumentID): 225 | """ 226 | 退订行情。 227 | @param ppInstrumentID 合约ID 228 | @param nCount 要订阅/退订行情的合约个数 229 | :return: 230 | """ 231 | cdef Py_ssize_t count, i 232 | cdef int result 233 | cdef char ** InstrumentIDs 234 | 235 | if self._spi is not NULL: 236 | count = len(pInstrumentID) 237 | InstrumentIDs = malloc(sizeof(char*) * count) 238 | 239 | try: 240 | for i from 0 <= i < count: 241 | InstrumentIDs[i] = pInstrumentID[i] 242 | with nogil: 243 | result = self._api.UnSubscribeMarketData(InstrumentIDs, count) 244 | finally: 245 | free(InstrumentIDs) 246 | return result 247 | 248 | def SubscribeForQuoteRsp(self, pInstrumentID): 249 | """ 250 | 订阅询价。 251 | :param pInstrumentID: 合约ID list 252 | :return: 253 | """ 254 | cdef Py_ssize_t count, i 255 | cdef int result 256 | cdef char ** InstrumentIDs 257 | 258 | if self._spi is not NULL: 259 | 260 | count = len(pInstrumentID) 261 | InstrumentIDs = malloc(sizeof(char*) * count) 262 | 263 | try: 264 | for i from 0 <= i < count: 265 | InstrumentIDs[i] = pInstrumentID[i] 266 | with nogil: 267 | result = self._api.SubscribeForQuoteRsp(InstrumentIDs, count) 268 | finally: 269 | free(InstrumentIDs) 270 | return result 271 | 272 | def UnSubscribeForQuoteRsp(self, pInstrumentID): 273 | """ 274 | 退订询价。 275 | :param pInstrumentID: 合约ID list 276 | :return: 277 | """ 278 | cdef Py_ssize_t count, i 279 | cdef int result 280 | cdef char ** InstrumentIDs 281 | 282 | if self._spi is not NULL: 283 | 284 | count = len(pInstrumentID) 285 | InstrumentIDs = malloc(sizeof(char*) * count) 286 | try: 287 | for i from 0 <= i < count: 288 | InstrumentIDs[i] = pInstrumentID[i] 289 | with nogil: 290 | result = self._api.UnSubscribeForQuoteRsp(InstrumentIDs, count) 291 | finally: 292 | free(InstrumentIDs) 293 | return result 294 | 295 | cdef extern int MdSpi_OnFrontConnected(self) except -1: 296 | self.OnFrontConnected() 297 | return 0 298 | 299 | cdef extern int MdSpi_OnFrontDisconnected(self, int nReason) except -1: 300 | self.OnFrontDisconnected(nReason) 301 | return 0 302 | 303 | cdef extern int MdSpi_OnHeartBeatWarning(self, int nTimeLapse) except -1: 304 | self.OnHeartBeatWarning(nTimeLapse) 305 | return 0 306 | 307 | cdef extern int MdSpi_OnRspUserLogin(self, 308 | CThostFtdcRspUserLoginField *pRspUserLogin, 309 | CThostFtdcRspInfoField *pRspInfo, 310 | int nRequestID, 311 | cbool bIsLast) except -1: 312 | if pRspUserLogin is NULL: 313 | user_login = None 314 | else: 315 | user_login = ApiStructure.RspUserLoginField.from_address( pRspUserLogin) 316 | 317 | if pRspInfo is NULL: 318 | rsp_info = None 319 | else: 320 | rsp_info = ApiStructure.RspInfoField.from_address( pRspInfo) 321 | self.OnRspUserLogin(user_login, rsp_info, nRequestID, bIsLast) 322 | return 0 323 | 324 | cdef extern int MdSpi_OnRspUserLogout(self, 325 | CThostFtdcUserLogoutField *pUserLogout, 326 | CThostFtdcRspInfoField *pRspInfo, 327 | int nRequestID, 328 | cbool bIsLast) except -1: 329 | if pUserLogout is NULL: 330 | user_logout = None 331 | else: 332 | user_logout = ApiStructure.UserLogoutField.from_address( pUserLogout) 333 | if pRspInfo is NULL: 334 | rsp_info = None 335 | else: 336 | rsp_info = ApiStructure.RspInfoField.from_address( pRspInfo) 337 | 338 | self.OnRspUserLogout(user_logout, rsp_info, nRequestID, bIsLast) 339 | return 0 340 | 341 | cdef extern int MdSpi_OnRspError(self, 342 | CThostFtdcRspInfoField *pRspInfo, 343 | int nRequestID, 344 | cbool bIsLast) except -1: 345 | if pRspInfo is NULL: 346 | rsp_info = None 347 | else: 348 | rsp_info = ApiStructure.RspInfoField.from_address( pRspInfo) 349 | self.OnRspError(rsp_info, nRequestID, bIsLast) 350 | return 0 351 | 352 | cdef extern int MdSpi_OnRspSubMarketData(self, 353 | CThostFtdcSpecificInstrumentField *pSpecificInstrument, 354 | CThostFtdcRspInfoField *pRspInfo, 355 | int nRequestID, 356 | cbool bIsLast) except -1: 357 | if pSpecificInstrument is NULL: 358 | instrument = None 359 | else: 360 | instrument = ApiStructure.SpecificInstrumentField.from_address( pSpecificInstrument) 361 | 362 | if pRspInfo is NULL: 363 | rsp_info = None 364 | else: 365 | rsp_info = ApiStructure.RspInfoField.from_address( pRspInfo) 366 | self.OnRspSubMarketData(instrument, rsp_info, nRequestID, bIsLast) 367 | return 0 368 | 369 | cdef extern int MdSpi_OnRspUnSubMarketData(self, 370 | CThostFtdcSpecificInstrumentField *pSpecificInstrument, 371 | CThostFtdcRspInfoField *pRspInfo, 372 | int nRequestID, 373 | cbool bIsLast) except -1: 374 | if pSpecificInstrument is NULL: 375 | instrument = None 376 | else: 377 | instrument = ApiStructure.SpecificInstrumentField.from_address( pSpecificInstrument) 378 | 379 | if pRspInfo is NULL: 380 | rsp_info = None 381 | else: 382 | rsp_info = ApiStructure.RspInfoField.from_address( pRspInfo) 383 | 384 | self.OnRspUnSubMarketData(instrument, rsp_info, nRequestID, bIsLast) 385 | return 0 386 | 387 | cdef extern int MdSpi_OnRspSubForQuoteRsp(self, 388 | CThostFtdcSpecificInstrumentField *pSpecificInstrument, 389 | CThostFtdcRspInfoField *pRspInfo, 390 | int nRequestID, 391 | cbool bIsLast) except -1: 392 | if pSpecificInstrument is NULL: 393 | instrument = None 394 | else: 395 | instrument = ApiStructure.SpecificInstrumentField.from_address( pSpecificInstrument) 396 | 397 | if pRspInfo is NULL: 398 | rsp_info = None 399 | else: 400 | rsp_info = ApiStructure.RspInfoField.from_address( pRspInfo) 401 | self.OnRspSubForQuoteRsp(instrument, rsp_info, nRequestID, bIsLast) 402 | return 0 403 | 404 | cdef extern int MdSpi_OnRspUnSubForQuoteRsp(self, 405 | CThostFtdcSpecificInstrumentField *pSpecificInstrument, 406 | CThostFtdcRspInfoField *pRspInfo, 407 | int nRequestID, 408 | cbool bIsLast) except -1: 409 | if pSpecificInstrument is NULL: 410 | instrument = None 411 | else: 412 | instrument = ApiStructure.SpecificInstrumentField.from_address( pRspInfo) 413 | 414 | if pRspInfo is NULL: 415 | rsp_info = None 416 | else: 417 | rsp_info = ApiStructure.RspInfoField.from_address( pRspInfo) 418 | self.OnRspUnSubForQuoteRsp(instrument, rsp_info, nRequestID, bIsLast) 419 | return 0 420 | 421 | cdef extern int MdSpi_OnRtnDepthMarketData(self, CThostFtdcDepthMarketDataField *pDepthMarketData) except -1: 422 | if pDepthMarketData is NULL: 423 | depth_market = None 424 | else: 425 | depth_market = ApiStructure.DepthMarketDataField.from_address( pDepthMarketData) 426 | self.OnRtnDepthMarketData(depth_market) 427 | return 0 428 | 429 | cdef extern int MdSpi_OnRtnForQuoteRsp(self, CThostFtdcForQuoteRspField *pForQuoteRsp) except -1: 430 | if pForQuoteRsp is NULL: 431 | quote = None 432 | else: 433 | quote = ApiStructure.ForQuoteRspField.from_address( pForQuoteRsp) 434 | 435 | self.OnRtnForQuoteRsp(quote) 436 | return 0 437 | 438 | cdef extern int MdSpi_OnRspQryMulticastInstrument(self, 439 | CThostFtdcMulticastInstrumentField *pMulticastInstrument, 440 | CThostFtdcRspInfoField *pRspInfo, 441 | int nRequestID, 442 | cbool bIsLast) except -1: 443 | if pMulticastInstrument is NULL: 444 | MulticastInstrument = None 445 | else: 446 | MulticastInstrument = ApiStructure.MulticastInstrumentField.from_address( pMulticastInstrument) 447 | 448 | if pRspInfo is NULL: 449 | rsp_info = None 450 | else: 451 | rsp_info = ApiStructure.RspInfoField.from_address( pRspInfo) 452 | 453 | self.OnRspQryMulticastInstrument(MulticastInstrument, rsp_info, nRequestID, bIsLast) 454 | return 0 455 | -------------------------------------------------------------------------------- /ctpwrapper/__init__.py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | """ 3 | (Copyright) 2018, Winton Wang <365504029@qq.com> 4 | 5 | ctpwrapper is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU LGPLv3 as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with ctpwrapper. If not, see . 17 | 18 | """ 19 | __version__ = "6.7.9" 20 | 21 | from ctpwrapper.Md import MdApiPy 22 | from ctpwrapper.Trader import TraderApiPy 23 | 24 | from ctpwrapper.datacollect import GetSystemInfo, GetDataCollectApiVersion 25 | 26 | 27 | __all__ = ( 28 | "MdApiPy", 29 | "TraderApiPy", 30 | "GetSystemInfo", 31 | "GetDataCollectApiVersion" 32 | ) 33 | 34 | -------------------------------------------------------------------------------- /ctpwrapper/base.py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | """ 3 | (Copyright) 2018, Winton Wang <365504029@qq.com> 4 | 5 | ctpwrapper is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU LGPLv3 as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with ctpwrapper. If not, see . 17 | 18 | """ 19 | import ctypes 20 | import typing 21 | 22 | 23 | class Base(ctypes.Structure): 24 | 25 | def __getattribute__(self, item): 26 | value = super().__getattribute__(item) 27 | if isinstance(value, bytes): 28 | try: 29 | return value.decode("gbk") 30 | except UnicodeDecodeError: 31 | # UnicodeDecodeError: 'gbk' codec 32 | # can't decode byte 0xd2 in position 499: 33 | # incomplete multibyte sequence 34 | # return bytes values 35 | return value 36 | else: 37 | return value 38 | 39 | def _to_bytes(self, value): 40 | """ 41 | :return: 42 | """ 43 | if isinstance(value, bytes): 44 | return value 45 | else: 46 | return bytes(str(value), encoding="utf-8") 47 | 48 | @classmethod 49 | def from_dict(cls, obj: typing.Dict): 50 | """ 51 | :return: 52 | """ 53 | return cls(**obj) 54 | 55 | def to_dict(self) -> typing.Dict: 56 | """ 57 | :return: 58 | """ 59 | results = {} 60 | for key, _ in self._fields_: 61 | _value = getattr(self, key) 62 | results[key] = _value 63 | return results 64 | 65 | def __repr__(self): 66 | """ 67 | :return: 68 | """ 69 | items = ["{0}({1})".format(item, getattr(self, item)) for item, value in self._fields_] 70 | return "{0}<{1}>".format(self.__class__.__name__, ",".join(items)) 71 | -------------------------------------------------------------------------------- /ctpwrapper/cppheader/CMdAPI.h: -------------------------------------------------------------------------------- 1 | /* 2 | (Copyright) 2018, Winton Wang <365504029@qq.com> 3 | 4 | ctpwrapper is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU LGPLv3 as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ctpwrapper. If not, see . 16 | 17 | */ 18 | 19 | #ifndef CMDAPI_H 20 | #define CMDAPI_H 21 | 22 | #include "Python.h" 23 | #include "pythread.h" 24 | #include "ThostFtdcMdApi.h" 25 | 26 | 27 | static inline int MdSpi_OnFrontConnected(PyObject *); 28 | 29 | static inline int MdSpi_OnFrontDisconnected(PyObject *, int); 30 | 31 | static inline int MdSpi_OnHeartBeatWarning(PyObject *, int); 32 | 33 | static inline int MdSpi_OnRspUserLogin(PyObject *, CThostFtdcRspUserLoginField *, CThostFtdcRspInfoField *, int, bool); 34 | 35 | static inline int MdSpi_OnRspUserLogout(PyObject *, CThostFtdcUserLogoutField *, CThostFtdcRspInfoField *, int, bool); 36 | 37 | static inline int MdSpi_OnRspError(PyObject *, CThostFtdcRspInfoField *, int, bool); 38 | 39 | static inline int MdSpi_OnRspSubMarketData(PyObject *, CThostFtdcSpecificInstrumentField *, CThostFtdcRspInfoField *, int, bool); 40 | 41 | static inline int MdSpi_OnRspUnSubMarketData(PyObject *, CThostFtdcSpecificInstrumentField *, CThostFtdcRspInfoField *, int, bool); 42 | 43 | static inline int MdSpi_OnRspSubForQuoteRsp(PyObject *, CThostFtdcSpecificInstrumentField *, CThostFtdcRspInfoField *, int, bool); 44 | 45 | static inline int MdSpi_OnRspUnSubForQuoteRsp(PyObject *, CThostFtdcSpecificInstrumentField *, CThostFtdcRspInfoField *, int, bool); 46 | 47 | static inline int MdSpi_OnRtnDepthMarketData(PyObject *, CThostFtdcDepthMarketDataField *); 48 | 49 | static inline int MdSpi_OnRtnForQuoteRsp(PyObject *, CThostFtdcForQuoteRspField *); 50 | 51 | static inline int MdSpi_OnRspQryMulticastInstrument(PyObject *, CThostFtdcMulticastInstrumentField *, CThostFtdcRspInfoField *, int, bool); 52 | 53 | #define Python_GIL(func) \ 54 | do { \ 55 | PyGILState_STATE gil_state = PyGILState_Ensure(); \ 56 | if ((func) == -1) PyErr_Print(); \ 57 | PyGILState_Release(gil_state); \ 58 | } while (false) 59 | 60 | 61 | class CMdSpi : public CThostFtdcMdSpi { 62 | public: 63 | 64 | CMdSpi(PyObject *obj) : self(obj) {}; 65 | 66 | virtual ~CMdSpi() {}; 67 | 68 | virtual void OnFrontConnected() { 69 | Python_GIL(MdSpi_OnFrontConnected(self)); 70 | }; 71 | 72 | virtual void OnFrontDisconnected(int nReason) { 73 | Python_GIL(MdSpi_OnFrontDisconnected(self, nReason)); 74 | }; 75 | 76 | virtual void OnHeartBeatWarning(int nTimeLapse) { 77 | Python_GIL(MdSpi_OnHeartBeatWarning(self, nTimeLapse)); 78 | }; 79 | 80 | virtual void OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) { 81 | Python_GIL(MdSpi_OnRspUserLogin(self, pRspUserLogin, pRspInfo, nRequestID, bIsLast)); 82 | }; 83 | 84 | virtual void OnRspUserLogout(CThostFtdcUserLogoutField *pUserLogout, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) { 85 | Python_GIL(MdSpi_OnRspUserLogout(self, pUserLogout, pRspInfo, nRequestID, bIsLast)); 86 | }; 87 | 88 | virtual void OnRspQryMulticastInstrument(CThostFtdcMulticastInstrumentField *pMulticastInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) { 89 | Python_GIL(MdSpi_OnRspQryMulticastInstrument(self, pMulticastInstrument, pRspInfo, nRequestID, bIsLast)); 90 | }; 91 | 92 | virtual void OnRspError(CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) { 93 | Python_GIL(MdSpi_OnRspError(self, pRspInfo, nRequestID, bIsLast)); 94 | }; 95 | 96 | virtual void OnRspSubMarketData(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) { 97 | Python_GIL(MdSpi_OnRspSubMarketData(self, pSpecificInstrument, pRspInfo, nRequestID, bIsLast)); 98 | }; 99 | 100 | virtual void OnRspUnSubMarketData(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) { 101 | Python_GIL(MdSpi_OnRspUnSubMarketData(self, pSpecificInstrument, pRspInfo, nRequestID, bIsLast)); 102 | }; 103 | 104 | virtual void OnRspSubForQuoteRsp(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) { 105 | Python_GIL(MdSpi_OnRspSubForQuoteRsp(self, pSpecificInstrument, pRspInfo, nRequestID, bIsLast)); 106 | }; 107 | 108 | virtual void OnRspUnSubForQuoteRsp(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) { 109 | Python_GIL(MdSpi_OnRspUnSubForQuoteRsp(self, pSpecificInstrument, pRspInfo, nRequestID, bIsLast)); 110 | }; 111 | 112 | virtual void OnRtnDepthMarketData(CThostFtdcDepthMarketDataField *pDepthMarketData) { 113 | Python_GIL(MdSpi_OnRtnDepthMarketData(self, pDepthMarketData)); 114 | }; 115 | 116 | virtual void OnRtnForQuoteRsp(CThostFtdcForQuoteRspField *pForQuoteRsp) { 117 | Python_GIL(MdSpi_OnRtnForQuoteRsp(self, pForQuoteRsp)); 118 | }; 119 | 120 | private: 121 | PyObject *self; 122 | }; 123 | 124 | #endif /* CMDAPI_H */ -------------------------------------------------------------------------------- /ctpwrapper/datacollect.pyx: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | # distutils: language=c++ 3 | 4 | from libc.string cimport const_char 5 | from ctpwrapper.headers.DataCollect cimport CTP_GetSystemInfo, CTP_GetDataCollectApiVersion 6 | 7 | def GetSystemInfo(char *pSystemInfo,int nLen): 8 | """ 9 | :return: 10 | """ 11 | cdef int result = CTP_GetSystemInfo(pSystemInfo, nLen) 12 | return result 13 | 14 | def GetDataCollectApiVersion(): 15 | cdef const_char *result = CTP_GetDataCollectApiVersion() 16 | return result 17 | 18 | 19 | -------------------------------------------------------------------------------- /ctpwrapper/headers/DataCollect.pxd: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | # distutils: language=c++ 3 | 4 | from libc.string cimport const_char 5 | 6 | cdef extern from "DataCollect.h": 7 | int CTP_GetSystemInfo(char *pSystemInfo, int &nLen) except + nogil 8 | const_char *CTP_GetDataCollectApiVersion() except + nogil 9 | -------------------------------------------------------------------------------- /ctpwrapper/headers/ThostFtdcUserApiDataType.pxd: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | # distutils: language=c++ 3 | """ 4 | (Copyright) 2018, Winton Wang <365504029@qq.com> 5 | 6 | ctpwrapper is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU LGPLv3 as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with ctpwrapper. If not, see . 18 | """ 19 | 20 | cdef extern from 'ThostFtdcUserApiDataType.h': 21 | cdef enum THOST_TE_RESUME_TYPE: 22 | THOST_TERT_RESTART = 0 23 | THOST_TERT_RESUME 24 | THOST_TERT_QUICK 25 | THOST_TERT_NONE 26 | ctypedef char TThostFtdcTraderIDType[21] 27 | ctypedef char TThostFtdcInvestorIDType[13] 28 | ctypedef char TThostFtdcBrokerIDType[11] 29 | ctypedef char TThostFtdcBrokerAbbrType[9] 30 | ctypedef char TThostFtdcBrokerNameType[81] 31 | ctypedef char TThostFtdcOldExchangeInstIDType[31] 32 | ctypedef char TThostFtdcExchangeInstIDType[81] 33 | ctypedef char TThostFtdcOrderRefType[13] 34 | ctypedef char TThostFtdcParticipantIDType[11] 35 | ctypedef char TThostFtdcUserIDType[16] 36 | ctypedef char TThostFtdcPasswordType[41] 37 | ctypedef char TThostFtdcClientIDType[11] 38 | ctypedef char TThostFtdcInstrumentIDType[81] 39 | ctypedef char TThostFtdcOldInstrumentIDType[31] 40 | ctypedef char TThostFtdcInstrumentCodeType[31] 41 | ctypedef char TThostFtdcMarketIDType[31] 42 | ctypedef char TThostFtdcProductNameType[21] 43 | ctypedef char TThostFtdcExchangeIDType[9] 44 | ctypedef char TThostFtdcExchangeNameType[61] 45 | ctypedef char TThostFtdcExchangeAbbrType[9] 46 | ctypedef char TThostFtdcExchangeFlagType[2] 47 | ctypedef char TThostFtdcMacAddressType[21] 48 | ctypedef char TThostFtdcSystemIDType[21] 49 | ctypedef char TThostFtdcClientLoginRemarkType[151] 50 | ctypedef char TThostFtdcExchangePropertyType 51 | ctypedef char TThostFtdcDateType[9] 52 | ctypedef char TThostFtdcTimeType[9] 53 | ctypedef char TThostFtdcLongTimeType[13] 54 | ctypedef char TThostFtdcInstrumentNameType[21] 55 | ctypedef char TThostFtdcSettlementGroupIDType[9] 56 | ctypedef char TThostFtdcOrderSysIDType[21] 57 | ctypedef char TThostFtdcTradeIDType[21] 58 | ctypedef char TThostFtdcCommandTypeType[65] 59 | ctypedef char TThostFtdcOldIPAddressType[16] 60 | ctypedef char TThostFtdcIPAddressType[33] 61 | ctypedef int TThostFtdcIPPortType 62 | ctypedef char TThostFtdcProductInfoType[11] 63 | ctypedef char TThostFtdcProtocolInfoType[11] 64 | ctypedef char TThostFtdcBusinessUnitType[21] 65 | ctypedef char TThostFtdcDepositSeqNoType[15] 66 | ctypedef char TThostFtdcIdentifiedCardNoType[51] 67 | ctypedef char TThostFtdcIdCardTypeType 68 | ctypedef char TThostFtdcOrderLocalIDType[13] 69 | ctypedef char TThostFtdcUserNameType[81] 70 | ctypedef char TThostFtdcPartyNameType[81] 71 | ctypedef char TThostFtdcErrorMsgType[81] 72 | ctypedef char TThostFtdcFieldNameType[2049] 73 | ctypedef char TThostFtdcFieldContentType[2049] 74 | ctypedef char TThostFtdcSystemNameType[41] 75 | ctypedef char TThostFtdcContentType[501] 76 | ctypedef char TThostFtdcInvestorRangeType 77 | ctypedef char TThostFtdcDepartmentRangeType 78 | ctypedef char TThostFtdcDataSyncStatusType 79 | ctypedef char TThostFtdcBrokerDataSyncStatusType 80 | ctypedef char TThostFtdcExchangeConnectStatusType 81 | ctypedef char TThostFtdcTraderConnectStatusType 82 | ctypedef char TThostFtdcFunctionCodeType 83 | ctypedef char TThostFtdcBrokerFunctionCodeType 84 | ctypedef char TThostFtdcOrderActionStatusType 85 | ctypedef char TThostFtdcOrderStatusType 86 | ctypedef char TThostFtdcOrderSubmitStatusType 87 | ctypedef char TThostFtdcPositionDateType 88 | ctypedef char TThostFtdcPositionDateTypeType 89 | ctypedef char TThostFtdcTradingRoleType 90 | ctypedef char TThostFtdcProductClassType 91 | ctypedef char TThostFtdcAPIProductClassType 92 | ctypedef char TThostFtdcInstLifePhaseType 93 | ctypedef char TThostFtdcDirectionType 94 | ctypedef char TThostFtdcPositionTypeType 95 | ctypedef char TThostFtdcPosiDirectionType 96 | ctypedef char TThostFtdcSysSettlementStatusType 97 | ctypedef char TThostFtdcRatioAttrType 98 | ctypedef char TThostFtdcHedgeFlagType 99 | ctypedef char TThostFtdcBillHedgeFlagType 100 | ctypedef char TThostFtdcClientIDTypeType 101 | ctypedef char TThostFtdcOrderPriceTypeType 102 | ctypedef char TThostFtdcOffsetFlagType 103 | ctypedef char TThostFtdcForceCloseReasonType 104 | ctypedef char TThostFtdcOrderTypeType 105 | ctypedef char TThostFtdcTimeConditionType 106 | ctypedef char TThostFtdcVolumeConditionType 107 | ctypedef char TThostFtdcContingentConditionType 108 | ctypedef char TThostFtdcActionFlagType 109 | ctypedef char TThostFtdcTradingRightType 110 | ctypedef char TThostFtdcOrderSourceType 111 | ctypedef char TThostFtdcTradeTypeType 112 | ctypedef char TThostFtdcSpecPosiTypeType 113 | ctypedef char TThostFtdcPriceSourceType 114 | ctypedef char TThostFtdcInstrumentStatusType 115 | ctypedef char TThostFtdcInstStatusEnterReasonType 116 | ctypedef int TThostFtdcOrderActionRefType 117 | ctypedef int TThostFtdcInstallCountType 118 | ctypedef int TThostFtdcInstallIDType 119 | ctypedef int TThostFtdcErrorIDType 120 | ctypedef int TThostFtdcSettlementIDType 121 | ctypedef int TThostFtdcVolumeType 122 | ctypedef int TThostFtdcFrontIDType 123 | ctypedef int TThostFtdcSessionIDType 124 | ctypedef int TThostFtdcSequenceNoType 125 | ctypedef int TThostFtdcCommandNoType 126 | ctypedef int TThostFtdcMillisecType 127 | ctypedef int TThostFtdcSecType 128 | ctypedef int TThostFtdcVolumeMultipleType 129 | ctypedef int TThostFtdcTradingSegmentSNType 130 | ctypedef int TThostFtdcRequestIDType 131 | ctypedef int TThostFtdcYearType 132 | ctypedef int TThostFtdcMonthType 133 | ctypedef int TThostFtdcBoolType 134 | ctypedef double TThostFtdcPriceType 135 | ctypedef char TThostFtdcCombOffsetFlagType[5] 136 | ctypedef char TThostFtdcCombHedgeFlagType[5] 137 | ctypedef double TThostFtdcRatioType 138 | ctypedef double TThostFtdcMoneyType 139 | ctypedef double TThostFtdcLargeVolumeType 140 | ctypedef short TThostFtdcSequenceSeriesType 141 | ctypedef short TThostFtdcCommPhaseNoType 142 | ctypedef char TThostFtdcSequenceLabelType[2] 143 | ctypedef double TThostFtdcUnderlyingMultipleType 144 | ctypedef int TThostFtdcPriorityType 145 | ctypedef char TThostFtdcContractCodeType[41] 146 | ctypedef char TThostFtdcCityType[51] 147 | ctypedef char TThostFtdcIsStockType[11] 148 | ctypedef char TThostFtdcChannelType[51] 149 | ctypedef char TThostFtdcAddressType[101] 150 | ctypedef char TThostFtdcZipCodeType[7] 151 | ctypedef char TThostFtdcTelephoneType[41] 152 | ctypedef char TThostFtdcFaxType[41] 153 | ctypedef char TThostFtdcMobileType[41] 154 | ctypedef char TThostFtdcEMailType[41] 155 | ctypedef char TThostFtdcMemoType[161] 156 | ctypedef char TThostFtdcCompanyCodeType[51] 157 | ctypedef char TThostFtdcWebsiteType[51] 158 | ctypedef char TThostFtdcTaxNoType[31] 159 | ctypedef char TThostFtdcBatchStatusType 160 | ctypedef char TThostFtdcPropertyIDType[33] 161 | ctypedef char TThostFtdcPropertyNameType[65] 162 | ctypedef char TThostFtdcLicenseNoType[51] 163 | ctypedef char TThostFtdcAgentIDType[13] 164 | ctypedef char TThostFtdcAgentNameType[41] 165 | ctypedef char TThostFtdcAgentGroupIDType[13] 166 | ctypedef char TThostFtdcAgentGroupNameType[41] 167 | ctypedef char TThostFtdcReturnStyleType 168 | ctypedef char TThostFtdcReturnPatternType 169 | ctypedef char TThostFtdcReturnLevelType 170 | ctypedef char TThostFtdcReturnStandardType 171 | ctypedef char TThostFtdcMortgageTypeType 172 | ctypedef char TThostFtdcInvestorSettlementParamIDType 173 | ctypedef char TThostFtdcExchangeSettlementParamIDType 174 | ctypedef char TThostFtdcSystemParamIDType 175 | ctypedef char TThostFtdcTradeParamIDType 176 | ctypedef char TThostFtdcSettlementParamValueType[256] 177 | ctypedef char TThostFtdcCounterIDType[33] 178 | ctypedef char TThostFtdcInvestorGroupNameType[41] 179 | ctypedef char TThostFtdcBrandCodeType[257] 180 | ctypedef char TThostFtdcWarehouseType[257] 181 | ctypedef char TThostFtdcProductDateType[41] 182 | ctypedef char TThostFtdcGradeType[41] 183 | ctypedef char TThostFtdcClassifyType[41] 184 | ctypedef char TThostFtdcPositionType[41] 185 | ctypedef char TThostFtdcYieldlyType[41] 186 | ctypedef char TThostFtdcWeightType[41] 187 | ctypedef int TThostFtdcSubEntryFundNoType 188 | ctypedef char TThostFtdcFileIDType 189 | ctypedef char TThostFtdcFileNameType[257] 190 | ctypedef char TThostFtdcFileTypeType 191 | ctypedef char TThostFtdcFileFormatType 192 | ctypedef char TThostFtdcFileUploadStatusType 193 | ctypedef char TThostFtdcTransferDirectionType 194 | ctypedef char TThostFtdcUploadModeType[21] 195 | ctypedef char TThostFtdcAccountIDType[13] 196 | ctypedef char TThostFtdcBankFlagType[4] 197 | ctypedef char TThostFtdcBankAccountType[41] 198 | ctypedef char TThostFtdcOpenNameType[61] 199 | ctypedef char TThostFtdcOpenBankType[101] 200 | ctypedef char TThostFtdcBankNameType[101] 201 | ctypedef char TThostFtdcPublishPathType[257] 202 | ctypedef char TThostFtdcOperatorIDType[65] 203 | ctypedef int TThostFtdcMonthCountType 204 | ctypedef char TThostFtdcAdvanceMonthArrayType[13] 205 | ctypedef char TThostFtdcDateExprType[1025] 206 | ctypedef char TThostFtdcInstrumentIDExprType[41] 207 | ctypedef char TThostFtdcInstrumentNameExprType[41] 208 | ctypedef char TThostFtdcSpecialCreateRuleType 209 | ctypedef char TThostFtdcBasisPriceTypeType 210 | ctypedef char TThostFtdcProductLifePhaseType 211 | ctypedef char TThostFtdcDeliveryModeType 212 | ctypedef char TThostFtdcLogLevelType[33] 213 | ctypedef char TThostFtdcProcessNameType[257] 214 | ctypedef char TThostFtdcOperationMemoType[1025] 215 | ctypedef char TThostFtdcFundIOTypeType 216 | ctypedef char TThostFtdcFundTypeType 217 | ctypedef char TThostFtdcFundDirectionType 218 | ctypedef char TThostFtdcFundStatusType 219 | ctypedef char TThostFtdcBillNoType[15] 220 | ctypedef char TThostFtdcBillNameType[33] 221 | ctypedef char TThostFtdcPublishStatusType 222 | ctypedef char TThostFtdcEnumValueIDType[65] 223 | ctypedef char TThostFtdcEnumValueTypeType[33] 224 | ctypedef char TThostFtdcEnumValueLabelType[65] 225 | ctypedef char TThostFtdcEnumValueResultType[33] 226 | ctypedef char TThostFtdcSystemStatusType 227 | ctypedef char TThostFtdcSettlementStatusType 228 | ctypedef char TThostFtdcRangeIntTypeType[33] 229 | ctypedef char TThostFtdcRangeIntFromType[33] 230 | ctypedef char TThostFtdcRangeIntToType[33] 231 | ctypedef char TThostFtdcFunctionIDType[25] 232 | ctypedef char TThostFtdcFunctionValueCodeType[257] 233 | ctypedef char TThostFtdcFunctionNameType[65] 234 | ctypedef char TThostFtdcRoleIDType[11] 235 | ctypedef char TThostFtdcRoleNameType[41] 236 | ctypedef char TThostFtdcDescriptionType[401] 237 | ctypedef char TThostFtdcCombineIDType[25] 238 | ctypedef char TThostFtdcCombineTypeType[25] 239 | ctypedef char TThostFtdcInvestorTypeType 240 | ctypedef char TThostFtdcBrokerTypeType 241 | ctypedef char TThostFtdcRiskLevelType 242 | ctypedef char TThostFtdcFeeAcceptStyleType 243 | ctypedef char TThostFtdcPasswordTypeType 244 | ctypedef char TThostFtdcAlgorithmType 245 | ctypedef char TThostFtdcIncludeCloseProfitType 246 | ctypedef char TThostFtdcAllWithoutTradeType 247 | ctypedef char TThostFtdcCommentType[31] 248 | ctypedef char TThostFtdcVersionType[4] 249 | ctypedef char TThostFtdcTradeCodeType[7] 250 | ctypedef char TThostFtdcTradeDateType[9] 251 | ctypedef char TThostFtdcTradeTimeType[9] 252 | ctypedef char TThostFtdcTradeSerialType[9] 253 | ctypedef int TThostFtdcTradeSerialNoType 254 | ctypedef char TThostFtdcFutureIDType[11] 255 | ctypedef char TThostFtdcBankIDType[4] 256 | ctypedef char TThostFtdcBankBrchIDType[5] 257 | ctypedef char TThostFtdcBankBranchIDType[11] 258 | ctypedef char TThostFtdcOperNoType[17] 259 | ctypedef char TThostFtdcDeviceIDType[3] 260 | ctypedef char TThostFtdcRecordNumType[7] 261 | ctypedef char TThostFtdcFutureAccountType[22] 262 | ctypedef char TThostFtdcFuturePwdFlagType 263 | ctypedef char TThostFtdcTransferTypeType 264 | ctypedef char TThostFtdcFutureAccPwdType[17] 265 | ctypedef char TThostFtdcCurrencyCodeType[4] 266 | ctypedef char TThostFtdcRetCodeType[5] 267 | ctypedef char TThostFtdcRetInfoType[129] 268 | ctypedef char TThostFtdcTradeAmtType[20] 269 | ctypedef char TThostFtdcUseAmtType[20] 270 | ctypedef char TThostFtdcFetchAmtType[20] 271 | ctypedef char TThostFtdcTransferValidFlagType 272 | ctypedef char TThostFtdcCertCodeType[21] 273 | ctypedef char TThostFtdcReasonType 274 | ctypedef char TThostFtdcFundProjectIDType[5] 275 | ctypedef char TThostFtdcSexType 276 | ctypedef char TThostFtdcProfessionType[101] 277 | ctypedef char TThostFtdcNationalType[31] 278 | ctypedef char TThostFtdcProvinceType[51] 279 | ctypedef char TThostFtdcRegionType[16] 280 | ctypedef char TThostFtdcCountryType[16] 281 | ctypedef char TThostFtdcLicenseNOType[33] 282 | ctypedef char TThostFtdcCompanyTypeType[16] 283 | ctypedef char TThostFtdcBusinessScopeType[1001] 284 | ctypedef char TThostFtdcCapitalCurrencyType[4] 285 | ctypedef char TThostFtdcUserTypeType 286 | ctypedef char TThostFtdcBranchIDType[9] 287 | ctypedef char TThostFtdcRateTypeType 288 | ctypedef char TThostFtdcNoteTypeType 289 | ctypedef char TThostFtdcSettlementStyleType 290 | ctypedef char TThostFtdcBrokerDNSType[256] 291 | ctypedef char TThostFtdcSentenceType[501] 292 | ctypedef char TThostFtdcSettlementBillTypeType 293 | ctypedef char TThostFtdcUserRightTypeType 294 | ctypedef char TThostFtdcMarginPriceTypeType 295 | ctypedef char TThostFtdcBillGenStatusType 296 | ctypedef char TThostFtdcAlgoTypeType 297 | ctypedef char TThostFtdcHandlePositionAlgoIDType 298 | ctypedef char TThostFtdcFindMarginRateAlgoIDType 299 | ctypedef char TThostFtdcHandleTradingAccountAlgoIDType 300 | ctypedef char TThostFtdcPersonTypeType 301 | ctypedef char TThostFtdcQueryInvestorRangeType 302 | ctypedef char TThostFtdcInvestorRiskStatusType 303 | ctypedef int TThostFtdcLegIDType 304 | ctypedef int TThostFtdcLegMultipleType 305 | ctypedef int TThostFtdcImplyLevelType 306 | ctypedef char TThostFtdcClearAccountType[33] 307 | ctypedef char TThostFtdcOrganNOType[6] 308 | ctypedef char TThostFtdcClearbarchIDType[6] 309 | ctypedef char TThostFtdcUserEventTypeType 310 | ctypedef char TThostFtdcUserEventInfoType[1025] 311 | ctypedef char TThostFtdcCloseStyleType 312 | ctypedef char TThostFtdcStatModeType 313 | ctypedef char TThostFtdcParkedOrderStatusType 314 | ctypedef char TThostFtdcParkedOrderIDType[13] 315 | ctypedef char TThostFtdcParkedOrderActionIDType[13] 316 | ctypedef char TThostFtdcVirDealStatusType 317 | ctypedef char TThostFtdcOrgSystemIDType 318 | ctypedef char TThostFtdcVirTradeStatusType 319 | ctypedef char TThostFtdcVirBankAccTypeType 320 | ctypedef char TThostFtdcVirementStatusType 321 | ctypedef char TThostFtdcVirementAvailAbilityType 322 | ctypedef char TThostFtdcVirementTradeCodeType 323 | ctypedef char TThostFtdcPhotoTypeNameType[41] 324 | ctypedef char TThostFtdcPhotoTypeIDType[5] 325 | ctypedef char TThostFtdcPhotoNameType[161] 326 | ctypedef int TThostFtdcTopicIDType 327 | ctypedef char TThostFtdcReportTypeIDType[3] 328 | ctypedef char TThostFtdcCharacterIDType[5] 329 | ctypedef char TThostFtdcAMLParamIDType[21] 330 | ctypedef char TThostFtdcAMLInvestorTypeType[3] 331 | ctypedef char TThostFtdcAMLIdCardTypeType[3] 332 | ctypedef char TThostFtdcAMLTradeDirectType[3] 333 | ctypedef char TThostFtdcAMLTradeModelType[3] 334 | ctypedef double TThostFtdcAMLOpParamValueType 335 | ctypedef char TThostFtdcAMLCustomerCardTypeType[81] 336 | ctypedef char TThostFtdcAMLInstitutionNameType[65] 337 | ctypedef char TThostFtdcAMLDistrictIDType[7] 338 | ctypedef char TThostFtdcAMLRelationShipType[3] 339 | ctypedef char TThostFtdcAMLInstitutionTypeType[3] 340 | ctypedef char TThostFtdcAMLInstitutionIDType[13] 341 | ctypedef char TThostFtdcAMLAccountTypeType[5] 342 | ctypedef char TThostFtdcAMLTradingTypeType[7] 343 | ctypedef char TThostFtdcAMLTransactClassType[7] 344 | ctypedef char TThostFtdcAMLCapitalIOType[3] 345 | ctypedef char TThostFtdcAMLSiteType[10] 346 | ctypedef char TThostFtdcAMLCapitalPurposeType[129] 347 | ctypedef char TThostFtdcAMLReportTypeType[2] 348 | ctypedef char TThostFtdcAMLSerialNoType[5] 349 | ctypedef char TThostFtdcAMLStatusType[2] 350 | ctypedef char TThostFtdcAMLGenStatusType 351 | ctypedef char TThostFtdcAMLSeqCodeType[65] 352 | ctypedef char TThostFtdcAMLFileNameType[257] 353 | ctypedef double TThostFtdcAMLMoneyType 354 | ctypedef int TThostFtdcAMLFileAmountType 355 | ctypedef char TThostFtdcCFMMCKeyType[21] 356 | ctypedef char TThostFtdcCFMMCTokenType[21] 357 | ctypedef char TThostFtdcCFMMCKeyKindType 358 | ctypedef char TThostFtdcAMLReportNameType[81] 359 | ctypedef char TThostFtdcIndividualNameType[51] 360 | ctypedef char TThostFtdcCurrencyIDType[4] 361 | ctypedef char TThostFtdcCustNumberType[36] 362 | ctypedef char TThostFtdcOrganCodeType[36] 363 | ctypedef char TThostFtdcOrganNameType[71] 364 | ctypedef char TThostFtdcSuperOrganCodeType[12] 365 | ctypedef char TThostFtdcSubBranchIDType[31] 366 | ctypedef char TThostFtdcSubBranchNameType[71] 367 | ctypedef char TThostFtdcBranchNetCodeType[31] 368 | ctypedef char TThostFtdcBranchNetNameType[71] 369 | ctypedef char TThostFtdcOrganFlagType[2] 370 | ctypedef char TThostFtdcBankCodingForFutureType[33] 371 | ctypedef char TThostFtdcBankReturnCodeType[7] 372 | ctypedef char TThostFtdcPlateReturnCodeType[5] 373 | ctypedef char TThostFtdcBankSubBranchIDType[31] 374 | ctypedef char TThostFtdcFutureBranchIDType[31] 375 | ctypedef char TThostFtdcReturnCodeType[7] 376 | ctypedef char TThostFtdcOperatorCodeType[17] 377 | ctypedef char TThostFtdcClearDepIDType[6] 378 | ctypedef char TThostFtdcClearBrchIDType[6] 379 | ctypedef char TThostFtdcClearNameType[71] 380 | ctypedef char TThostFtdcBankAccountNameType[71] 381 | ctypedef char TThostFtdcInvDepIDType[6] 382 | ctypedef char TThostFtdcInvBrchIDType[6] 383 | ctypedef char TThostFtdcMessageFormatVersionType[36] 384 | ctypedef char TThostFtdcDigestType[36] 385 | ctypedef char TThostFtdcAuthenticDataType[129] 386 | ctypedef char TThostFtdcPasswordKeyType[129] 387 | ctypedef char TThostFtdcFutureAccountNameType[129] 388 | ctypedef char TThostFtdcMobilePhoneType[21] 389 | ctypedef char TThostFtdcFutureMainKeyType[129] 390 | ctypedef char TThostFtdcFutureWorkKeyType[129] 391 | ctypedef char TThostFtdcFutureTransKeyType[129] 392 | ctypedef char TThostFtdcBankMainKeyType[129] 393 | ctypedef char TThostFtdcBankWorkKeyType[129] 394 | ctypedef char TThostFtdcBankTransKeyType[129] 395 | ctypedef char TThostFtdcBankServerDescriptionType[129] 396 | ctypedef char TThostFtdcAddInfoType[129] 397 | ctypedef char TThostFtdcDescrInfoForReturnCodeType[129] 398 | ctypedef char TThostFtdcCountryCodeType[21] 399 | ctypedef int TThostFtdcSerialType 400 | ctypedef int TThostFtdcPlateSerialType 401 | ctypedef char TThostFtdcBankSerialType[13] 402 | ctypedef int TThostFtdcCorrectSerialType 403 | ctypedef int TThostFtdcFutureSerialType 404 | ctypedef int TThostFtdcApplicationIDType 405 | ctypedef int TThostFtdcBankProxyIDType 406 | ctypedef int TThostFtdcFBTCoreIDType 407 | ctypedef int TThostFtdcServerPortType 408 | ctypedef int TThostFtdcRepealedTimesType 409 | ctypedef int TThostFtdcRepealTimeIntervalType 410 | ctypedef int TThostFtdcTotalTimesType 411 | ctypedef int TThostFtdcFBTRequestIDType 412 | ctypedef int TThostFtdcTIDType 413 | ctypedef double TThostFtdcTradeAmountType 414 | ctypedef double TThostFtdcCustFeeType 415 | ctypedef double TThostFtdcFutureFeeType 416 | ctypedef double TThostFtdcSingleMaxAmtType 417 | ctypedef double TThostFtdcSingleMinAmtType 418 | ctypedef double TThostFtdcTotalAmtType 419 | ctypedef char TThostFtdcCertificationTypeType 420 | ctypedef char TThostFtdcFileBusinessCodeType 421 | ctypedef char TThostFtdcCashExchangeCodeType 422 | ctypedef char TThostFtdcYesNoIndicatorType 423 | ctypedef char TThostFtdcBanlanceTypeType 424 | ctypedef char TThostFtdcGenderType 425 | ctypedef char TThostFtdcFeePayFlagType 426 | ctypedef char TThostFtdcPassWordKeyTypeType 427 | ctypedef char TThostFtdcFBTPassWordTypeType 428 | ctypedef char TThostFtdcFBTEncryModeType 429 | ctypedef char TThostFtdcBankRepealFlagType 430 | ctypedef char TThostFtdcBrokerRepealFlagType 431 | ctypedef char TThostFtdcInstitutionTypeType 432 | ctypedef char TThostFtdcLastFragmentType 433 | ctypedef char TThostFtdcBankAccStatusType 434 | ctypedef char TThostFtdcMoneyAccountStatusType 435 | ctypedef char TThostFtdcManageStatusType 436 | ctypedef char TThostFtdcSystemTypeType 437 | ctypedef char TThostFtdcTxnEndFlagType 438 | ctypedef char TThostFtdcProcessStatusType 439 | ctypedef char TThostFtdcCustTypeType 440 | ctypedef char TThostFtdcFBTTransferDirectionType 441 | ctypedef char TThostFtdcOpenOrDestroyType 442 | ctypedef char TThostFtdcAvailabilityFlagType 443 | ctypedef char TThostFtdcOrganTypeType 444 | ctypedef char TThostFtdcOrganLevelType 445 | ctypedef char TThostFtdcProtocalIDType 446 | ctypedef char TThostFtdcConnectModeType 447 | ctypedef char TThostFtdcSyncModeType 448 | ctypedef char TThostFtdcBankAccTypeType 449 | ctypedef char TThostFtdcFutureAccTypeType 450 | ctypedef char TThostFtdcOrganStatusType 451 | ctypedef char TThostFtdcCCBFeeModeType 452 | ctypedef char TThostFtdcCommApiTypeType 453 | ctypedef int TThostFtdcServiceIDType 454 | ctypedef int TThostFtdcServiceLineNoType 455 | ctypedef char TThostFtdcServiceNameType[61] 456 | ctypedef char TThostFtdcLinkStatusType 457 | ctypedef int TThostFtdcCommApiPointerType 458 | ctypedef char TThostFtdcPwdFlagType 459 | ctypedef char TThostFtdcSecuAccTypeType 460 | ctypedef char TThostFtdcTransferStatusType 461 | ctypedef char TThostFtdcSponsorTypeType 462 | ctypedef char TThostFtdcReqRspTypeType 463 | ctypedef char TThostFtdcFBTUserEventTypeType 464 | ctypedef char TThostFtdcBankIDByBankType[21] 465 | ctypedef char TThostFtdcBankOperNoType[4] 466 | ctypedef char TThostFtdcBankCustNoType[21] 467 | ctypedef int TThostFtdcDBOPSeqNoType 468 | ctypedef char TThostFtdcTableNameType[61] 469 | ctypedef char TThostFtdcPKNameType[201] 470 | ctypedef char TThostFtdcPKValueType[501] 471 | ctypedef char TThostFtdcDBOperationType 472 | ctypedef char TThostFtdcSyncFlagType 473 | ctypedef char TThostFtdcTargetIDType[4] 474 | ctypedef char TThostFtdcSyncTypeType 475 | ctypedef char TThostFtdcFBETimeType[7] 476 | ctypedef char TThostFtdcFBEBankNoType[13] 477 | ctypedef char TThostFtdcFBECertNoType[13] 478 | ctypedef char TThostFtdcExDirectionType 479 | ctypedef char TThostFtdcFBEBankAccountType[33] 480 | ctypedef char TThostFtdcFBEBankAccountNameType[61] 481 | ctypedef double TThostFtdcFBEAmtType 482 | ctypedef char TThostFtdcFBEBusinessTypeType[3] 483 | ctypedef char TThostFtdcFBEPostScriptType[61] 484 | ctypedef char TThostFtdcFBERemarkType[71] 485 | ctypedef double TThostFtdcExRateType 486 | ctypedef char TThostFtdcFBEResultFlagType 487 | ctypedef char TThostFtdcFBERtnMsgType[61] 488 | ctypedef char TThostFtdcFBEExtendMsgType[61] 489 | ctypedef char TThostFtdcFBEBusinessSerialType[31] 490 | ctypedef char TThostFtdcFBESystemSerialType[21] 491 | ctypedef int TThostFtdcFBETotalExCntType 492 | ctypedef char TThostFtdcFBEExchStatusType 493 | ctypedef char TThostFtdcFBEFileFlagType 494 | ctypedef char TThostFtdcFBEAlreadyTradeType 495 | ctypedef char TThostFtdcFBEOpenBankType[61] 496 | ctypedef char TThostFtdcFBEUserEventTypeType 497 | ctypedef char TThostFtdcFBEFileNameType[21] 498 | ctypedef char TThostFtdcFBEBatchSerialType[21] 499 | ctypedef char TThostFtdcFBEReqFlagType 500 | ctypedef char TThostFtdcNotifyClassType 501 | ctypedef char TThostFtdcRiskNofityInfoType[257] 502 | ctypedef char TThostFtdcForceCloseSceneIdType[24] 503 | ctypedef char TThostFtdcForceCloseTypeType 504 | ctypedef char TThostFtdcInstrumentIDsType[101] 505 | ctypedef char TThostFtdcRiskNotifyMethodType 506 | ctypedef char TThostFtdcRiskNotifyStatusType 507 | ctypedef char TThostFtdcRiskUserEventType 508 | ctypedef int TThostFtdcParamIDType 509 | ctypedef char TThostFtdcParamNameType[41] 510 | ctypedef char TThostFtdcParamValueType[41] 511 | ctypedef char TThostFtdcConditionalOrderSortTypeType 512 | ctypedef char TThostFtdcSendTypeType 513 | ctypedef char TThostFtdcClientIDStatusType 514 | ctypedef char TThostFtdcIndustryIDType[17] 515 | ctypedef char TThostFtdcQuestionIDType[5] 516 | ctypedef char TThostFtdcQuestionContentType[41] 517 | ctypedef char TThostFtdcOptionIDType[13] 518 | ctypedef char TThostFtdcOptionContentType[61] 519 | ctypedef char TThostFtdcQuestionTypeType 520 | ctypedef char TThostFtdcProcessIDType[33] 521 | ctypedef int TThostFtdcSeqNoType 522 | ctypedef char TThostFtdcUOAProcessStatusType[3] 523 | ctypedef char TThostFtdcProcessTypeType[3] 524 | ctypedef char TThostFtdcBusinessTypeType 525 | ctypedef char TThostFtdcCfmmcReturnCodeType 526 | ctypedef int TThostFtdcExReturnCodeType 527 | ctypedef char TThostFtdcClientTypeType 528 | ctypedef char TThostFtdcExchangeIDTypeType 529 | ctypedef char TThostFtdcExClientIDTypeType 530 | ctypedef char TThostFtdcClientClassifyType[11] 531 | ctypedef char TThostFtdcUOAOrganTypeType[11] 532 | ctypedef char TThostFtdcUOACountryCodeType[11] 533 | ctypedef char TThostFtdcAreaCodeType[11] 534 | ctypedef char TThostFtdcFuturesIDType[21] 535 | ctypedef char TThostFtdcCffmcDateType[11] 536 | ctypedef char TThostFtdcCffmcTimeType[11] 537 | ctypedef char TThostFtdcNocIDType[21] 538 | ctypedef char TThostFtdcUpdateFlagType 539 | ctypedef char TThostFtdcApplyOperateIDType 540 | ctypedef char TThostFtdcApplyStatusIDType 541 | ctypedef char TThostFtdcSendMethodType 542 | ctypedef char TThostFtdcEventTypeType[33] 543 | ctypedef char TThostFtdcEventModeType 544 | ctypedef char TThostFtdcUOAAutoSendType 545 | ctypedef int TThostFtdcQueryDepthType 546 | ctypedef int TThostFtdcDataCenterIDType 547 | ctypedef char TThostFtdcFlowIDType 548 | ctypedef char TThostFtdcCheckLevelType 549 | ctypedef int TThostFtdcCheckNoType 550 | ctypedef char TThostFtdcCheckStatusType 551 | ctypedef char TThostFtdcUsedStatusType 552 | ctypedef char TThostFtdcRateTemplateNameType[61] 553 | ctypedef char TThostFtdcPropertyStringType[2049] 554 | ctypedef char TThostFtdcBankAcountOriginType 555 | ctypedef char TThostFtdcMonthBillTradeSumType 556 | ctypedef char TThostFtdcFBTTradeCodeEnumType 557 | ctypedef char TThostFtdcRateTemplateIDType[9] 558 | ctypedef char TThostFtdcRiskRateType[21] 559 | ctypedef int TThostFtdcTimestampType 560 | ctypedef char TThostFtdcInvestorIDRuleNameType[61] 561 | ctypedef char TThostFtdcInvestorIDRuleExprType[513] 562 | ctypedef int TThostFtdcLastDriftType 563 | ctypedef int TThostFtdcLastSuccessType 564 | ctypedef char TThostFtdcAuthKeyType[41] 565 | ctypedef char TThostFtdcSerialNumberType[17] 566 | ctypedef char TThostFtdcOTPTypeType 567 | ctypedef char TThostFtdcOTPVendorsIDType[2] 568 | ctypedef char TThostFtdcOTPVendorsNameType[61] 569 | ctypedef char TThostFtdcOTPStatusType 570 | ctypedef char TThostFtdcBrokerUserTypeType 571 | ctypedef char TThostFtdcFutureTypeType 572 | ctypedef char TThostFtdcFundEventTypeType 573 | ctypedef char TThostFtdcAccountSourceTypeType 574 | ctypedef char TThostFtdcCodeSourceTypeType 575 | ctypedef char TThostFtdcUserRangeType 576 | ctypedef char TThostFtdcTimeSpanType[9] 577 | ctypedef char TThostFtdcImportSequenceIDType[17] 578 | ctypedef char TThostFtdcByGroupType 579 | ctypedef char TThostFtdcTradeSumStatModeType 580 | ctypedef int TThostFtdcComTypeType 581 | ctypedef char TThostFtdcUserProductIDType[33] 582 | ctypedef char TThostFtdcUserProductNameType[65] 583 | ctypedef char TThostFtdcUserProductMemoType[129] 584 | ctypedef char TThostFtdcCSRCCancelFlagType[2] 585 | ctypedef char TThostFtdcCSRCDateType[11] 586 | ctypedef char TThostFtdcCSRCInvestorNameType[201] 587 | ctypedef char TThostFtdcCSRCOpenInvestorNameType[101] 588 | ctypedef char TThostFtdcCSRCInvestorIDType[13] 589 | ctypedef char TThostFtdcCSRCIdentifiedCardNoType[51] 590 | ctypedef char TThostFtdcCSRCClientIDType[11] 591 | ctypedef char TThostFtdcCSRCBankFlagType[3] 592 | ctypedef char TThostFtdcCSRCBankAccountType[23] 593 | ctypedef char TThostFtdcCSRCOpenNameType[401] 594 | ctypedef char TThostFtdcCSRCMemoType[101] 595 | ctypedef char TThostFtdcCSRCTimeType[11] 596 | ctypedef char TThostFtdcCSRCTradeIDType[21] 597 | ctypedef char TThostFtdcCSRCExchangeInstIDType[31] 598 | ctypedef char TThostFtdcCSRCMortgageNameType[7] 599 | ctypedef char TThostFtdcCSRCReasonType[3] 600 | ctypedef char TThostFtdcIsSettlementType[2] 601 | ctypedef double TThostFtdcCSRCMoneyType 602 | ctypedef double TThostFtdcCSRCPriceType 603 | ctypedef char TThostFtdcCSRCOptionsTypeType[2] 604 | ctypedef double TThostFtdcCSRCStrikePriceType 605 | ctypedef char TThostFtdcCSRCTargetProductIDType[3] 606 | ctypedef char TThostFtdcCSRCTargetInstrIDType[31] 607 | ctypedef char TThostFtdcCommModelNameType[161] 608 | ctypedef char TThostFtdcCommModelMemoType[1025] 609 | ctypedef char TThostFtdcExprSetModeType 610 | ctypedef char TThostFtdcRateInvestorRangeType 611 | ctypedef char TThostFtdcAgentBrokerIDType[13] 612 | ctypedef int TThostFtdcDRIdentityIDType 613 | ctypedef char TThostFtdcDRIdentityNameType[65] 614 | ctypedef char TThostFtdcDBLinkIDType[31] 615 | ctypedef char TThostFtdcSyncDataStatusType 616 | ctypedef char TThostFtdcTradeSourceType 617 | ctypedef char TThostFtdcFlexStatModeType 618 | ctypedef char TThostFtdcByInvestorRangeType 619 | ctypedef char TThostFtdcSRiskRateType[21] 620 | ctypedef int TThostFtdcSequenceNo12Type 621 | ctypedef char TThostFtdcPropertyInvestorRangeType 622 | ctypedef char TThostFtdcFileStatusType 623 | ctypedef char TThostFtdcFileGenStyleType 624 | ctypedef char TThostFtdcSysOperModeType 625 | ctypedef char TThostFtdcSysOperTypeType 626 | ctypedef char TThostFtdcCSRCDataQueyTypeType 627 | ctypedef char TThostFtdcFreezeStatusType 628 | ctypedef char TThostFtdcStandardStatusType 629 | ctypedef char TThostFtdcCSRCFreezeStatusType[2] 630 | ctypedef char TThostFtdcRightParamTypeType 631 | ctypedef char TThostFtdcRightTemplateIDType[9] 632 | ctypedef char TThostFtdcRightTemplateNameType[61] 633 | ctypedef char TThostFtdcDataStatusType 634 | ctypedef char TThostFtdcAMLCheckStatusType 635 | ctypedef char TThostFtdcAmlDateTypeType 636 | ctypedef char TThostFtdcAmlCheckLevelType 637 | ctypedef char TThostFtdcAmlCheckFlowType[2] 638 | ctypedef char TThostFtdcDataTypeType[129] 639 | ctypedef char TThostFtdcExportFileTypeType 640 | ctypedef char TThostFtdcSettleManagerTypeType 641 | ctypedef char TThostFtdcSettleManagerIDType[33] 642 | ctypedef char TThostFtdcSettleManagerNameType[129] 643 | ctypedef char TThostFtdcSettleManagerLevelType 644 | ctypedef char TThostFtdcSettleManagerGroupType 645 | ctypedef char TThostFtdcCheckResultMemoType[1025] 646 | ctypedef char TThostFtdcFunctionUrlType[1025] 647 | ctypedef char TThostFtdcAuthInfoType[129] 648 | ctypedef char TThostFtdcAuthCodeType[17] 649 | ctypedef char TThostFtdcLimitUseTypeType 650 | ctypedef char TThostFtdcDataResourceType 651 | ctypedef char TThostFtdcMarginTypeType 652 | ctypedef char TThostFtdcActiveTypeType 653 | ctypedef char TThostFtdcMarginRateTypeType 654 | ctypedef char TThostFtdcBackUpStatusType 655 | ctypedef char TThostFtdcInitSettlementType 656 | ctypedef char TThostFtdcReportStatusType 657 | ctypedef char TThostFtdcSaveStatusType 658 | ctypedef char TThostFtdcSettArchiveStatusType 659 | ctypedef char TThostFtdcCTPTypeType 660 | ctypedef char TThostFtdcToolIDType[9] 661 | ctypedef char TThostFtdcToolNameType[81] 662 | ctypedef char TThostFtdcCloseDealTypeType 663 | ctypedef char TThostFtdcMortgageFundUseRangeType 664 | ctypedef double TThostFtdcCurrencyUnitType 665 | ctypedef double TThostFtdcExchangeRateType 666 | ctypedef char TThostFtdcSpecProductTypeType 667 | ctypedef char TThostFtdcFundMortgageTypeType 668 | ctypedef char TThostFtdcAccountSettlementParamIDType 669 | ctypedef char TThostFtdcCurrencyNameType[31] 670 | ctypedef char TThostFtdcCurrencySignType[4] 671 | ctypedef char TThostFtdcFundMortDirectionType 672 | ctypedef char TThostFtdcBusinessClassType 673 | ctypedef char TThostFtdcSwapSourceTypeType 674 | ctypedef char TThostFtdcCurrExDirectionType 675 | ctypedef char TThostFtdcCurrencySwapStatusType 676 | ctypedef char TThostFtdcCurrExchCertNoType[13] 677 | ctypedef char TThostFtdcBatchSerialNoType[21] 678 | ctypedef char TThostFtdcReqFlagType 679 | ctypedef char TThostFtdcResFlagType 680 | ctypedef char TThostFtdcPageControlType[2] 681 | ctypedef int TThostFtdcRecordCountType 682 | ctypedef char TThostFtdcCurrencySwapMemoType[101] 683 | ctypedef char TThostFtdcExStatusType 684 | ctypedef char TThostFtdcClientRegionType 685 | ctypedef char TThostFtdcWorkPlaceType[101] 686 | ctypedef char TThostFtdcBusinessPeriodType[21] 687 | ctypedef char TThostFtdcWebSiteType[101] 688 | ctypedef char TThostFtdcUOAIdCardTypeType[3] 689 | ctypedef char TThostFtdcClientModeType[3] 690 | ctypedef char TThostFtdcInvestorFullNameType[101] 691 | ctypedef char TThostFtdcUOABrokerIDType[11] 692 | ctypedef char TThostFtdcUOAZipCodeType[11] 693 | ctypedef char TThostFtdcUOAEMailType[101] 694 | ctypedef char TThostFtdcOldCityType[41] 695 | ctypedef char TThostFtdcCorporateIdentifiedCardNoType[101] 696 | ctypedef char TThostFtdcHasBoardType 697 | ctypedef char TThostFtdcStartModeType 698 | ctypedef char TThostFtdcTemplateTypeType 699 | ctypedef char TThostFtdcLoginModeType 700 | ctypedef char TThostFtdcPromptTypeType 701 | ctypedef char TThostFtdcLedgerManageIDType[51] 702 | ctypedef char TThostFtdcInvestVarietyType[101] 703 | ctypedef char TThostFtdcBankAccountTypeType[2] 704 | ctypedef char TThostFtdcLedgerManageBankType[101] 705 | ctypedef char TThostFtdcCffexDepartmentNameType[101] 706 | ctypedef char TThostFtdcCffexDepartmentCodeType[9] 707 | ctypedef char TThostFtdcHasTrusteeType 708 | ctypedef char TThostFtdcCSRCMemo1Type[41] 709 | ctypedef char TThostFtdcAssetmgrCFullNameType[101] 710 | ctypedef char TThostFtdcAssetmgrApprovalNOType[51] 711 | ctypedef char TThostFtdcAssetmgrMgrNameType[401] 712 | ctypedef char TThostFtdcAmTypeType 713 | ctypedef char TThostFtdcCSRCAmTypeType[5] 714 | ctypedef char TThostFtdcCSRCFundIOTypeType 715 | ctypedef char TThostFtdcCusAccountTypeType 716 | ctypedef char TThostFtdcCSRCNationalType[4] 717 | ctypedef char TThostFtdcCSRCSecAgentIDType[11] 718 | ctypedef char TThostFtdcLanguageTypeType 719 | ctypedef char TThostFtdcAmAccountType[23] 720 | ctypedef char TThostFtdcAssetmgrClientTypeType 721 | ctypedef char TThostFtdcAssetmgrTypeType 722 | ctypedef char TThostFtdcUOMType[11] 723 | ctypedef char TThostFtdcSHFEInstLifePhaseType[3] 724 | ctypedef char TThostFtdcSHFEProductClassType[11] 725 | ctypedef char TThostFtdcPriceDecimalType[2] 726 | ctypedef char TThostFtdcInTheMoneyFlagType[2] 727 | ctypedef char TThostFtdcCheckInstrTypeType 728 | ctypedef char TThostFtdcDeliveryTypeType 729 | ctypedef double TThostFtdcBigMoneyType 730 | ctypedef char TThostFtdcMaxMarginSideAlgorithmType 731 | ctypedef char TThostFtdcDAClientTypeType 732 | ctypedef char TThostFtdcCombinInstrIDType[61] 733 | ctypedef char TThostFtdcCombinSettlePriceType[61] 734 | ctypedef int TThostFtdcDCEPriorityType 735 | ctypedef int TThostFtdcTradeGroupIDType 736 | ctypedef int TThostFtdcIsCheckPrepaType 737 | ctypedef char TThostFtdcUOAAssetmgrTypeType 738 | ctypedef char TThostFtdcDirectionEnType 739 | ctypedef char TThostFtdcOffsetFlagEnType 740 | ctypedef char TThostFtdcHedgeFlagEnType 741 | ctypedef char TThostFtdcFundIOTypeEnType 742 | ctypedef char TThostFtdcFundTypeEnType 743 | ctypedef char TThostFtdcFundDirectionEnType 744 | ctypedef char TThostFtdcFundMortDirectionEnType 745 | ctypedef char TThostFtdcSwapBusinessTypeType[3] 746 | ctypedef char TThostFtdcOptionsTypeType 747 | ctypedef char TThostFtdcStrikeModeType 748 | ctypedef char TThostFtdcStrikeTypeType 749 | ctypedef char TThostFtdcApplyTypeType 750 | ctypedef char TThostFtdcGiveUpDataSourceType 751 | ctypedef char TThostFtdcExecOrderSysIDType[21] 752 | ctypedef char TThostFtdcExecResultType 753 | ctypedef int TThostFtdcStrikeSequenceType 754 | ctypedef char TThostFtdcStrikeTimeType[13] 755 | ctypedef char TThostFtdcCombinationTypeType 756 | ctypedef char TThostFtdcDceCombinationTypeType 757 | ctypedef char TThostFtdcOptionRoyaltyPriceTypeType 758 | ctypedef char TThostFtdcBalanceAlgorithmType 759 | ctypedef char TThostFtdcActionTypeType 760 | ctypedef char TThostFtdcForQuoteStatusType 761 | ctypedef char TThostFtdcValueMethodType 762 | ctypedef char TThostFtdcExecOrderPositionFlagType 763 | ctypedef char TThostFtdcExecOrderCloseFlagType 764 | ctypedef char TThostFtdcProductTypeType 765 | ctypedef char TThostFtdcCZCEUploadFileNameType 766 | ctypedef char TThostFtdcDCEUploadFileNameType 767 | ctypedef char TThostFtdcSHFEUploadFileNameType 768 | ctypedef char TThostFtdcCFFEXUploadFileNameType 769 | ctypedef char TThostFtdcCombDirectionType 770 | ctypedef char TThostFtdcStrikeOffsetTypeType 771 | ctypedef char TThostFtdcReserveOpenAccStasType 772 | ctypedef char TThostFtdcLoginRemarkType[36] 773 | ctypedef char TThostFtdcInvestUnitIDType[17] 774 | ctypedef int TThostFtdcBulletinIDType 775 | ctypedef char TThostFtdcNewsTypeType[3] 776 | ctypedef char TThostFtdcNewsUrgencyType 777 | ctypedef char TThostFtdcAbstractType[81] 778 | ctypedef char TThostFtdcComeFromType[21] 779 | ctypedef char TThostFtdcURLLinkType[201] 780 | ctypedef char TThostFtdcLongIndividualNameType[161] 781 | ctypedef char TThostFtdcLongFBEBankAccountNameType[161] 782 | ctypedef char TThostFtdcDateTimeType[17] 783 | ctypedef char TThostFtdcWeakPasswordSourceType 784 | ctypedef char TThostFtdcRandomStringType[17] 785 | ctypedef char TThostFtdcOrderMemoType[13] 786 | ctypedef char TThostFtdcOptSelfCloseFlagType 787 | ctypedef char TThostFtdcBizTypeType 788 | ctypedef char TThostFtdcAppTypeType 789 | ctypedef char TThostFtdcAppIDType[33] 790 | ctypedef int TThostFtdcSystemInfoLenType 791 | ctypedef int TThostFtdcAdditionalInfoLenType 792 | ctypedef char TThostFtdcClientSystemInfoType[273] 793 | ctypedef char TThostFtdcAdditionalInfoType[261] 794 | ctypedef char TThostFtdcBase64ClientSystemInfoType[365] 795 | ctypedef char TThostFtdcBase64AdditionalInfoType[349] 796 | ctypedef int TThostFtdcCurrentAuthMethodType 797 | ctypedef int TThostFtdcCaptchaInfoLenType 798 | ctypedef char TThostFtdcCaptchaInfoType[2561] 799 | ctypedef int TThostFtdcUserTextSeqType 800 | ctypedef char TThostFtdcHandshakeDataType[301] 801 | ctypedef int TThostFtdcHandshakeDataLenType 802 | ctypedef char TThostFtdcCryptoKeyVersionType[31] 803 | ctypedef int TThostFtdcRsaKeyVersionType 804 | ctypedef char TThostFtdcSoftwareProviderIDType[22] 805 | ctypedef char TThostFtdcCollectTimeType[21] 806 | ctypedef int TThostFtdcQueryFreqType 807 | ctypedef char TThostFtdcResponseValueType 808 | ctypedef char TThostFtdcOTCTradeTypeType 809 | ctypedef char TThostFtdcMatchTypeType 810 | ctypedef char TThostFtdcOTCTraderIDType[31] 811 | ctypedef double TThostFtdcRiskValueType 812 | ctypedef char TThostFtdcIDBNameType[100] 813 | ctypedef double TThostFtdcDiscountRatioType 814 | ctypedef char TThostFtdcAuthTypeType 815 | ctypedef char TThostFtdcClassTypeType 816 | ctypedef char TThostFtdcTradingTypeType 817 | ctypedef char TThostFtdcProductStatusType 818 | ctypedef char TThostFtdcSyncDeltaStatusType 819 | ctypedef char TThostFtdcActionDirectionType 820 | ctypedef char TThostFtdcOrderCancelAlgType 821 | ctypedef char TThostFtdcSyncDescriptionType[257] 822 | ctypedef int TThostFtdcCommonIntType 823 | ctypedef char TThostFtdcSysVersionType[41] 824 | ctypedef char TThostFtdcOpenLimitControlLevelType 825 | ctypedef char TThostFtdcOrderFreqControlLevelType 826 | ctypedef char TThostFtdcEnumBoolType 827 | ctypedef char TThostFtdcTimeRangeType 828 | ctypedef double TThostFtdcDeltaType 829 | ctypedef int TThostFtdcSpreadIdType 830 | ctypedef char TThostFtdcPortfolioType 831 | ctypedef int TThostFtdcPortfolioDefIDType 832 | ctypedef char TThostFtdcWithDrawParamIDType 833 | ctypedef char TThostFtdcWithDrawParamValueType[41] 834 | ctypedef char TThostFtdcInvstTradingRightType 835 | ctypedef int TThostFtdcThostFunctionCodeType 836 | ctypedef double TThostFtdcSPMMDiscountRatioType 837 | ctypedef char TThostFtdcSPMMModelDescType[129] 838 | ctypedef char TThostFtdcSPMMModelIDType[33] 839 | ctypedef char TThostFtdcSPMMProductIDType[41] 840 | ctypedef char TThostFtdcInstMarginCalIDType 841 | ctypedef char TThostFtdcProductIDType[41] 842 | ctypedef double TThostFtdcHedgeRateType 843 | ctypedef int TThostFtdcRCAMSPriorityType 844 | ctypedef double TThostFtdcAdjustValueType 845 | ctypedef char TThostFtdcRCAMSCombinationTypeType 846 | ctypedef char TThostFtdcRuleIdType[51] 847 | ctypedef char TThostFtdcPortfTypeType 848 | ctypedef char TThostFtdcInstrumentClassType 849 | ctypedef int TThostFtdcCommodityGroupIDType 850 | ctypedef double TThostFtdcStdPositionType 851 | ctypedef char TThostFtdcProdChangeFlagType 852 | ctypedef char TThostFtdcPwdRcdSrcType 853 | ctypedef char TThostFtdcAddrSrvModeType 854 | ctypedef char TThostFtdcAddrVerType 855 | ctypedef char TThostFtdcAddrRemarkType[161] 856 | ctypedef char TThostFtdcAddrNameType[65] 857 | ctypedef char TThostFtdcIpAddrType[129] 858 | ctypedef char TThostFtdcTGSessionQryStatusType 859 | ctypedef char TThostFtdcOffsetTypeType 860 | ctypedef char TThostFtdcSiteType[51] 861 | ctypedef char TThostFtdcNetOperatorType[9] 862 | -------------------------------------------------------------------------------- /ctpwrapper/headers/__init__.pxd: -------------------------------------------------------------------------------- 1 | # distutils: language=c++ 2 | """ 3 | (Copyright) 2018, Winton Wang <365504029@qq.com> 4 | 5 | ctpwrapper is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU LGPLv3 as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with ctpwrapper. If not, see . 17 | 18 | """ 19 | -------------------------------------------------------------------------------- /ctpwrapper/headers/cMdAPI.pxd: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | # distutils: language=c++ 3 | """ 4 | (Copyright) 2018, Winton Wang <365504029@qq.com> 5 | 6 | ctpwrapper is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU LGPLv3 as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with ctpwrapper. If not, see . 18 | 19 | """ 20 | from cpython cimport PyObject 21 | from libc.string cimport const_char 22 | from libcpp cimport bool as cbool 23 | 24 | # from libcpp.memory cimport shared_ptr,make_shared 25 | 26 | from .ThostFtdcUserApiStruct cimport ( 27 | CThostFtdcReqUserLoginField, 28 | CThostFtdcUserLogoutField, 29 | CThostFtdcFensUserInfoField, 30 | CThostFtdcQryMulticastInstrumentField 31 | ) 32 | 33 | cdef extern from 'ThostFtdcMdApi.h': 34 | 35 | cdef cppclass CMdApi "CThostFtdcMdApi": 36 | 37 | @staticmethod 38 | const_char *GetApiVersion() 39 | 40 | # 删除接口对象本身 41 | # @remark 不再使用本接口对象时,调用该函数删除接口对象 42 | void Release() except + nogil 43 | 44 | # 初始化 45 | # @remark 初始化运行环境,只有调用后,接口才开始工作 46 | void Init() except + nogil 47 | 48 | # 等待接口线程结束运行 49 | # @return 线程退出代码 50 | int Join() except + nogil 51 | 52 | # 获取当前交易日 53 | # @retrun 获取到的交易日 54 | # @remark 只有登录成功后,才能得到正确的交易日 55 | const_char *GetTradingDay() except + nogil 56 | 57 | # 注册前置机网络地址 58 | # @param pszFrontAddress:前置机网络地址。 59 | # @remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。 60 | # @remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。 61 | void RegisterFront(char *pszFrontAddress) except + nogil 62 | 63 | # 注册名字服务器网络地址 64 | # @param pszNsAddress:名字服务器网络地址。 65 | # @remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:12001”。 66 | # @remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”12001”代表服务器端口号。 67 | # @remark RegisterNameServer优先于RegisterFront 68 | void RegisterNameServer(char *pszNsAddress) except + nogil 69 | 70 | # 注册名字服务器用户信息 71 | # @param pFensUserInfo:用户信息。 72 | void RegisterFensUserInfo(CThostFtdcFensUserInfoField *pFensUserInfo) except + nogil 73 | 74 | # 注册回调接口 75 | # @param pSpi 派生自回调接口类的实例 76 | void RegisterSpi(CMdSpi *pSpi) except + nogil 77 | 78 | # 订阅行情。 79 | # @param ppInstrumentID 合约ID 80 | # @param nCount 要订阅/退订行情的合约个数 81 | int SubscribeMarketData(char *ppInstrumentID[], int nCount) except + nogil 82 | 83 | # 退订行情。 84 | # @param ppInstrumentID 合约ID 85 | # @param nCount 要订阅/退订行情的合约个数 86 | int UnSubscribeMarketData(char *ppInstrumentID[], int nCount) except + nogil 87 | 88 | #订阅询价。 89 | #@param ppInstrumentID 合约ID 90 | #@param nCount 要订阅/退订行情的合约个数 91 | int SubscribeForQuoteRsp(char *ppInstrumentID[], int nCount) except + nogil 92 | 93 | #退订询价。 94 | #@param ppInstrumentID 合约ID 95 | #@param nCount 要订阅/退订行情的合约个数 96 | int UnSubscribeForQuoteRsp(char *ppInstrumentID[], int nCount) except + nogil 97 | 98 | # 用户登录请求 99 | int ReqUserLogin(CThostFtdcReqUserLoginField *pReqUserLoginField, int nRequestID) except + nogil 100 | 101 | # 登出请求 102 | int ReqUserLogout(CThostFtdcUserLogoutField *pUserLogout, int nRequestID) except + nogil 103 | 104 | # 请求查询组播合约 105 | int ReqQryMulticastInstrument(CThostFtdcQryMulticastInstrumentField *pQryMulticastInstrument, int nRequestID) except + nogil 106 | 107 | cdef extern from 'ThostFtdcMdApi.h' namespace "CThostFtdcMdApi": 108 | CMdApi *CreateFtdcMdApi(const_char *pszFlowPath, cbool bIsUsingUdp, cbool bIsMulticast) except + nogil 109 | 110 | 111 | cdef extern from 'CMdAPI.h': 112 | cdef cppclass CMdSpi: 113 | CMdSpi(PyObject *obj) except + 114 | -------------------------------------------------------------------------------- /ctpwrapper/headers/cTraderApi.pxd: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | # distutils: language=c++ 3 | """ 4 | (Copyright) 2018, Winton Wang <365504029@qq.com> 5 | 6 | ctpwrapper is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU LGPLv3 as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with ctpwrapper. If not, see . 18 | 19 | """ 20 | from cpython cimport PyObject 21 | from libc.string cimport const_char 22 | 23 | from .ThostFtdcUserApiStruct cimport * 24 | 25 | cdef extern from "ThostFtdcTraderApi.h": 26 | cdef cppclass CTraderApi "CThostFtdcTraderApi": 27 | 28 | @staticmethod 29 | const_char *GetApiVersion() 30 | 31 | # 删除接口对象本身 32 | #@remark 不再使用本接口对象时,调用该函数删除接口对象 33 | void Release() except + nogil 34 | 35 | #初始化 36 | #@remark 初始化运行环境,只有调用后,接口才开始工作 37 | void Init() except + nogil 38 | 39 | #等待接口线程结束运行 40 | #@return 线程退出代码 41 | int Join() except + nogil 42 | 43 | #获取当前交易日 44 | #@retrun 获取到的交易日 45 | #@remark 只有登录成功后,才能得到正确的交易日 46 | const_char *GetTradingDay() except + nogil 47 | 48 | # 获取已连接的前置的信息 49 | # @param pFrontInfo:输入输出参数,用于存储获取到的前置信息,不能为空 50 | # @remark 连接成功后,可获取正确的前置地址信息 51 | # @remark 登录成功后,可获取正确的前置流控信息 52 | void GetFrontInfo(CThostFtdcFrontInfoField *pFrontInfo) except + nogil 53 | 54 | #注册前置机网络地址 55 | #@param pszFrontAddress:前置机网络地址。 56 | #@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。 57 | #@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。 58 | void RegisterFront(char *pszFrontAddress) except + nogil 59 | 60 | #注册名字服务器网络地址 61 | #@param pszNsAddress:名字服务器网络地址。 62 | #@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:12001”。 63 | #@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”12001”代表服务器端口号。 64 | #@remark RegisterNameServer优先于RegisterFront 65 | void RegisterNameServer(char *pszNsAddress) except + nogil 66 | 67 | #注册名字服务器用户信息 68 | #@param pFensUserInfo:用户信息。 69 | void RegisterFensUserInfo(CThostFtdcFensUserInfoField *pFensUserInfo) except + nogil 70 | 71 | #注册回调接口 72 | #@param pSpi 派生自回调接口类的实例 73 | void RegisterSpi(CTraderSpi *pSpi) except + nogil 74 | 75 | #订阅私有流。 76 | #@param nResumeType 私有流重传方式 77 | # THOST_TERT_RESTART:从本交易日开始重传 78 | # THOST_TERT_RESUME:从上次收到的续传 79 | # THOST_TERT_QUICK:只传送登录后私有流的内容 80 | #@remark 该方法要在Init方法前调用。若不调用则不会收到私有流的数据。 81 | void SubscribePrivateTopic(THOST_TE_RESUME_TYPE nResumeType) except + nogil 82 | 83 | #订阅公共流。 84 | #@param nResumeType 公共流重传方式 85 | # THOST_TERT_RESTART:从本交易日开始重传 86 | # THOST_TERT_RESUME:从上次收到的续传 87 | # THOST_TERT_QUICK:只传送登录后公共流的内容 88 | #@remark 该方法要在Init方法前调用。若不调用则不会收到公共流的数据。 89 | void SubscribePublicTopic(THOST_TE_RESUME_TYPE nResumeType) except + nogil 90 | 91 | #客户端认证请求 92 | int ReqAuthenticate(CThostFtdcReqAuthenticateField *pReqAuthenticateField, int nRequestID) except + nogil 93 | 94 | #注册用户终端信息,用于中继服务器多连接模式 95 | #需要在终端认证成功后,用户登录前调用该接口 96 | int RegisterUserSystemInfo(CThostFtdcUserSystemInfoField *pUserSystemInfo) except + nogil 97 | 98 | #上报用户终端信息,用于中继服务器操作员登录模式 99 | # 操作员登录后,可以多次调用该接口上报客户信息 100 | int SubmitUserSystemInfo(CThostFtdcUserSystemInfoField *pUserSystemInfo) except + nogil 101 | 102 | #用户登录请求 103 | int ReqUserLogin(CThostFtdcReqUserLoginField *pReqUserLoginField, int nRequestID) except + nogil 104 | 105 | #登出请求 106 | int ReqUserLogout(CThostFtdcUserLogoutField *pUserLogout, int nRequestID) except + nogil 107 | 108 | #用户口令更新请求 109 | int ReqUserPasswordUpdate(CThostFtdcUserPasswordUpdateField *pUserPasswordUpdate, int nRequestID) except + nogil 110 | 111 | #资金账户口令更新请求 112 | int ReqTradingAccountPasswordUpdate(CThostFtdcTradingAccountPasswordUpdateField *pTradingAccountPasswordUpdate, int nRequestID) except + nogil 113 | 114 | # 查询用户当前支持的认证模式 115 | int ReqUserAuthMethod(CThostFtdcReqUserAuthMethodField *pReqUserAuthMethod, int nRequestID) except + nogil 116 | 117 | # 用户发出获取图形验证码请求 118 | int ReqGenUserCaptcha(CThostFtdcReqGenUserCaptchaField *pReqGenUserCaptcha, int nRequestID) except + nogil 119 | 120 | # 用户发出获取短信验证码请求 121 | int ReqGenUserText(CThostFtdcReqGenUserTextField *pReqGenUserText, int nRequestID) except + nogil 122 | 123 | # 用户发出带有图片验证码的登陆请求 124 | int ReqUserLoginWithCaptcha(CThostFtdcReqUserLoginWithCaptchaField *pReqUserLoginWithCaptcha, int nRequestID) except + nogil 125 | 126 | # 用户发出带有短信验证码的登陆请求 127 | int ReqUserLoginWithText(CThostFtdcReqUserLoginWithTextField *pReqUserLoginWithText, int nRequestID) except + nogil 128 | 129 | # 用户发出带有动态口令的登陆请求 130 | int ReqUserLoginWithOTP(CThostFtdcReqUserLoginWithOTPField *pReqUserLoginWithOTP, int nRequestID) except + nogil 131 | 132 | #报单录入请求 133 | int ReqOrderInsert(CThostFtdcInputOrderField *pInputOrder, int nRequestID) except + nogil 134 | 135 | #预埋单录入请求 136 | int ReqParkedOrderInsert(CThostFtdcParkedOrderField *pParkedOrder, int nRequestID) except + nogil 137 | 138 | #预埋撤单录入请求 139 | int ReqParkedOrderAction(CThostFtdcParkedOrderActionField *pParkedOrderAction, int nRequestID) except + nogil 140 | 141 | #报单操作请求 142 | int ReqOrderAction(CThostFtdcInputOrderActionField *pInputOrderAction, int nRequestID) except + nogil 143 | 144 | #查询最大报单数量请求 145 | 146 | int ReqQryMaxOrderVolume(CThostFtdcQryMaxOrderVolumeField *pQryMaxOrderVolume, int nRequestID) except + nogil 147 | 148 | #投资者结算结果确认 149 | int ReqSettlementInfoConfirm(CThostFtdcSettlementInfoConfirmField *pSettlementInfoConfirm, int nRequestID) except + nogil 150 | 151 | #请求删除预埋单 152 | int ReqRemoveParkedOrder(CThostFtdcRemoveParkedOrderField *pRemoveParkedOrder, int nRequestID) except + nogil 153 | 154 | #请求删除预埋撤单 155 | int ReqRemoveParkedOrderAction(CThostFtdcRemoveParkedOrderActionField *pRemoveParkedOrderAction, int nRequestID) except + nogil 156 | 157 | #执行宣告录入请求 158 | int ReqExecOrderInsert(CThostFtdcInputExecOrderField *pInputExecOrder, int nRequestID) except + nogil 159 | 160 | #执行宣告操作请求 161 | int ReqExecOrderAction(CThostFtdcInputExecOrderActionField *pInputExecOrderAction, int nRequestID) except + nogil 162 | 163 | #询价录入请求 164 | int ReqForQuoteInsert(CThostFtdcInputForQuoteField *pInputForQuote, int nRequestID) except + nogil 165 | 166 | #报价录入请求 167 | int ReqQuoteInsert(CThostFtdcInputQuoteField *pInputQuote, int nRequestID) except + nogil 168 | 169 | #报价操作请求 170 | int ReqQuoteAction(CThostFtdcInputQuoteActionField *pInputQuoteAction, int nRequestID) except + nogil 171 | 172 | #批量报单操作请求 173 | int ReqBatchOrderAction(CThostFtdcInputBatchOrderActionField *pInputBatchOrderAction, int nRequestID) except + nogil 174 | 175 | #期权自对冲录入请求 176 | int ReqOptionSelfCloseInsert(CThostFtdcInputOptionSelfCloseField *pInputOptionSelfClose, int nRequestID) except + nogil 177 | 178 | #期权自对冲操作请求 179 | int ReqOptionSelfCloseAction(CThostFtdcInputOptionSelfCloseActionField *pInputOptionSelfCloseAction, int nRequestID) except + nogil 180 | 181 | #申请组合录入请求 182 | int ReqCombActionInsert(CThostFtdcInputCombActionField *pInputCombAction, int nRequestID) except + nogil 183 | 184 | #请求查询报单 185 | int ReqQryOrder(CThostFtdcQryOrderField *pQryOrder, int nRequestID) except + nogil 186 | 187 | #请求查询成交 188 | int ReqQryTrade(CThostFtdcQryTradeField *pQryTrade, int nRequestID) except + nogil 189 | 190 | #请求查询投资者持仓 191 | int ReqQryInvestorPosition(CThostFtdcQryInvestorPositionField *pQryInvestorPosition, int nRequestID) except + nogil 192 | 193 | #请求查询资金账户 194 | int ReqQryTradingAccount(CThostFtdcQryTradingAccountField *pQryTradingAccount, int nRequestID) except + nogil 195 | 196 | #请求查询投资者 197 | int ReqQryInvestor(CThostFtdcQryInvestorField *pQryInvestor, int nRequestID) except + nogil 198 | 199 | #请求查询交易编码 200 | int ReqQryTradingCode(CThostFtdcQryTradingCodeField *pQryTradingCode, int nRequestID) except + nogil 201 | 202 | #请求查询合约保证金率 203 | int ReqQryInstrumentMarginRate(CThostFtdcQryInstrumentMarginRateField *pQryInstrumentMarginRate, int nRequestID) except + nogil 204 | 205 | #请求查询合约手续费率 206 | int ReqQryInstrumentCommissionRate(CThostFtdcQryInstrumentCommissionRateField *pQryInstrumentCommissionRate, int nRequestID) except + nogil 207 | 208 | #请求查询交易所 209 | int ReqQryExchange(CThostFtdcQryExchangeField *pQryExchange, int nRequestID) except + nogil 210 | 211 | #请求查询产品 212 | int ReqQryProduct(CThostFtdcQryProductField *pQryProduct, int nRequestID) except + nogil 213 | 214 | #请求查询合约 215 | int ReqQryInstrument(CThostFtdcQryInstrumentField *pQryInstrument, int nRequestID) except + nogil 216 | 217 | #请求查询行情 218 | int ReqQryDepthMarketData(CThostFtdcQryDepthMarketDataField *pQryDepthMarketData, int nRequestID) except + nogil 219 | 220 | # 请求查询交易员报盘机 221 | int ReqQryTraderOffer(CThostFtdcQryTraderOfferField *pQryTraderOffer, int nRequestID) except + nogil 222 | 223 | #请求查询投资者结算结果 224 | int ReqQrySettlementInfo(CThostFtdcQrySettlementInfoField *pQrySettlementInfo, int nRequestID) except + nogil 225 | 226 | #请求查询转帐银行 227 | int ReqQryTransferBank(CThostFtdcQryTransferBankField *pQryTransferBank, int nRequestID) except + nogil 228 | 229 | #请求查询投资者持仓明细 230 | int ReqQryInvestorPositionDetail(CThostFtdcQryInvestorPositionDetailField *pQryInvestorPositionDetail, int nRequestID) except + nogil 231 | 232 | #请求查询客户通知 233 | int ReqQryNotice(CThostFtdcQryNoticeField *pQryNotice, int nRequestID) except + nogil 234 | 235 | #请求查询结算信息确认 236 | int ReqQrySettlementInfoConfirm(CThostFtdcQrySettlementInfoConfirmField *pQrySettlementInfoConfirm, int nRequestID) except + nogil 237 | 238 | #请求查询投资者持仓明细 239 | int ReqQryInvestorPositionCombineDetail(CThostFtdcQryInvestorPositionCombineDetailField *pQryInvestorPositionCombineDetail, int nRequestID) except + nogil 240 | 241 | #请求查询保证金监管系统经纪公司资金账户密钥 242 | int ReqQryCFMMCTradingAccountKey(CThostFtdcQryCFMMCTradingAccountKeyField *pQryCFMMCTradingAccountKey, int nRequestID) except + nogil 243 | 244 | #请求查询仓单折抵信息 245 | int ReqQryEWarrantOffset(CThostFtdcQryEWarrantOffsetField *pQryEWarrantOffset, int nRequestID) except + nogil 246 | 247 | #请求查询投资者品种/跨品种保证金 248 | int ReqQryInvestorProductGroupMargin(CThostFtdcQryInvestorProductGroupMarginField *pQryInvestorProductGroupMargin, int nRequestID) except + nogil 249 | 250 | #请求查询交易所保证金率 251 | int ReqQryExchangeMarginRate(CThostFtdcQryExchangeMarginRateField *pQryExchangeMarginRate, int nRequestID) except + nogil 252 | 253 | #请求查询交易所调整保证金率 254 | int ReqQryExchangeMarginRateAdjust(CThostFtdcQryExchangeMarginRateAdjustField *pQryExchangeMarginRateAdjust, int nRequestID) except + nogil 255 | 256 | #请求查询汇率 257 | int ReqQryExchangeRate(CThostFtdcQryExchangeRateField *pQryExchangeRate, int nRequestID) except + nogil 258 | 259 | #请求查询二级代理操作员银期权限 260 | int ReqQrySecAgentACIDMap(CThostFtdcQrySecAgentACIDMapField *pQrySecAgentACIDMap, int nRequestID) except + nogil 261 | 262 | #请求查询产品报价汇率 263 | int ReqQryProductExchRate(CThostFtdcQryProductExchRateField *pQryProductExchRate, int nRequestID) except + nogil 264 | 265 | #请求查询产品组 266 | int ReqQryProductGroup(CThostFtdcQryProductGroupField *pQryProductGroup, int nRequestID) except + nogil 267 | 268 | #请求查询做市商合约手续费率 269 | int ReqQryMMInstrumentCommissionRate(CThostFtdcQryMMInstrumentCommissionRateField *pQryMMInstrumentCommissionRate, int nRequestID) except + nogil 270 | 271 | #请求查询做市商期权合约手续费 272 | int ReqQryMMOptionInstrCommRate(CThostFtdcQryMMOptionInstrCommRateField *pQryMMOptionInstrCommRate, int nRequestID) except + nogil 273 | 274 | #请求查询报单手续费 275 | int ReqQryInstrumentOrderCommRate(CThostFtdcQryInstrumentOrderCommRateField *pQryInstrumentOrderCommRate, int nRequestID) except + nogil 276 | 277 | #请求查询资金账户 278 | int ReqQrySecAgentTradingAccount(CThostFtdcQryTradingAccountField *pQryTradingAccount, int nRequestID) except + nogil 279 | 280 | #请求查询二级代理商资金校验模式 281 | int ReqQrySecAgentCheckMode(CThostFtdcQrySecAgentCheckModeField *pQrySecAgentCheckMode, int nRequestID) except + nogil 282 | 283 | #请求查询二级代理商信息 284 | int ReqQrySecAgentTradeInfo(CThostFtdcQrySecAgentTradeInfoField *pQrySecAgentTradeInfo, int nRequestID) except + nogil 285 | 286 | #请求查询期权交易成本 287 | int ReqQryOptionInstrTradeCost(CThostFtdcQryOptionInstrTradeCostField *pQryOptionInstrTradeCost, int nRequestID) except + nogil 288 | 289 | #请求查询期权合约手续费 290 | int ReqQryOptionInstrCommRate(CThostFtdcQryOptionInstrCommRateField *pQryOptionInstrCommRate, int nRequestID) except + nogil 291 | 292 | #请求查询执行宣告 293 | int ReqQryExecOrder(CThostFtdcQryExecOrderField *pQryExecOrder, int nRequestID) except + nogil 294 | 295 | #请求查询询价 296 | int ReqQryForQuote(CThostFtdcQryForQuoteField *pQryForQuote, int nRequestID) except + nogil 297 | 298 | #请求查询报价 299 | int ReqQryQuote(CThostFtdcQryQuoteField *pQryQuote, int nRequestID) except + nogil 300 | 301 | #请求查询期权自对冲 302 | int ReqQryOptionSelfClose(CThostFtdcQryOptionSelfCloseField *pQryOptionSelfClose, int nRequestID) except + nogil 303 | 304 | #请求查询投资单元 305 | int ReqQryInvestUnit(CThostFtdcQryInvestUnitField *pQryInvestUnit, int nRequestID) except + nogil 306 | 307 | #请求查询组合合约安全系数 308 | int ReqQryCombInstrumentGuard(CThostFtdcQryCombInstrumentGuardField *pQryCombInstrumentGuard, int nRequestID) except + nogil 309 | 310 | #请求查询申请组合 311 | int ReqQryCombAction(CThostFtdcQryCombActionField *pQryCombAction, int nRequestID) except + nogil 312 | 313 | #请求查询转帐流水 314 | int ReqQryTransferSerial(CThostFtdcQryTransferSerialField *pQryTransferSerial, int nRequestID) except + nogil 315 | 316 | #请求查询银期签约关系 317 | int ReqQryAccountregister(CThostFtdcQryAccountregisterField *pQryAccountregister, int nRequestID) except + nogil 318 | 319 | #请求查询签约银行 320 | int ReqQryContractBank(CThostFtdcQryContractBankField *pQryContractBank, int nRequestID) except + nogil 321 | 322 | #请求查询预埋单 323 | int ReqQryParkedOrder(CThostFtdcQryParkedOrderField *pQryParkedOrder, int nRequestID) except + nogil 324 | 325 | #请求查询预埋撤单 326 | int ReqQryParkedOrderAction(CThostFtdcQryParkedOrderActionField *pQryParkedOrderAction, int nRequestID) except + nogil 327 | 328 | #请求查询交易通知 329 | int ReqQryTradingNotice(CThostFtdcQryTradingNoticeField *pQryTradingNotice, int nRequestID) except + nogil 330 | 331 | #请求查询经纪公司交易参数 332 | int ReqQryBrokerTradingParams(CThostFtdcQryBrokerTradingParamsField *pQryBrokerTradingParams, int nRequestID) except + nogil 333 | 334 | #请求查询经纪公司交易算法 335 | int ReqQryBrokerTradingAlgos(CThostFtdcQryBrokerTradingAlgosField *pQryBrokerTradingAlgos, int nRequestID) except + nogil 336 | 337 | #请求查询监控中心用户令牌 338 | int ReqQueryCFMMCTradingAccountToken(CThostFtdcQueryCFMMCTradingAccountTokenField *pQueryCFMMCTradingAccountToken, int nRequestID) except + nogil 339 | 340 | #期货发起银行资金转期货请求 341 | int ReqFromBankToFutureByFuture(CThostFtdcReqTransferField *pReqTransfer, int nRequestID) except + nogil 342 | 343 | #期货发起期货资金转银行请求 344 | int ReqFromFutureToBankByFuture(CThostFtdcReqTransferField *pReqTransfer, int nRequestID) except + nogil 345 | 346 | #期货发起查询银行余额请求 347 | int ReqQueryBankAccountMoneyByFuture(CThostFtdcReqQueryAccountField *pReqQueryAccount, int nRequestID) except + nogil 348 | 349 | # 请求查询分类合约 350 | int ReqQryClassifiedInstrument(CThostFtdcQryClassifiedInstrumentField *pQryClassifiedInstrument, int nRequestID) except + nogil 351 | 352 | # 请求组合优惠比例 353 | int ReqQryCombPromotionParam(CThostFtdcQryCombPromotionParamField *pQryCombPromotionParam, int nRequestID) except + nogil 354 | 355 | # 投资者风险结算持仓查询 356 | int ReqQryRiskSettleInvstPosition(CThostFtdcQryRiskSettleInvstPositionField *pQryRiskSettleInvstPosition, int nRequestID) except + nogil 357 | 358 | # 风险结算产品查询 359 | int ReqQryRiskSettleProductStatus(CThostFtdcQryRiskSettleProductStatusField *pQryRiskSettleProductStatus, int nRequestID) except + nogil 360 | 361 | # SPBM期货合约参数查询 362 | int ReqQrySPBMFutureParameter(CThostFtdcQrySPBMFutureParameterField *pQrySPBMFutureParameter, int nRequestID) except + nogil 363 | 364 | # SPBM期权合约参数查询 365 | int ReqQrySPBMOptionParameter(CThostFtdcQrySPBMOptionParameterField *pQrySPBMOptionParameter, int nRequestID) except + nogil 366 | 367 | # SPBM品种内对锁仓折扣参数查询 368 | int ReqQrySPBMIntraParameter(CThostFtdcQrySPBMIntraParameterField *pQrySPBMIntraParameter, int nRequestID) except + nogil 369 | 370 | # SPBM跨品种抵扣参数查询 371 | int ReqQrySPBMInterParameter(CThostFtdcQrySPBMInterParameterField *pQrySPBMInterParameter, int nRequestID) except + nogil 372 | 373 | # SPBM组合保证金套餐查询 374 | int ReqQrySPBMPortfDefinition(CThostFtdcQrySPBMPortfDefinitionField *pQrySPBMPortfDefinition, int nRequestID) except + nogil 375 | 376 | # 投资者SPBM套餐选择查询 377 | int ReqQrySPBMInvestorPortfDef(CThostFtdcQrySPBMInvestorPortfDefField *pQrySPBMInvestorPortfDef, int nRequestID) except + nogil 378 | 379 | # 投资者新型组合保证金系数查询 380 | int ReqQryInvestorPortfMarginRatio(CThostFtdcQryInvestorPortfMarginRatioField *pQryInvestorPortfMarginRatio, int nRequestID) except + nogil 381 | 382 | # 投资者产品SPBM明细查询 383 | int ReqQryInvestorProdSPBMDetail(CThostFtdcQryInvestorProdSPBMDetailField *pQryInvestorProdSPBMDetail, int nRequestID) except + nogil 384 | 385 | # 投资者商品组SPMM记录查询 386 | int ReqQryInvestorCommoditySPMMMargin(CThostFtdcQryInvestorCommoditySPMMMarginField *pQryInvestorCommoditySPMMMargin, int nRequestID) except + nogil 387 | 388 | # 投资者商品群SPMM记录查询 389 | int ReqQryInvestorCommodityGroupSPMMMargin(CThostFtdcQryInvestorCommodityGroupSPMMMarginField *pQryInvestorCommodityGroupSPMMMargin, int nRequestID) except + nogil 390 | 391 | # SPMM合约参数查询 392 | int ReqQrySPMMInstParam(CThostFtdcQrySPMMInstParamField *pQrySPMMInstParam, int nRequestID) except + nogil 393 | 394 | # SPMM产品参数查询 395 | int ReqQrySPMMProductParam(CThostFtdcQrySPMMProductParamField *pQrySPMMProductParam, int nRequestID) except + nogil 396 | 397 | # SPBM附加跨品种抵扣参数查询 398 | int ReqQrySPBMAddOnInterParameter(CThostFtdcQrySPBMAddOnInterParameterField *pQrySPBMAddOnInterParameter, int nRequestID) except + nogil 399 | 400 | # RCAMS产品组合信息查询 401 | int ReqQryRCAMSCombProductInfo(CThostFtdcQryRCAMSCombProductInfoField *pQryRCAMSCombProductInfo, int nRequestID) except + nogil 402 | 403 | # RCAMS同合约风险对冲参数查询 404 | int ReqQryRCAMSInstrParameter(CThostFtdcQryRCAMSInstrParameterField *pQryRCAMSInstrParameter, int nRequestID) except + nogil 405 | 406 | # RCAMS品种内风险对冲参数查询 407 | int ReqQryRCAMSIntraParameter(CThostFtdcQryRCAMSIntraParameterField *pQryRCAMSIntraParameter, int nRequestID) except + nogil 408 | 409 | # RCAMS跨品种风险折抵参数查询 410 | int ReqQryRCAMSInterParameter(CThostFtdcQryRCAMSInterParameterField *pQryRCAMSInterParameter, int nRequestID) except + nogil 411 | 412 | # RCAMS空头期权风险调整参数查询 413 | int ReqQryRCAMSShortOptAdjustParam(CThostFtdcQryRCAMSShortOptAdjustParamField *pQryRCAMSShortOptAdjustParam, int nRequestID) except + nogil 414 | 415 | # RCAMS策略组合持仓查询 416 | int ReqQryRCAMSInvestorCombPosition(CThostFtdcQryRCAMSInvestorCombPositionField *pQryRCAMSInvestorCombPosition, int nRequestID) except + nogil 417 | 418 | # 投资者品种RCAMS保证金查询 419 | int ReqQryInvestorProdRCAMSMargin(CThostFtdcQryInvestorProdRCAMSMarginField *pQryInvestorProdRCAMSMargin, int nRequestID) except + nogil 420 | 421 | # RULE合约保证金参数查询 422 | int ReqQryRULEInstrParameter(CThostFtdcQryRULEInstrParameterField *pQryRULEInstrParameter, int nRequestID) except + nogil 423 | 424 | # RULE品种内对锁仓折扣参数查询 425 | int ReqQryRULEIntraParameter(CThostFtdcQryRULEIntraParameterField *pQryRULEIntraParameter, int nRequestID) except + nogil 426 | 427 | # RULE跨品种抵扣参数查询 428 | int ReqQryRULEInterParameter(CThostFtdcQryRULEInterParameterField *pQryRULEInterParameter, int nRequestID) except + nogil 429 | 430 | # 投资者产品RULE保证金查询 431 | int ReqQryInvestorProdRULEMargin(CThostFtdcQryInvestorProdRULEMarginField *pQryInvestorProdRULEMargin, int nRequestID) except + nogil 432 | 433 | # 投资者新型组合保证金开关查询 434 | int ReqQryInvestorPortfSetting(CThostFtdcQryInvestorPortfSettingField *pQryInvestorPortfSetting, int nRequestID) except + nogil 435 | 436 | # 投资者申报费阶梯收取记录查询 437 | int ReqQryInvestorInfoCommRec(CThostFtdcQryInvestorInfoCommRecField *pQryInvestorInfoCommRec, int nRequestID) except + nogil 438 | 439 | # 组合腿信息查询 440 | int ReqQryCombLeg(CThostFtdcQryCombLegField *pQryCombLeg, int nRequestID) except + nogil 441 | 442 | # 对冲设置请求 443 | int ReqOffsetSetting(CThostFtdcInputOffsetSettingField *pInputOffsetSetting, int nRequestID) except + nogil 444 | 445 | # 对冲设置撤销请求 446 | int ReqCancelOffsetSetting(CThostFtdcInputOffsetSettingField *pInputOffsetSetting, int nRequestID) except + nogil 447 | 448 | # 投资者对冲设置查询 449 | int ReqQryOffsetSetting(CThostFtdcQryOffsetSettingField *pQryOffsetSetting, int nRequestID) except + nogil 450 | 451 | 452 | cdef extern from "ThostFtdcTraderApi.h" namespace "CThostFtdcTraderApi": 453 | CTraderApi *CreateFtdcTraderApi(const_char *pszFlowPath) except + nogil 454 | 455 | cdef extern from "CTraderAPI.h": 456 | cdef cppclass CTraderSpi: 457 | CTraderSpi(PyObject *obj) except + 458 | -------------------------------------------------------------------------------- /doc/ctp/6.7.0.chm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nooperpudd/ctpwrapper/58c13e0e3a3473ebfac57138ffca4d5926fefb37/doc/ctp/6.7.0.chm -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.10 2 | RUN pip3 install cython pip setuptools --upgrade 3 | 4 | WORKDIR /code 5 | -------------------------------------------------------------------------------- /docker/pypy3-Dockerfile: -------------------------------------------------------------------------------- 1 | FROM pypy:3.9 2 | RUN pypy3 -m ensurepip 3 | RUN pip3 install cython pip setuptools --upgrade 4 | WORKDIR /code 5 | -------------------------------------------------------------------------------- /extra/appveyor/compiler.cmd: -------------------------------------------------------------------------------- 1 | :: To build extensions for 64 bit Python 3, we need to configure environment 2 | :: variables to use the MSVC 2010 C++ compilers from GRMSDKX_EN_DVD.iso of: 3 | :: MS Windows SDK for Windows 7 and .NET Framework 4 (SDK v7.1) 4 | :: 5 | :: To build extensions for 64 bit Python 2, we need to configure environment 6 | :: variables to use the MSVC 2008 C++ compilers from GRMSDKX_EN_DVD.iso of: 7 | :: MS Windows SDK for Windows 7 and .NET Framework 3.5 (SDK v7.0) 8 | :: 9 | :: 32 bit builds, and 64-bit builds for 3.5 and beyond, do not require specific 10 | :: environment configurations. 11 | :: 12 | :: Note: this script needs to be run with the /E:ON and /V:ON flags for the 13 | :: cmd interpreter, at least for (SDK v7.0) 14 | :: 15 | :: More details at: 16 | :: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows 17 | :: http://stackoverflow.com/a/13751649/163740 18 | :: 19 | :: Author: Olivier Grisel 20 | :: License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/ 21 | :: 22 | :: Notes about batch files for Python people: 23 | :: 24 | :: Quotes in values are literally part of the values: 25 | :: SET FOO="bar" 26 | :: FOO is now five characters long: " b a r " 27 | :: If you don't want quotes, don't include them on the right-hand side. 28 | :: 29 | :: The CALL lines at the end of this file look redundant, but if you move them 30 | :: outside of the IF clauses, they do not run properly in the SET_SDK_64==Y 31 | :: case, I don't know why. 32 | 33 | @ECHO OFF 34 | 35 | SET COMMAND_TO_RUN=%* 36 | SET WIN_SDK_ROOT=C:\Program Files\Microsoft SDKs\Windows 37 | SET WIN_WDK=c:\Program Files (x86)\Windows Kits\10\Include\wdf 38 | 39 | :: Extract the major and minor versions, and allow for the minor version to be 40 | :: more than 9. This requires the version number to have two dots in it. 41 | SET MAJOR_PYTHON_VERSION=%PYTHON_VERSION:~0,1% 42 | IF "%PYTHON_VERSION:~3,1%" == "." ( 43 | SET MINOR_PYTHON_VERSION=%PYTHON_VERSION:~2,1% 44 | ) ELSE ( 45 | SET MINOR_PYTHON_VERSION=%PYTHON_VERSION:~2,2% 46 | ) 47 | 48 | :: Based on the Python version, determine what SDK version to use, and whether 49 | :: to set the SDK for 64-bit. 50 | IF %MAJOR_PYTHON_VERSION% == 2 ( 51 | SET WINDOWS_SDK_VERSION="v7.0" 52 | SET SET_SDK_64=Y 53 | ) ELSE ( 54 | IF %MAJOR_PYTHON_VERSION% == 3 ( 55 | SET WINDOWS_SDK_VERSION="v7.1" 56 | IF %MINOR_PYTHON_VERSION% LEQ 4 ( 57 | SET SET_SDK_64=Y 58 | ) ELSE ( 59 | SET SET_SDK_64=N 60 | IF EXIST "%WIN_WDK%" ( 61 | :: See: https://connect.microsoft.com/VisualStudio/feedback/details/1610302/ 62 | REN "%WIN_WDK%" 0wdf 63 | ) 64 | ) 65 | ) ELSE ( 66 | ECHO Unsupported Python version: "%MAJOR_PYTHON_VERSION%" 67 | EXIT 1 68 | ) 69 | ) 70 | 71 | 72 | IF %PYTHON_ARCH% == 64 ( 73 | IF %SET_SDK_64% == Y ( 74 | ECHO Configuring Windows SDK %WINDOWS_SDK_VERSION% for Python %MAJOR_PYTHON_VERSION% on a 64 bit architecture 75 | SET DISTUTILS_USE_SDK=1 76 | SET MSSdk=1 77 | "%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Setup\WindowsSdkVer.exe" -q -version:%WINDOWS_SDK_VERSION% 78 | "%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x64 /release 79 | ECHO Executing: %COMMAND_TO_RUN% 80 | call %COMMAND_TO_RUN% || EXIT 1 81 | ) ELSE ( 82 | ECHO Using default MSVC build environment for 64 bit architecture 83 | ECHO Executing: %COMMAND_TO_RUN% 84 | call %COMMAND_TO_RUN% || EXIT 1 85 | ) 86 | ) ELSE ( 87 | ECHO Using default MSVC build environment for 32 bit architecture 88 | ECHO Executing: %COMMAND_TO_RUN% 89 | call %COMMAND_TO_RUN% || EXIT 1 90 | ) -------------------------------------------------------------------------------- /generate.py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | import codecs 3 | import os 4 | import re 5 | from collections import OrderedDict 6 | 7 | CTP_PATH = os.path.join(os.path.dirname(__file__), "ctp") 8 | 9 | HEADER_PATH = os.path.join(CTP_PATH, "header") 10 | 11 | USERAPI_DATA_FILE = os.path.join(HEADER_PATH, "ThostFtdcUserApiDataType.h") 12 | USERAPI_STRUCT_FILE = os.path.join(HEADER_PATH, "ThostFtdcUserApiStruct.h") 13 | 14 | GENERATE_PATH = os.path.join(os.path.dirname(__file__), "ctpwrapper/headers") 15 | 16 | 17 | def generate_structure(datatype_dict): 18 | """ 19 | generate structure file 20 | :return: 21 | """ 22 | 23 | generate_file = os.path.join(GENERATE_PATH, "ThostFtdcUserApiStruct.pxd") 24 | 25 | data_struct_file = codecs.open(generate_file, "w", encoding="utf-8") 26 | data_struct_file.write("# encoding:utf-8") 27 | data_struct_file.write("\n" * 2) 28 | 29 | data_struct_file.write("from .ThostFtdcUserApiDataType cimport *\n") 30 | data_struct_file.write("\n" * 2) 31 | 32 | data_struct_file.write("cdef extern from 'ThostFtdcUserApiStruct.h':\n") 33 | 34 | for line in codecs.open(USERAPI_STRUCT_FILE, encoding="utf-8"): 35 | if line.startswith("struct"): 36 | result = re.findall("\w+", line) 37 | name = result[1] 38 | data_struct_file.write(" cdef struct {name}:\n".format(name=name)) 39 | else: 40 | 41 | result = re.findall("\w+", line) 42 | 43 | if result: 44 | type_name = result[0] 45 | if type_name in datatype_dict: 46 | data_struct_file.write(" " + line.replace(";", "")) 47 | 48 | data_struct_file.close() 49 | 50 | 51 | def generate_datatype(): 52 | """ 53 | generate structure data 54 | :return: 55 | """ 56 | datatype_dict = OrderedDict() 57 | 58 | generate_file = os.path.join(GENERATE_PATH, "ThostFtdcUserApiDataType.pxd") 59 | data_type_file = codecs.open(generate_file, "w", encoding="utf-8") 60 | 61 | data_type_file.write("# encoding:utf-8") 62 | data_type_file.write("\n" * 2) 63 | data_type_file.write("cdef extern from 'ThostFtdcUserApiDataType.h':\n") 64 | 65 | for line in codecs.open(USERAPI_DATA_FILE, encoding="utf-8"): 66 | if line.startswith("enum"): 67 | # special output data 68 | data_type_file.write(""" 69 | cdef enum THOST_TE_RESUME_TYPE: 70 | THOST_TERT_RESTART = 0 71 | THOST_TERT_RESUME 72 | THOST_TERT_QUICK 73 | THOST_TERT_NONE 74 | """) 75 | # special write data 76 | if line.startswith("#define"): 77 | pass 78 | elif line.startswith("typedef"): 79 | result = re.findall("\w+", line) 80 | 81 | _type = result[1] 82 | name = result[2] 83 | datatype_dict.setdefault(name) 84 | length = None 85 | 86 | if len(result) == 4: # char xxxxx [10] 87 | length = result[3] 88 | 89 | if length: 90 | data_type_file.write(" ctypedef {_type} {name}[{length}]\n".format(_type=_type, 91 | name=name, 92 | length=length)) 93 | else: 94 | data_type_file.write(" ctypedef {_type} {name}\n".format(_type=_type, 95 | name=name)) 96 | data_type_file.close() 97 | return datatype_dict 98 | 99 | 100 | if __name__ == "__main__": 101 | datatype_dict = generate_datatype() 102 | generate_structure(datatype_dict) 103 | -------------------------------------------------------------------------------- /generate_structure.py: -------------------------------------------------------------------------------- 1 | # encoding=utf-8 2 | import codecs 3 | import linecache 4 | import os 5 | import re 6 | from collections import OrderedDict 7 | 8 | CTP_PATH = os.path.join(os.path.dirname(__file__), "ctp") 9 | HEADER_PATH = os.path.join(CTP_PATH, "header") 10 | USERAPI_DATA_FILE = os.path.join(HEADER_PATH, "ThostFtdcUserApiDataType.h") 11 | USERAPI_STRUCT_FILE = os.path.join(HEADER_PATH, "ThostFtdcUserApiStruct.h") 12 | GENERATE_FILE = os.path.join(os.path.dirname(__file__), "ctpwrapper/ApiStructure.py") 13 | 14 | 15 | class Parse(object): 16 | """ 17 | 解析结构体 18 | """ 19 | 20 | def __init__(self, type_file, struct_file): 21 | """ 22 | :param type_file: 23 | :param struct_file: 24 | """ 25 | self.type_file = type_file 26 | self.struct_file = struct_file 27 | 28 | self.data_type = OrderedDict() 29 | self.struct = OrderedDict() 30 | self.struct_doc = dict() # for struct doc 31 | 32 | def parse_datatype(self): 33 | """ 34 | 处理 UserApiDataType file. 35 | """ 36 | for line in codecs.open(self.type_file, encoding="utf-8"): 37 | if line.startswith("typedef"): 38 | 39 | result = re.findall("\w+", line) 40 | name = result[2] 41 | type_ = result[1] 42 | 43 | if len(result) == 4 and type_ == "char": 44 | self.data_type[name] = { 45 | "type": "str", 46 | "length": int(result[3]) 47 | } 48 | elif type_ == "char": 49 | self.data_type[name] = { 50 | "type": "str", 51 | } 52 | else: 53 | self.data_type[name] = { 54 | "type": type_, 55 | } 56 | 57 | def parse_struct(self): 58 | """ 59 | 解析结构体定义 60 | """ 61 | self.parse_datatype() 62 | 63 | for index, line in enumerate(codecs.open(self.struct_file, 64 | encoding="utf-8")): 65 | doc_line = index 66 | 67 | if line.startswith("struct"): 68 | result = re.findall("\w+", line) 69 | name = result[1] # assign the name 70 | self.struct[name] = OrderedDict() 71 | 72 | # stuct doc 73 | struct_doc = linecache.getline(self.struct_file, doc_line) 74 | struct_doc = struct_doc.strip().replace("///", "") 75 | self.struct_doc[name] = struct_doc 76 | 77 | if line.strip().startswith("TThostFtdc"): 78 | result = re.findall("\w+", line) 79 | field_type = result[0] 80 | field_name = result[1].replace(";", "") 81 | struct_dict = self.struct[name] 82 | struct_dict[field_name] = self.data_type[field_type] 83 | 84 | # doc 85 | field_doc = linecache.getline(self.struct_file, doc_line) 86 | field_doc = field_doc.strip().replace("///", "") 87 | struct_dict[field_name + "_doc"] = field_doc 88 | 89 | 90 | def generate_struct(struct, struct_doc, py_file): 91 | for item in struct: 92 | 93 | py_file.write("class {class_name}(Base):\n".format(class_name=item.replace("CThostFtdc", ""))) 94 | py_file.write(' """{doc}"""\n'.format(doc=struct_doc[item])) 95 | py_file.write(" _fields_ = [\n") 96 | struct_dict = struct[item] 97 | 98 | for field in struct_dict: 99 | 100 | if field.endswith("_doc"): 101 | continue 102 | field_data = struct_dict[field] 103 | field_doc = struct[item][field+"_doc"] 104 | 105 | if field_data["type"] == "double": 106 | py_file.write(" ('{field}', ctypes.c_double), # {doc}\n".format(field=field, doc=field_doc)) 107 | elif field_data["type"] == "int": 108 | py_file.write(" ('{field}', ctypes.c_int), # {doc}\n".format(field=field, doc=field_doc)) 109 | elif field_data["type"] == "short": 110 | py_file.write(" ('{field}', ctypes.c_short), # {doc}\n".format(field=field, doc=field_doc)) 111 | elif field_data["type"] == "str" and "length" not in field_data: 112 | py_file.write(" ('{field}', ctypes.c_char), # {doc} \n ".format(field=field, doc=field_doc)) 113 | elif field_data["type"] == "str" and "length" in field_data: 114 | py_file.write(" ('{field}', ctypes.c_char*{len}), # {doc}\n".format(field=field, 115 | len=field_data["length"], 116 | doc=field_doc)) 117 | 118 | py_file.write(" ]\n") 119 | 120 | struct_fields = [] 121 | for field in struct_dict: 122 | 123 | if field.endswith("_doc"): 124 | continue 125 | 126 | field_data = struct_dict[field] 127 | if field_data["type"] == "double": 128 | struct_fields.append("%s:float=0.0" % field) 129 | elif field_data["type"] in ["int", "short"]: 130 | struct_fields.append("%s:int=0" % field) 131 | else: 132 | struct_fields.append("%s:str=''" % field) 133 | py_file.write(" def __init__(self,%s):\n" % ",".join(struct_fields)) 134 | py_file.write(" super({class_name},self).__init__()\n".format(class_name=item.replace("CThostFtdc", ""))) 135 | 136 | for field in struct_dict: 137 | if field.endswith("_doc"): 138 | continue 139 | if struct_dict[field]["type"] == "double": 140 | py_file.write(" self.%s=float(%s)\n" % (field, field)) 141 | if struct_dict[field]["type"] in ["int", "short"]: 142 | py_file.write(" self.%s=int(%s)\n" % (field, field)) 143 | if struct_dict[field]["type"] == "str": 144 | py_file.write(" self.%s=self._to_bytes(%s)\n" % (field, field)) 145 | 146 | 147 | def generate_interface(): 148 | parse = Parse(USERAPI_DATA_FILE, USERAPI_STRUCT_FILE) 149 | parse.parse_struct() 150 | structure = parse.struct 151 | struct_doc = parse.struct_doc 152 | # generate python 153 | py_file = codecs.open(GENERATE_FILE, "w", encoding="utf-8") 154 | 155 | py_file.write('# encoding=utf-8\n') 156 | py_file.write("import ctypes\n") 157 | py_file.write("from ctpwrapper.base import Base\n") 158 | py_file.write("\n" * 2) 159 | 160 | generate_struct(structure, struct_doc, py_file) 161 | 162 | py_file.close() 163 | 164 | 165 | if __name__ == "__main__": 166 | generate_interface() 167 | -------------------------------------------------------------------------------- /images/alipay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nooperpudd/ctpwrapper/58c13e0e3a3473ebfac57138ffca4d5926fefb37/images/alipay.png -------------------------------------------------------------------------------- /images/wechat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nooperpudd/ctpwrapper/58c13e0e3a3473ebfac57138ffca4d5926fefb37/images/wechat.jpg -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | clean: 2 | python3 setup.py clean --all 3 | rm -rf build dist 4 | find ./ctpwrapper/ -name "Md*.so" -delete 5 | find ./ctpwrapper/ -name "Trader*.so" -delete 6 | find ./ctpwrapper/ -name "*.cpp" -delete 7 | 8 | 9 | .PHONY: build-local 10 | build-local: clean 11 | python3 setup.py build_ext --inplace 12 | 13 | 14 | .PHONY: build 15 | build: clean 16 | python3 setup.py build 17 | 18 | .PHONY: install 19 | install: clean 20 | python3 setup.py install 21 | 22 | .PHONY: sdist 23 | sdist: clean 24 | python3 setup.py sdist 25 | 26 | twine: 27 | twine upload dist/* 28 | 29 | .PHONY: pypy 30 | pypy: 31 | pypy3 setup.py clean --all 32 | pypy3 setup.py build_ext --inplace 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | 3 | ; To send tests to multiple CPUs 4 | ;addopts = -n2 -v --boxed 5 | # todo support multi tests 6 | addopts = -v 7 | 8 | testpaths = tests -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | cython 2 | -------------------------------------------------------------------------------- /samples/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "investor_id": "", 3 | "broker_id": "", 4 | "password": "", 5 | "md_server": "tcp://180.168.146.187:10110", 6 | "trader_server": "tcp://180.168.146.187:10100", 7 | "app_id": "simnow_client_test", 8 | "auth_code": "0000000000000000" 9 | } -------------------------------------------------------------------------------- /samples/md_main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # encoding:utf-8 3 | 4 | """ 5 | (Copyright) 2018, Winton Wang <365504029@qq.com> 6 | 7 | ctpwrapper is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU LGPLv3 as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with ctpwrapper. If not, see . 19 | 20 | """ 21 | import json 22 | import socket 23 | import sys 24 | import urllib.parse 25 | from contextlib import closing 26 | import time 27 | from ctpwrapper import ApiStructure 28 | from ctpwrapper import MdApiPy 29 | 30 | 31 | def check_address_port(tcp): 32 | """ 33 | :param tcp: 34 | :return: 35 | """ 36 | host_schema = urllib.parse.urlparse(tcp) 37 | 38 | ip = host_schema.hostname 39 | port = host_schema.port 40 | 41 | with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock: 42 | if sock.connect_ex((ip, port)) == 0: 43 | return True # OPEN 44 | else: 45 | return False # closed 46 | 47 | 48 | class Md(MdApiPy): 49 | """ 50 | """ 51 | 52 | def __init__(self, broker_id, investor_id, password, request_id=100): 53 | """ 54 | """ 55 | self.login = False 56 | self.broker_id = broker_id 57 | self.investor_id = investor_id 58 | self.password = password 59 | self._request_id = request_id 60 | 61 | @property 62 | def request_id(self): 63 | self._request_id += 1 64 | return self._request_id 65 | 66 | def OnRspError(self, pRspInfo, nRequestID, bIsLast): 67 | print("OnRspError:") 68 | print("requestID:", nRequestID) 69 | print(pRspInfo) 70 | print(bIsLast) 71 | 72 | def OnFrontConnected(self): 73 | """ 74 | :return: 75 | """ 76 | user_login = ApiStructure.ReqUserLoginField(BrokerID=self.broker_id, UserID=self.investor_id, Password=self.password) 77 | self.ReqUserLogin(user_login, self.request_id) 78 | 79 | def OnFrontDisconnected(self, nReason): 80 | print("Md OnFrontDisconnected {0}".format(nReason)) 81 | sys.exit() 82 | 83 | def OnHeartBeatWarning(self, nTimeLapse): 84 | """心跳超时警告。当长时间未收到报文时,该方法被调用。 85 | @param nTimeLapse 距离上次接收报文的时间 86 | """ 87 | print('Md OnHeartBeatWarning, time = {0}'.format(nTimeLapse)) 88 | 89 | def OnRspUserLogin(self, pRspUserLogin, pRspInfo, nRequestID, bIsLast): 90 | """ 91 | 用户登录应答 92 | :param pRspUserLogin: 93 | :param pRspInfo: 94 | :param nRequestID: 95 | :param bIsLast: 96 | :return: 97 | """ 98 | print("OnRspUserLogin") 99 | print("requestID:", nRequestID) 100 | print("RspInfo:", pRspInfo) 101 | 102 | if pRspInfo.ErrorID != 0: 103 | print("RspInfo:", pRspInfo) 104 | else: 105 | print("user login successfully") 106 | print("RspUserLogin:", pRspUserLogin) 107 | self.login = True 108 | 109 | def OnRtnDepthMarketData(self, pDepthMarketData): 110 | """ 111 | 行情订阅推送信息 112 | :param pDepthMarketData: 113 | :return: 114 | """ 115 | print("OnRtnDepthMarketData") 116 | print("DepthMarketData:", pDepthMarketData) 117 | 118 | def OnRspSubMarketData(self, pSpecificInstrument, pRspInfo, nRequestID, bIsLast): 119 | """ 120 | 订阅行情应答 121 | :param pSpecificInstrument: 122 | :param pRspInfo: 123 | :param nRequestID: 124 | :param bIsLast: 125 | :return: 126 | """ 127 | print("OnRspSubMarketData") 128 | print("RequestId:", nRequestID) 129 | print("isLast:", bIsLast) 130 | print("pRspInfo:", pRspInfo) 131 | print("pSpecificInstrument:", pSpecificInstrument) 132 | 133 | def OnRspUnSubMarketData(self, pSpecificInstrument, pRspInfo, nRequestID, bIsLast): 134 | """ 135 | 取消订阅行情应答 136 | :param pSpecificInstrument: 137 | :param pRspInfo: 138 | :param nRequestID: 139 | :param bIsLast: 140 | :return: 141 | """ 142 | print("OnRspUnSubMarketData") 143 | print("RequestId:", nRequestID) 144 | print("isLast:", bIsLast) 145 | print("pRspInfo:", pRspInfo) 146 | print("pSpecificInstrument:", pSpecificInstrument) 147 | 148 | 149 | def main(): 150 | json_file = open("config.json") 151 | config = json.load(json_file) 152 | json_file.close() 153 | 154 | investor_id = config["investor_id"] 155 | broker_id = config["broker_id"] 156 | password = config["password"] 157 | server = config["md_server"] 158 | 159 | if check_address_port(server): 160 | print("connect to md sever successfully") 161 | # 1 create 162 | # 2 register 163 | # 3 register front 164 | # 4 init 165 | md = Md(broker_id, investor_id, password) 166 | md.Create() 167 | md.RegisterFront(server) 168 | md.Init() 169 | 170 | day = md.GetTradingDay() 171 | print("trading day:", day) 172 | print("md login:", md.login) 173 | if md.login: 174 | md.SubscribeMarketData(["ru2101"]) 175 | time.sleep(30) 176 | md.UnSubscribeMarketData(["ru2101"]) 177 | md.Join() 178 | else: 179 | print("md server is down") 180 | 181 | 182 | if __name__ == "__main__": 183 | main() 184 | -------------------------------------------------------------------------------- /samples/trader_main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # encoding:utf-8 3 | 4 | """ 5 | (Copyright) 2018, Winton Wang <365504029@qq.com> 6 | 7 | ctpwrapper is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU LGPLv3 as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with ctpwrapper. If not, see . 19 | 20 | """ 21 | import json 22 | import socket 23 | import urllib.parse 24 | from contextlib import closing 25 | import time 26 | from ctpwrapper import ApiStructure 27 | from ctpwrapper import TraderApiPy 28 | 29 | 30 | def check_address_port(tcp): 31 | """ 32 | :param tcp: 33 | :return: 34 | """ 35 | host_schema = urllib.parse.urlparse(tcp) 36 | 37 | ip = host_schema.hostname 38 | port = host_schema.port 39 | 40 | with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock: 41 | if sock.connect_ex((ip, port)) == 0: 42 | return True # OPEN 43 | else: 44 | return False # closed 45 | 46 | 47 | class Trader(TraderApiPy): 48 | 49 | def __init__(self, app_id, auth_code, broker_id, investor_id, password, request_id=100): 50 | self.app_id = app_id 51 | self.auth_code = auth_code 52 | self.broker_id = broker_id 53 | self.investor_id = investor_id 54 | self.password = password 55 | self._request_id = request_id 56 | self.login = False 57 | 58 | @property 59 | def request_id(self): 60 | self._request_id += 1 61 | return self._request_id 62 | 63 | def OnRspError(self, pRspInfo, nRequestID, bIsLast): 64 | print("OnRspError:") 65 | print("requestID:", nRequestID) 66 | print(pRspInfo) 67 | print(bIsLast) 68 | 69 | def OnHeartBeatWarning(self, nTimeLapse): 70 | """心跳超时警告。当长时间未收到报文时,该方法被调用。 71 | @param nTimeLapse 距离上次接收报文的时间 72 | """ 73 | print("OnHeartBeatWarning time: ", nTimeLapse) 74 | 75 | def OnFrontDisconnected(self, nReason): 76 | print("OnFrontConnected:", nReason) 77 | 78 | def OnFrontConnected(self): 79 | print("OnFrontConnected") 80 | authenticate = ApiStructure.ReqAuthenticateField(BrokerID=self.broker_id, 81 | UserID=self.investor_id, 82 | AppID=self.app_id, 83 | AuthCode=self.auth_code) 84 | 85 | self.ReqAuthenticate(authenticate, self.request_id) 86 | 87 | def OnRspAuthenticate(self, pRspAuthenticateField, pRspInfo, nRequestID, bIsLast): 88 | 89 | print("OnRspAuthenticate") 90 | print("pRspInfo:", pRspInfo) 91 | print("nRequestID:", nRequestID) 92 | print("bIsLast:", bIsLast) 93 | 94 | if pRspInfo.ErrorID == 0: 95 | req = ApiStructure.ReqUserLoginField(BrokerID=self.broker_id, 96 | UserID=self.investor_id, 97 | Password=self.password) 98 | self.ReqUserLogin(req, self.request_id) 99 | else: 100 | print("auth failed") 101 | 102 | def OnRspUserLogin(self, pRspUserLogin, pRspInfo, nRequestID, bIsLast): 103 | print("OnRspUserLogin") 104 | print("nRequestID:", nRequestID) 105 | print("bIsLast:", bIsLast) 106 | print("pRspInfo:", pRspInfo) 107 | 108 | if pRspInfo.ErrorID != 0: 109 | print("RspInfo:", pRspInfo) 110 | else: 111 | print("trader user login successfully") 112 | self.login = True 113 | print("pRspUserLogin:", pRspUserLogin) 114 | 115 | def OnRspSettlementInfoConfirm(self, pSettlementInfoConfirm, pRspInfo, nRequestID, bIsLast): 116 | """ 117 | """ 118 | print("OnRspSettlementInfoConfirm") 119 | print("nRequestID:", nRequestID) 120 | print("bIsLast:", bIsLast) 121 | print("pRspInfo:", pRspInfo) 122 | 123 | print(pSettlementInfoConfirm) 124 | 125 | def OnRspQryInvestor(self, pInvestor, pRspInfo, nRequestID, bIsLast): 126 | """ 127 | """ 128 | print("OnRspQryInvestor") 129 | print("nRequestID:", nRequestID) 130 | print("bIsLast:", bIsLast) 131 | print("pRspInfo:", pRspInfo) 132 | print("pInvestor:", pInvestor) 133 | 134 | def OnRspQryInvestorPosition(self, pInvestorPosition, pRspInfo, nRequestID, bIsLast): 135 | print("OnRspQryInvestorPosition") 136 | print("nRequestID:", nRequestID) 137 | print("bIsLast:", bIsLast) 138 | print("pRspInfo:", pRspInfo) 139 | print("pInvestorPosition:", pInvestorPosition) 140 | 141 | def OnRspQryTradingAccount(self, pTradingAccount, pRspInfo, nRequestID, bIsLast): 142 | print("OnRspQryTradingAccount") 143 | print("nRequestID:", nRequestID) 144 | print("bIsLast:", bIsLast) 145 | print("pRspInfo:", pRspInfo) 146 | print("pTradingAccount:", pTradingAccount) 147 | 148 | 149 | def main(): 150 | json_file = open("config.json") 151 | config = json.load(json_file) 152 | json_file.close() 153 | 154 | print(config) 155 | 156 | investor_id = config["investor_id"] 157 | broker_id = config["broker_id"] 158 | password = config["password"] 159 | server = config["trader_server"] 160 | app_id = config["app_id"] 161 | auth_code = config["auth_code"] 162 | 163 | if check_address_port(server): 164 | 165 | user_trader = Trader(broker_id=broker_id, app_id=app_id, auth_code=auth_code, 166 | investor_id=investor_id, password=password) 167 | 168 | user_trader.Create() 169 | user_trader.RegisterFront(server) 170 | user_trader.SubscribePrivateTopic(2) # 只传送登录后的流内容 171 | 172 | user_trader.Init() 173 | 174 | print("trader api started") 175 | print("trading day:", user_trader.GetTradingDay()) 176 | 177 | if user_trader.login: 178 | investor = ApiStructure.QryInvestorField(broker_id, investor_id) 179 | 180 | user_trader.ReqQryInvestor(investor, user_trader.request_id) 181 | 182 | # position = ApiStructure.QryInvestorPositionField.from_dict({"BrokerID": broker_id, 183 | # "InvestorID": investor_id}) 184 | # user_trader.ReqQryInvestorPosition(position, user_trader.request_id) 185 | 186 | settlement_info = ApiStructure.SettlementInfoConfirmField.from_dict({"BrokerID": broker_id, 187 | "InvestorID": investor_id}) 188 | 189 | user_trader.ReqSettlementInfoConfirm(settlement_info, user_trader.request_id) 190 | 191 | trader_account = ApiStructure.QryTradingAccountField(BrokerID=broker_id, InvestorID=investor_id, BizType="1") 192 | user_trader.ReqQryTradingAccount(trader_account, user_trader.request_id) 193 | 194 | user_trader.Join() 195 | 196 | else: 197 | print("trader server down") 198 | 199 | 200 | if __name__ == "__main__": 201 | main() 202 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | requires_dist = cython 3 | 4 | [wheel] 5 | universal = 1 -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | import codecs 3 | import os 4 | import platform 5 | import re 6 | import shutil 7 | import sys 8 | from distutils.dir_util import copy_tree 9 | from setuptools import setup 10 | 11 | from Cython.Build import cythonize, build_ext 12 | from Cython.Distutils import Extension as Cython_Extension 13 | 14 | 15 | # issue put in the cython library bellow will cause 16 | # error: each element of 'ext_modules' option must be an Extension instance or 2-tuple 17 | 18 | 19 | def find_version(*file_paths): 20 | """ 21 | Don't pull version by importing package as it will be broken due to as-yet uninstalled 22 | dependencies, following recommendations at https://packaging.python.org/single_source_version, 23 | extract directly from the init file 24 | """ 25 | here = os.path.abspath(os.path.dirname(__file__)) 26 | with codecs.open(os.path.join(here, *file_paths), 'r', encoding="utf-8") as f: 27 | version_file = f.read() 28 | 29 | # The version line must have the form 30 | # __version__ = 'ver' 31 | version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", 32 | version_file, re.M) 33 | if version_match: 34 | return version_match.group(1) 35 | raise RuntimeError("Unable to find version string.") 36 | 37 | 38 | if platform.architecture()[0] != "64bit": 39 | raise EnvironmentError("Please install Python x86-64") 40 | 41 | base_dir = os.path.dirname(os.path.abspath(__file__)) 42 | project_dir = os.path.join(base_dir, "ctpwrapper") 43 | ctp_dir = os.path.join(base_dir, "ctp") 44 | cython_headers = os.path.join(project_dir, "headers") 45 | header_dir = os.path.join(ctp_dir, "header") 46 | cpp_header_dir = os.path.join(project_dir, "cppheader") 47 | 48 | lib_dir = None 49 | package_data = ["*.xml", "*.dtd"] 50 | extra_link_args = None 51 | extra_compile_args = None 52 | 53 | if sys.platform == "linux": 54 | lib_dir = os.path.join(ctp_dir, "linux") 55 | package_data.append("*.so") 56 | extra_compile_args = ["-Wall"] 57 | extra_link_args = ['-Wl,-rpath,$ORIGIN'] 58 | 59 | elif sys.platform == "win32": 60 | lib_dir = os.path.join(ctp_dir, "win") 61 | extra_compile_args = ["/GR", "/EHsc"] 62 | # extra_link_args = [] 63 | package_data.append("*.dll") 64 | 65 | package_data.append("error.dtd") 66 | package_data.append("error.xml") 67 | shutil.copy2(header_dir + "/error.dtd", project_dir + "/error.dtd") 68 | shutil.copy2(header_dir + "/error.xml", project_dir + "/error.xml") 69 | 70 | if sys.platform in ["linux", "win32"]: 71 | copy_tree(lib_dir, project_dir) 72 | 73 | common_args = { 74 | "cython_include_dirs": [cython_headers], 75 | "include_dirs": [header_dir, cpp_header_dir], 76 | "library_dirs": [lib_dir], 77 | "language": "c++", 78 | "extra_compile_args": extra_compile_args, 79 | "extra_link_args": extra_link_args, 80 | } 81 | 82 | ext_modules = [ 83 | Cython_Extension(name="ctpwrapper.MdApi", 84 | sources=["ctpwrapper/MdApi.pyx"], 85 | libraries=["thostmduserapi_se"], 86 | **common_args), 87 | Cython_Extension(name="ctpwrapper.TraderApi", 88 | sources=["ctpwrapper/TraderApi.pyx"], 89 | libraries=["thosttraderapi_se"], 90 | **common_args), 91 | Cython_Extension(name="ctpwrapper.datacollect", 92 | sources=["ctpwrapper/datacollect.pyx"], 93 | libraries=["LinuxDataCollect"] if sys.platform == "linux" else ["WinDataCollect"], 94 | **common_args) 95 | ] 96 | 97 | setup( 98 | name="ctpwrapper", 99 | version=find_version("ctpwrapper", "__init__.py"), 100 | description="CTP client v6.7.9", 101 | long_description=codecs.open("README.md", encoding="utf-8").read(), 102 | long_description_content_type='text/markdown', 103 | license="LGPLv3", 104 | keywords="CTP,Future,SHFE,Shanghai Future Exchange", 105 | author="Winton Wang", 106 | author_email="365504029@qq.com", 107 | url="https://github.com/nooperpudd/ctpwrapper", 108 | include_dirs=[header_dir, cpp_header_dir], 109 | platforms=["win32", "linux"], 110 | packages=["ctpwrapper"], 111 | package_data={"": package_data}, 112 | python_requires=">=3.9", 113 | # cython: binding=True 114 | # binding = true for inspect get callargs 115 | ext_modules=cythonize(ext_modules, 116 | compiler_directives={'language_level': 3, 117 | "binding": True} 118 | ), 119 | cmdclass={'build_ext': build_ext}, 120 | classifiers=[ 121 | "Development Status :: 5 - Production/Stable", 122 | "Intended Audience :: Developers", 123 | "Operating System :: POSIX", 124 | "Operating System :: Microsoft", 125 | "Operating System :: Microsoft :: Windows", 126 | "Programming Language :: Python", 127 | "Programming Language :: Python :: 3", 128 | "Programming Language :: Python :: 3 :: Only", 129 | "Programming Language :: Python :: 3.9", 130 | "Programming Language :: Python :: 3.10", 131 | "Programming Language :: Python :: 3.11", 132 | "Programming Language :: Python :: 3.12", 133 | "Programming Language :: Python :: 3.13", 134 | "Programming Language :: Python :: Implementation", 135 | "Programming Language :: Python :: Implementation :: CPython", 136 | "Programming Language :: Python :: Implementation :: PyPy", 137 | "Topic :: Software Development", 138 | "Topic :: Software Development :: Libraries" 139 | ] 140 | ) 141 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | (Copyright) 2018, Winton Wang <365504029@qq.com> 3 | 4 | ctpwrapper is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU LGPLv3 as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ctpwrapper. If not, see . 16 | 17 | """ 18 | -------------------------------------------------------------------------------- /tests/server_check.py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | """ 3 | (Copyright) 2018, Winton Wang <365504029@qq.com> 4 | 5 | ctpwrapper is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU LGPLv3 as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with ctpwrapper. If not, see . 17 | 18 | """ 19 | 20 | 21 | import socket 22 | import urllib.parse 23 | from contextlib import closing 24 | 25 | 26 | def check_address_port(tcp): 27 | """ 28 | :param tcp: 29 | :return: 30 | """ 31 | host_schema = urllib.parse.urlparse(tcp) 32 | 33 | ip = host_schema.hostname 34 | port = host_schema.port 35 | 36 | with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock: 37 | if sock.connect_ex((ip, port)) == 0: 38 | return True # OPEN 39 | else: 40 | return False # closed 41 | -------------------------------------------------------------------------------- /tests/test_api.py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | """ 3 | (Copyright) 2018, Winton Wang <365504029@qq.com> 4 | 5 | ctpwrapper is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU LGPLv3 as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with ctpwrapper. If not, see . 17 | 18 | """ 19 | 20 | import unittest 21 | 22 | from ctpwrapper import TraderApiPy, MdApiPy 23 | 24 | 25 | class ApiTest(unittest.TestCase): 26 | def test_md_version(self): 27 | print(MdApiPy.GetApiVersion()) 28 | 29 | def test_trader_version(self): 30 | print(TraderApiPy.GetApiVersion()) 31 | -------------------------------------------------------------------------------- /tests/test_datacollect.py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | """ 3 | (Copyright) 2018, Winton Wang <365504029@qq.com> 4 | 5 | ctpwrapper is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU LGPLv3 as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with ctpwrapper. If not, see . 17 | 18 | """ 19 | import unittest 20 | 21 | 22 | from ctpwrapper import datacollect 23 | 24 | 25 | class DataCollectTest(unittest.TestCase): 26 | def test_data_collect_api(self): 27 | def test_get_collect_version(self): 28 | print(datacollect.GetDataCollectApiVersion()) 29 | -------------------------------------------------------------------------------- /tests/test_structure.py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | """ 3 | (Copyright) 2018, Winton Wang <365504029@qq.com> 4 | 5 | ctpwrapper is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU LGPLv3 as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with ctpwrapper. If not, see . 17 | 18 | """ 19 | 20 | import unittest 21 | 22 | from ctpwrapper import ApiStructure 23 | 24 | 25 | class TestStructure(unittest.TestCase): 26 | # ('BrokerID', ctypes.c_char * 11), 27 | # ('FromCurrencyID', ctypes.c_char * 4), 28 | # ('FromCurrencyUnit', ctypes.c_double), 29 | # ('ToCurrencyID', ctypes.c_char * 4), 30 | # ('ExchangeRate', ctypes.c_double), 31 | 32 | def test_to_dict(self): 33 | result = { 34 | "BrokerID": "45544", 35 | "FromCurrencyID": "4343", 36 | "FromCurrencyUnit": 19.0, 37 | "ToCurrencyID": "4334", 38 | "ExchangeRate": 11.0 39 | } 40 | field = ApiStructure.ExchangeRateField( 41 | BrokerID="45544", 42 | FromCurrencyID="4343", 43 | FromCurrencyUnit=19.0, 44 | ToCurrencyID="4334", 45 | ExchangeRate=11.0 46 | ) 47 | result_dict = field.to_dict() 48 | self.assertDictEqual(result, result_dict) 49 | 50 | def test_from_dict(self): 51 | result = { 52 | "BrokerID": "45544", 53 | "FromCurrencyID": "4343", 54 | "FromCurrencyUnit": 19.0, 55 | "ToCurrencyID": "4334", 56 | "ExchangeRate": 11.0 57 | } 58 | field = ApiStructure.ExchangeRateField.from_dict(result) 59 | 60 | self.assertEqual(field.BrokerID, "45544") 61 | self.assertEqual(field.FromCurrencyID, "4343") 62 | self.assertEqual(field.FromCurrencyUnit, 19.0) 63 | self.assertEqual(field.ToCurrencyID, "4334") 64 | self.assertEqual(field.ExchangeRate, 11.0) 65 | 66 | def test_struct_missing_parameter(self): 67 | result = { 68 | "BrokerID": "45544", 69 | "FromCurrencyID": "", 70 | "FromCurrencyUnit": 0.0, 71 | "ToCurrencyID": "4334", 72 | "ExchangeRate": 11.0 73 | } 74 | 75 | field = ApiStructure.ExchangeRateField( 76 | BrokerID="45544", 77 | ToCurrencyID="4334", 78 | ExchangeRate=11.0 79 | ) 80 | result_dict = field.to_dict() 81 | self.assertDictEqual(result_dict, result) 82 | 83 | def test_dict_missing_parameter(self): 84 | result = { 85 | "BrokerID": "45544", 86 | 87 | "ToCurrencyID": "4334", 88 | "ExchangeRate": 11.0 89 | } 90 | field = ApiStructure.ExchangeRateField.from_dict(result) 91 | 92 | self.assertEqual(field.BrokerID, "45544") 93 | self.assertEqual(field.FromCurrencyID, "") 94 | self.assertEqual(field.FromCurrencyUnit, 0.0) 95 | self.assertEqual(field.ToCurrencyID, "4334") 96 | self.assertEqual(field.ExchangeRate, 11.0) 97 | --------------------------------------------------------------------------------