├── .gitignore ├── CTP_CPP_Note ├── CTP_CPP_Note.sln ├── CTP_CPP_Note │ ├── CTP_CPP_Note.cpp │ ├── CTP_CPP_Note.vcxproj │ ├── CTP_CPP_Note.vcxproj.filters │ ├── Config.h │ ├── Instrument.h │ ├── LockingQueue.h │ ├── Macro.h │ ├── MacroDefine.h │ ├── MarketApi.cpp │ ├── MarketApi.h │ ├── Order.h │ ├── TradeApi.cpp │ ├── TradeApi.h │ └── cpp.hint ├── MarketApi │ ├── MarketApi.vcxproj │ ├── MarketApi.vcxproj.filters │ ├── dllmain.cpp │ ├── framework.h │ ├── pch.cpp │ └── pch.h ├── TradeApi │ ├── TradeApi.vcxproj │ ├── TradeApi.vcxproj.filters │ ├── dllmain.cpp │ ├── framework.h │ ├── pch.cpp │ └── pch.h ├── ctp_api_simnow │ ├── ThostFtdcMdApi.h │ ├── ThostFtdcTraderApi.h │ ├── ThostFtdcUserApiDataType.h │ ├── ThostFtdcUserApiStruct.h │ ├── config.txt │ ├── error.dtd │ ├── error.xml │ ├── thostmduserapi_se.dll │ ├── thostmduserapi_se.lib │ ├── thosttraderapi_se.dll │ ├── thosttraderapi_se.lib │ └── 版本信息.txt └── pythonScript │ ├── check_TCP_connect.bat │ └── tcp_connect.py ├── Docs ├── 6.5.1_API接口说明.chm ├── 6.5.1_API接口说明.chw ├── CTP客户端开发指南 V3.5-中文.pdf ├── dima-boost-intro.pdf ├── dima-ql-intro-1.pdf └── dima-ql-intro-2.pdf ├── LICENSE ├── README.md └── Scripts ├── ReadMe.txt ├── check_TCP_connect.bat ├── tcp_connect.py └── tcp_connect.zip /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | build/ 19 | install/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | 26 | # Visual Studio 2015 cache/options directory 27 | .vs/ 28 | # Uncomment if you have tasks that create the project's static files in wwwroot 29 | #wwwroot/ 30 | 31 | # MSTest test Results 32 | [Tt]est[Rr]esult*/ 33 | [Bb]uild[Ll]og.* 34 | 35 | # NUNIT 36 | *.VisualState.xml 37 | TestResult.xml 38 | 39 | # Build Results of an ATL Project 40 | [Dd]ebugPS/ 41 | [Rr]eleasePS/ 42 | dlldata.c 43 | 44 | # DNX 45 | project.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | # TODO: Comment the next line if you want to checkin your web deploy settings 143 | # but database connection strings (with potential passwords) will be unencrypted 144 | *.pubxml 145 | *.publishproj 146 | 147 | # NuGet Packages 148 | *.nupkg 149 | # The packages folder can be ignored because of Package Restore 150 | **/packages/* 151 | # except build/, which is used as an MSBuild target. 152 | !**/packages/build/ 153 | # Uncomment if necessary however generally it will be regenerated when needed 154 | #!**/packages/repositories.config 155 | # NuGet v3's project.json files produces more ignoreable files 156 | *.nuget.props 157 | *.nuget.targets 158 | 159 | # Microsoft Azure Build Output 160 | csx/ 161 | *.build.csdef 162 | 163 | # Microsoft Azure Emulator 164 | ecf/ 165 | rcf/ 166 | 167 | # Microsoft Azure ApplicationInsights config file 168 | ApplicationInsights.config 169 | 170 | # Windows Store app package directory 171 | AppPackages/ 172 | BundleArtifacts/ 173 | 174 | # Visual Studio cache files 175 | # files ending in .cache can be ignored 176 | *.[Cc]ache 177 | # but keep track of directories ending in .cache 178 | !*.[Cc]ache/ 179 | 180 | # Others 181 | ClientBin/ 182 | ~$* 183 | *~ 184 | *.dbmdl 185 | *.dbproj.schemaview 186 | *.pfx 187 | *.publishsettings 188 | node_modules/ 189 | orleans.codegen.cs 190 | *.con 191 | 192 | # RIA/Silverlight projects 193 | Generated_Code/ 194 | 195 | # Backup & report files from converting an old project file 196 | # to a newer Visual Studio version. Backup files are not needed, 197 | # because we have git ;-) 198 | _UpgradeReport_Files/ 199 | Backup*/ 200 | UpgradeLog*.XML 201 | UpgradeLog*.htm 202 | 203 | # SQL Server files 204 | *.mdf 205 | *.ldf 206 | 207 | # Business Intelligence projects 208 | *.rdl.data 209 | *.bim.layout 210 | *.bim_*.settings 211 | 212 | # Microsoft Fakes 213 | FakesAssemblies/ 214 | 215 | # GhostDoc plugin setting file 216 | *.GhostDoc.xml 217 | 218 | # Node.js Tools for Visual Studio 219 | .ntvs_analysis.dat 220 | 221 | # Visual Studio 6 build log 222 | *.plg 223 | 224 | # Visual Studio 6 workspace options file 225 | *.opt 226 | 227 | # Visual Studio LightSwitch build output 228 | **/*.HTMLClient/GeneratedArtifacts 229 | **/*.DesktopClient/GeneratedArtifacts 230 | **/*.DesktopClient/ModelManifest.xml 231 | **/*.Server/GeneratedArtifacts 232 | **/*.Server/ModelManifest.xml 233 | _Pvt_Extensions 234 | 235 | # Paket dependency manager 236 | .paket/paket.exe 237 | 238 | # FAKE - F# Make 239 | .fake/ 240 | 241 | 242 | /CTP_CPP_Note/boost_1_80_0/* -------------------------------------------------------------------------------- /CTP_CPP_Note/CTP_CPP_Note.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33723.286 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CTP_CPP_Note", "CTP_CPP_Note\CTP_CPP_Note.vcxproj", "{44D707FD-52BD-4E1C-87B7-D994EF456363}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {44D707FD-52BD-4E1C-87B7-D994EF456363}.Debug|x64.ActiveCfg = Debug|x64 17 | {44D707FD-52BD-4E1C-87B7-D994EF456363}.Debug|x64.Build.0 = Debug|x64 18 | {44D707FD-52BD-4E1C-87B7-D994EF456363}.Debug|x86.ActiveCfg = Debug|Win32 19 | {44D707FD-52BD-4E1C-87B7-D994EF456363}.Debug|x86.Build.0 = Debug|Win32 20 | {44D707FD-52BD-4E1C-87B7-D994EF456363}.Release|x64.ActiveCfg = Release|x64 21 | {44D707FD-52BD-4E1C-87B7-D994EF456363}.Release|x64.Build.0 = Release|x64 22 | {44D707FD-52BD-4E1C-87B7-D994EF456363}.Release|x86.ActiveCfg = Release|Win32 23 | {44D707FD-52BD-4E1C-87B7-D994EF456363}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {3990FE55-EFB2-466B-AC9B-700AA00EF550} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /CTP_CPP_Note/CTP_CPP_Note/CTP_CPP_Note.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "Config.h" 6 | #include "MarketApi.h" 7 | #include "TradeApi.h" 8 | 9 | 10 | int main() { 11 | std::string input; 12 | 13 | 14 | auto tradeApi = TradeProxy::TradeApi::instance(); 15 | tradeApi->start(); 16 | 17 | 18 | std::this_thread::sleep_for(std::chrono::milliseconds(2000)); 19 | tradeApi->reqQryInstrument(Config::CFFEX); 20 | //std::this_thread::sleep_for(std::chrono::milliseconds(4000)); 21 | //tradeApi->reqQryInstrument(Config::CZCE); 22 | //std::this_thread::sleep_for(std::chrono::milliseconds(4000)); 23 | //tradeApi->reqQryInstrument(Config::DCE); 24 | //std::this_thread::sleep_for(std::chrono::milliseconds(4000)); 25 | //tradeApi->reqQryInstrument(Config::INE); 26 | //std::this_thread::sleep_for(std::chrono::milliseconds(4000)); 27 | //tradeApi->reqQryInstrument(Config::SHFE); 28 | 29 | auto marketApi = new MarketProxy::MarketApi(); 30 | 31 | 32 | std::this_thread::sleep_for(std::chrono::milliseconds(4000)); 33 | 34 | 35 | 36 | std::vector allConstracts = TradeProxy::ReferenceData::getContracts(); 37 | const int numb = allConstracts.size(); 38 | for (int i = 0; i < numb; ++i) 39 | { 40 | marketApi->subscribeMarketData(allConstracts[i]); 41 | } 42 | 43 | std::string instrumentId = "MO2401-P-5400"; 44 | char side = '0'; 45 | double price = 10.1; 46 | int size = 20; 47 | std::cin >> input; 48 | tradeApi->sendFakOrder(instrumentId, side, price, size); 49 | std::cin >> input; 50 | tradeApi->sendFokOrder(instrumentId, side, price, size); 51 | std::cin >> input; 52 | 53 | 54 | 55 | 56 | 57 | /*marketApi->subscribeMarketData("IO2403-P-3600");*/ 58 | 59 | std::cin >> input; 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /CTP_CPP_Note/CTP_CPP_Note/CTP_CPP_Note.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {44d707fd-52bd-4e1c-87b7-d994ef456363} 25 | CTPCPPNote 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | ..\install\$(Platform)_$(Configuration)\ 75 | 76 | 77 | ..\install\$(Platform)_$(Configuration)\ 78 | 79 | 80 | 81 | Level3 82 | true 83 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 84 | true 85 | 86 | 87 | Console 88 | true 89 | 90 | 91 | 92 | 93 | Level3 94 | true 95 | true 96 | true 97 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 98 | true 99 | 100 | 101 | Console 102 | true 103 | true 104 | true 105 | 106 | 107 | 108 | 109 | Level3 110 | true 111 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 112 | true 113 | ..\ctp_api_simnow;..\boost_1_80_0\boost_1_80_0;%(AdditionalIncludeDirectories) 114 | stdcpp17 115 | 116 | 117 | Console 118 | true 119 | ..\ctp_api_simnow;..\boost_1_80_0\boost_1_80_0;%(AdditionalLibraryDirectories) 120 | thostmduserapi_se.lib;thosttraderapi_se.lib;%(AdditionalDependencies) 121 | 122 | 123 | 124 | 125 | Level3 126 | true 127 | true 128 | true 129 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 130 | true 131 | ..\ctp_api_simnow;%(AdditionalIncludeDirectories) 132 | stdcpp17 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | ..\ctp_api_simnow;%(AdditionalLibraryDirectories) 140 | thostmduserapi_se.lib;thosttraderapi_se.lib;%(AdditionalDependencies) 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /CTP_CPP_Note/CTP_CPP_Note/CTP_CPP_Note.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | 29 | 30 | Source Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | Header Files 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /CTP_CPP_Note/CTP_CPP_Note/Config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Config { 5 | 6 | // trade config 7 | static std::string TRADE_FLOW = "\\flow\\"; 8 | static std::string TRADE_FROND_ADDRESS = "tcp://180.168.146.187:10130"; 9 | static std::string BROKER_ID = "9999"; 10 | static std::string USER_ID = "207925"; 11 | static std::string USER_PRODUCT_INFO = "ATrader"; 12 | static std::string AUTH_CODE = "0000000000000000"; 13 | static std::string APP_ID = "simnow_client_test"; 14 | static std::string PASSWORD = "Paic@1234"; 15 | static std::string CFFEX = "CFFEX"; 16 | static std::string CZCE = "CZCE"; 17 | static std::string DCE = "DCE"; 18 | static std::string INE = "INE"; 19 | static std::string SHFE = "SHFE"; 20 | 21 | // market config 22 | static std::string MARKET_FROND_ADDRESS = "tcp://180.168.146.187:10131"; 23 | 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /CTP_CPP_Note/CTP_CPP_Note/Instrument.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/CTP_CPP_Note/CTP_CPP_Note/Instrument.h -------------------------------------------------------------------------------- /CTP_CPP_Note/CTP_CPP_Note/LockingQueue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | template 7 | class LockingQueue 8 | { 9 | public: 10 | void push(T const& _data) 11 | { 12 | { 13 | std::lock_guard lock(guard); 14 | queue.push(_data); 15 | } 16 | signal.notify_one(); 17 | } 18 | 19 | bool empty() const 20 | { 21 | std::lock_guard lock(guard); 22 | return queue.empty(); 23 | } 24 | 25 | bool tryPop(T& _value) 26 | { 27 | std::lock_guard lock(guard); 28 | if (queue.empty()) 29 | { 30 | return false; 31 | } 32 | 33 | _value = queue.front(); 34 | queue.pop(); 35 | return true; 36 | } 37 | 38 | void waitAndPop(T& _value) 39 | { 40 | std::unique_lock lock(guard); 41 | while (queue.empty()) 42 | { 43 | signal.wait(lock); 44 | } 45 | 46 | _value = queue.front(); 47 | queue.pop(); 48 | } 49 | 50 | bool tryWaitAndPop(T& _value, int _milli) 51 | { 52 | std::unique_lock lock(guard); 53 | while (queue.empty()) 54 | { 55 | signal.wait_for(lock, std::chrono::milliseconds(_milli)); 56 | return false; 57 | } 58 | 59 | _value = queue.front(); 60 | queue.pop(); 61 | return true; 62 | } 63 | 64 | private: 65 | std::queue queue; 66 | mutable std::mutex guard; 67 | std::condition_variable signal; 68 | }; -------------------------------------------------------------------------------- /CTP_CPP_Note/CTP_CPP_Note/Macro.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #define SHARED_PTR(NAME) \ 5 | using NAME ## Ptr = std::shared_ptr< NAME >; \ 6 | using NAME ## ConstPtr = std::shared_ptr< const NAME >; 7 | 8 | 9 | -------------------------------------------------------------------------------- /CTP_CPP_Note/CTP_CPP_Note/MacroDefine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #define SHARED_PTR(NAME) \ 5 | using NAME ## Ptr = std::shared_ptr< NAME >; \ 6 | using NAME ## ConstPtr = std::shared_ptr< const NAME >; 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /CTP_CPP_Note/CTP_CPP_Note/MarketApi.cpp: -------------------------------------------------------------------------------- 1 | #include "MarketApi.h" 2 | 3 | #include 4 | #include 5 | #include "Config.h" 6 | #include "Instrument.h" 7 | 8 | namespace MarketProxy 9 | { 10 | namespace 11 | { 12 | static int MarketProxyRequestId = 0; 13 | 14 | } 15 | 16 | MarketApi::MarketApi() 17 | { 18 | auto currentPath = std::filesystem::current_path(); 19 | currentPath += Config::TRADE_FLOW; 20 | auto flowPath = std::filesystem::create_directories(currentPath); 21 | ctpMdApi_ = CThostFtdcMdApi::CreateFtdcMdApi(currentPath.string().c_str()); 22 | ctpMdApi_->RegisterSpi(this); 23 | ctpMdApi_->RegisterFront(const_cast(Config::MARKET_FROND_ADDRESS.c_str())); 24 | ctpMdApi_->Init(); 25 | } 26 | 27 | void MarketApi::OnFrontConnected() 28 | { 29 | std::cout << __FUNCTION__ << std::endl; 30 | std::cout << "Market api connected successfully" << std::endl; 31 | 32 | CThostFtdcReqUserLoginField requestLogin = CThostFtdcReqUserLoginField(); 33 | memset(&requestLogin, 0, sizeof(requestLogin)); 34 | strcpy_s(requestLogin.BrokerID, Config::BROKER_ID.c_str()); 35 | strcpy_s(requestLogin.UserID, Config::USER_ID.c_str()); 36 | strcpy_s(requestLogin.Password, Config::PASSWORD.c_str()); 37 | int reqResult = ctpMdApi_->ReqUserLogin(&requestLogin, ++MarketProxyRequestId); 38 | if (reqResult != 0) 39 | std::cout << __FUNCTION__ << "|response: " << reqResult << std::endl; 40 | else 41 | std::cout << __FUNCTION__ << "|response: " << reqResult << std::endl; 42 | } 43 | 44 | void MarketApi::OnRspUserLogin(CThostFtdcRspUserLoginField* pRspUserLogin, CThostFtdcRspInfoField* pRspInfo, 45 | int nRequestID, bool bIsLast) 46 | { 47 | std::cout << __FUNCTION__ << std::endl; 48 | if (pRspInfo != nullptr && pRspInfo->ErrorID != 0) 49 | { 50 | std::cout << "pRspInfo@" __FUNCTION__ "|ErrorID: " << pRspInfo->ErrorID << "|ErrorMsg: " << pRspInfo-> 51 | ErrorMsg; 52 | } 53 | else 54 | { 55 | std::cout << __FUNCTION__ << "|Login success, LoginTime: " << pRspUserLogin->LoginTime << "|BrokerID: " << 56 | pRspUserLogin->BrokerID 57 | << "|UserID: " << pRspUserLogin->UserID; 58 | } 59 | } 60 | std::string instType(std::string instrumentId) 61 | { 62 | if (instrumentId.find("-c-") || instrumentId.find("-p-")) 63 | return "opt"; 64 | else 65 | return "underlying"; 66 | } 67 | void MarketApi::OnRtnDepthMarketData(CThostFtdcDepthMarketDataField* pDepthMarketData) 68 | { 69 | std::cout << pDepthMarketData->InstrumentID << " Bid: " << pDepthMarketData->BidPrice1 70 | << " " << pDepthMarketData->BidVolume1 << " Ask: " << pDepthMarketData->AskPrice1 71 | << " Bid: " << pDepthMarketData->AskVolume1 << std::endl; 72 | 73 | //Instrument* instPtrTem = new Instrument(); 74 | //instPtrTem->exchangeId(pDepthMarketData->ExchangeID); 75 | 76 | 77 | InstrumentPtr instPtr= std::make_shared(); 78 | instPtr->exchangeId(pDepthMarketData->ExchangeID); 79 | instPtr->instrumentName(pDepthMarketData->InstrumentID); 80 | instPtr->productClass(instType(pDepthMarketData->ExchangeID)); 81 | instPtr->exchangeId(pDepthMarketData->ExchangeID); 82 | //delete instPtrTem 83 | } 84 | void MarketApi::OnRspSubMarketData(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) 85 | { 86 | if (true) {} 87 | } 88 | void MarketApi::subscribeMarketData(const std::string& instrumendId) 89 | { 90 | char* buffer = (char*)instrumendId.c_str(); 91 | char* myreq[1] = { buffer }; 92 | int reqResult = ctpMdApi_->SubscribeMarketData(myreq, 1); 93 | 94 | if (reqResult != 0) 95 | std::cout << __FUNCTION__ << "|response: " << reqResult << std::endl; 96 | else 97 | std::cout << __FUNCTION__ << "|response: " << reqResult << std::endl; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /CTP_CPP_Note/CTP_CPP_Note/MarketApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/CTP_CPP_Note/CTP_CPP_Note/MarketApi.h -------------------------------------------------------------------------------- /CTP_CPP_Note/CTP_CPP_Note/Order.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Macro.h" 4 | 5 | class Order 6 | { 7 | public: 8 | void setPrice(double price_) 9 | { 10 | price = price_; 11 | } 12 | 13 | void setSize(int size_) 14 | { 15 | size = size_; 16 | } 17 | 18 | void setOrderStatus(std::string orderStatus_) 19 | { 20 | orderStatus = orderStatus_; 21 | } 22 | 23 | double getPrice() 24 | { 25 | return price; 26 | } 27 | 28 | 29 | private: 30 | double price; 31 | int size; 32 | std::string orderStatus; 33 | 34 | }; 35 | SHARED_PTR(Order) -------------------------------------------------------------------------------- /CTP_CPP_Note/CTP_CPP_Note/TradeApi.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/CTP_CPP_Note/CTP_CPP_Note/TradeApi.cpp -------------------------------------------------------------------------------- /CTP_CPP_Note/CTP_CPP_Note/TradeApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/CTP_CPP_Note/CTP_CPP_Note/TradeApi.h -------------------------------------------------------------------------------- /CTP_CPP_Note/CTP_CPP_Note/cpp.hint: -------------------------------------------------------------------------------- 1 | // Hint files help the Visual Studio IDE interpret Visual C++ identifiers 2 | // such as names of functions and macros. 3 | // For more information see https://go.microsoft.com/fwlink/?linkid=865984 4 | #define SHARED_PTR(NAME) 5 | -------------------------------------------------------------------------------- /CTP_CPP_Note/MarketApi/MarketApi.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {d4b870bf-64f8-4395-8ca9-72d2fd09e0af} 25 | MarketApi 26 | 10.0 27 | 28 | 29 | 30 | DynamicLibrary 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | DynamicLibrary 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | DynamicLibrary 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | DynamicLibrary 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | Level3 76 | true 77 | WIN32;_DEBUG;MARKETAPI_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 78 | true 79 | Use 80 | pch.h 81 | 82 | 83 | Windows 84 | true 85 | false 86 | 87 | 88 | 89 | 90 | Level3 91 | true 92 | true 93 | true 94 | WIN32;NDEBUG;MARKETAPI_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 95 | true 96 | Use 97 | pch.h 98 | 99 | 100 | Windows 101 | true 102 | true 103 | true 104 | false 105 | 106 | 107 | 108 | 109 | Level3 110 | true 111 | _DEBUG;MARKETAPI_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 112 | true 113 | Use 114 | pch.h 115 | stdcpp17 116 | 117 | 118 | Windows 119 | true 120 | false 121 | 122 | 123 | 124 | 125 | Level3 126 | true 127 | true 128 | true 129 | NDEBUG;MARKETAPI_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 130 | true 131 | Use 132 | pch.h 133 | stdcpp17 134 | 135 | 136 | Windows 137 | true 138 | true 139 | true 140 | false 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | Create 151 | Create 152 | Create 153 | Create 154 | 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /CTP_CPP_Note/MarketApi/MarketApi.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | Source Files 31 | 32 | 33 | -------------------------------------------------------------------------------- /CTP_CPP_Note/MarketApi/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : Defines the entry point for the DLL application. 2 | #include "pch.h" 3 | 4 | BOOL APIENTRY DllMain( HMODULE hModule, 5 | DWORD ul_reason_for_call, 6 | LPVOID lpReserved 7 | ) 8 | { 9 | switch (ul_reason_for_call) 10 | { 11 | case DLL_PROCESS_ATTACH: 12 | case DLL_THREAD_ATTACH: 13 | case DLL_THREAD_DETACH: 14 | case DLL_PROCESS_DETACH: 15 | break; 16 | } 17 | return TRUE; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /CTP_CPP_Note/MarketApi/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 4 | // Windows Header Files 5 | #include 6 | -------------------------------------------------------------------------------- /CTP_CPP_Note/MarketApi/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: source file corresponding to the pre-compiled header 2 | 3 | #include "pch.h" 4 | 5 | // When you are using pre-compiled headers, this source file is necessary for compilation to succeed. 6 | -------------------------------------------------------------------------------- /CTP_CPP_Note/MarketApi/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: This is a precompiled header file. 2 | // Files listed below are compiled only once, improving build performance for future builds. 3 | // This also affects IntelliSense performance, including code completion and many code browsing features. 4 | // However, files listed here are ALL re-compiled if any one of them is updated between builds. 5 | // Do not add files here that you will be updating frequently as this negates the performance advantage. 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // add headers that you want to pre-compile here 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /CTP_CPP_Note/TradeApi/TradeApi.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {afc49cc2-4cc0-4b88-8a26-fb124dda41f7} 25 | TradeApi 26 | 10.0 27 | 28 | 29 | 30 | DynamicLibrary 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | DynamicLibrary 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | DynamicLibrary 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | DynamicLibrary 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | Level3 76 | true 77 | WIN32;_DEBUG;TRADEAPI_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 78 | true 79 | Use 80 | pch.h 81 | 82 | 83 | Windows 84 | true 85 | false 86 | 87 | 88 | 89 | 90 | Level3 91 | true 92 | true 93 | true 94 | WIN32;NDEBUG;TRADEAPI_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 95 | true 96 | Use 97 | pch.h 98 | 99 | 100 | Windows 101 | true 102 | true 103 | true 104 | false 105 | 106 | 107 | 108 | 109 | Level3 110 | true 111 | _DEBUG;TRADEAPI_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 112 | true 113 | Use 114 | pch.h 115 | stdcpp17 116 | ..\ctp_api_simnow; 117 | 118 | 119 | Windows 120 | true 121 | false 122 | ..\ctp_api_simnow; 123 | thostmduserapi_se.lib;thosttraderapi_se.lib;$(CoreLibraryDependencies);%(AdditionalDependencies) 124 | 125 | 126 | 127 | 128 | Level3 129 | true 130 | true 131 | true 132 | NDEBUG;TRADEAPI_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 133 | true 134 | Use 135 | pch.h 136 | stdcpp17 137 | ..\ctp_api_simnow; 138 | 139 | 140 | Windows 141 | true 142 | true 143 | true 144 | false 145 | ..\ctp_api_simnow; 146 | thostmduserapi_se.lib;thosttraderapi_se.lib;$(CoreLibraryDependencies);%(AdditionalDependencies) 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | Create 157 | Create 158 | Create 159 | Create 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /CTP_CPP_Note/TradeApi/TradeApi.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | Source Files 31 | 32 | 33 | -------------------------------------------------------------------------------- /CTP_CPP_Note/TradeApi/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : Defines the entry point for the DLL application. 2 | #include "pch.h" 3 | 4 | BOOL APIENTRY DllMain( HMODULE hModule, 5 | DWORD ul_reason_for_call, 6 | LPVOID lpReserved 7 | ) 8 | { 9 | switch (ul_reason_for_call) 10 | { 11 | case DLL_PROCESS_ATTACH: 12 | case DLL_THREAD_ATTACH: 13 | case DLL_THREAD_DETACH: 14 | case DLL_PROCESS_DETACH: 15 | break; 16 | } 17 | return TRUE; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /CTP_CPP_Note/TradeApi/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 4 | // Windows Header Files 5 | #include 6 | -------------------------------------------------------------------------------- /CTP_CPP_Note/TradeApi/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: source file corresponding to the pre-compiled header 2 | 3 | #include "pch.h" 4 | 5 | // When you are using pre-compiled headers, this source file is necessary for compilation to succeed. 6 | -------------------------------------------------------------------------------- /CTP_CPP_Note/TradeApi/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: This is a precompiled header file. 2 | // Files listed below are compiled only once, improving build performance for future builds. 3 | // This also affects IntelliSense performance, including code completion and many code browsing features. 4 | // However, files listed here are ALL re-compiled if any one of them is updated between builds. 5 | // Do not add files here that you will be updating frequently as this negates the performance advantage. 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // add headers that you want to pre-compile here 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /CTP_CPP_Note/ctp_api_simnow/ThostFtdcMdApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/CTP_CPP_Note/ctp_api_simnow/ThostFtdcMdApi.h -------------------------------------------------------------------------------- /CTP_CPP_Note/ctp_api_simnow/ThostFtdcTraderApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/CTP_CPP_Note/ctp_api_simnow/ThostFtdcTraderApi.h -------------------------------------------------------------------------------- /CTP_CPP_Note/ctp_api_simnow/ThostFtdcUserApiDataType.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/CTP_CPP_Note/ctp_api_simnow/ThostFtdcUserApiDataType.h -------------------------------------------------------------------------------- /CTP_CPP_Note/ctp_api_simnow/ThostFtdcUserApiStruct.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/CTP_CPP_Note/ctp_api_simnow/ThostFtdcUserApiStruct.h -------------------------------------------------------------------------------- /CTP_CPP_Note/ctp_api_simnow/config.txt: -------------------------------------------------------------------------------- 1 | 注册账号:177****9601 2 | 3 | 用户昵称:MR_Michael 4 | 5 | investorId:133640 6 | 7 | brokerId:9999 8 | 9 | 挂靠会员:SimNow 10 | 11 | Paic@906912 12 | 13 | 上期技术: 14 | https://www.simnow.com.cn/ 15 | 16 | CTP报单指令详解 17 | https://www.shinnytech.com/blog/ctp-insert-order-field/ 18 | 19 | 20 | -------------------------------------------------------------------------------- /CTP_CPP_Note/ctp_api_simnow/error.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /CTP_CPP_Note/ctp_api_simnow/error.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/CTP_CPP_Note/ctp_api_simnow/error.xml -------------------------------------------------------------------------------- /CTP_CPP_Note/ctp_api_simnow/thostmduserapi_se.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/CTP_CPP_Note/ctp_api_simnow/thostmduserapi_se.dll -------------------------------------------------------------------------------- /CTP_CPP_Note/ctp_api_simnow/thostmduserapi_se.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/CTP_CPP_Note/ctp_api_simnow/thostmduserapi_se.lib -------------------------------------------------------------------------------- /CTP_CPP_Note/ctp_api_simnow/thosttraderapi_se.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/CTP_CPP_Note/ctp_api_simnow/thosttraderapi_se.dll -------------------------------------------------------------------------------- /CTP_CPP_Note/ctp_api_simnow/thosttraderapi_se.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/CTP_CPP_Note/ctp_api_simnow/thosttraderapi_se.lib -------------------------------------------------------------------------------- /CTP_CPP_Note/ctp_api_simnow/版本信息.txt: -------------------------------------------------------------------------------- 1 | v6.6.1_P1_tradeapi.zip -------------------------------------------------------------------------------- /CTP_CPP_Note/pythonScript/check_TCP_connect.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | cd %~dp0 3 | python tcp_connect.py -------------------------------------------------------------------------------- /CTP_CPP_Note/pythonScript/tcp_connect.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sat Jun 17 15:33:54 2023 4 | 5 | @author: Administrator 6 | """ 7 | 8 | import socket 9 | import time 10 | 11 | def check_tcp_connection(host, port, msg): 12 | try: 13 | # 创建TCP套接字 14 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 15 | # 设置超时时间为3秒 16 | sock.settimeout(3) 17 | # 尝试连接 18 | result = sock.connect_ex((host, port)) 19 | if result == 0: 20 | print(msg + "TCP连接正常" ) 21 | else: 22 | print(msg + "TCP连接异常") 23 | # 关闭套接字 24 | sock.close() 25 | except socket.error as e: 26 | print(msg + "发生错误:", e) 27 | 28 | trade_host_msg = "checking simnow 7x24 trade host: " 29 | trade_host = "180.168.146.187" 30 | trade_port = 10130 31 | 32 | market_host_msg = "checking simnow 7x24 market host: " 33 | market_host = "180.168.146.187" 34 | market_port = 10131 35 | 36 | # 检查TCP连接 37 | while True: 38 | check_tcp_connection(trade_host, trade_port, trade_host_msg) 39 | check_tcp_connection(market_host, market_port, market_host_msg) 40 | time.sleep(5) -------------------------------------------------------------------------------- /Docs/6.5.1_API接口说明.chm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/Docs/6.5.1_API接口说明.chm -------------------------------------------------------------------------------- /Docs/6.5.1_API接口说明.chw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/Docs/6.5.1_API接口说明.chw -------------------------------------------------------------------------------- /Docs/CTP客户端开发指南 V3.5-中文.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/Docs/CTP客户端开发指南 V3.5-中文.pdf -------------------------------------------------------------------------------- /Docs/dima-boost-intro.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/Docs/dima-boost-intro.pdf -------------------------------------------------------------------------------- /Docs/dima-ql-intro-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/Docs/dima-ql-intro-1.pdf -------------------------------------------------------------------------------- /Docs/dima-ql-intro-2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/Docs/dima-ql-intro-2.pdf -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Michael 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CTP_DEV_NOTE 2 | 3 | CTP是目前国内高频量化交易重要的接口,通过期货公司开通CTP接口,可以连接国内四大期货交易所,进行期货和期权等金融衍生品的交易。 4 | 5 | ## 为什么要自己开发交易系统? 6 | 目前市场中,有很多的基于CTP二次开发的客户端,这些客户端大多数都是将CTP原始的接口封装成Python供大家使用,然而作为一名量化高频的开发人员,深知这其中的弊端,一是交易不能有黑盒子,大多数的国际投行,比如高盛,摩根,美林等,都有自己的交易系统,原因是实际交易过程中,如果遇到问题,那么交易员还是量化开发人员都需要知道整个交易决策的过程,这就需要对原始的交易逻辑和代码进行分析,如果是使用第三方的封装的软件,除非有源码提供,否则是无法实现的,其次,第三方的交易软件更新迭代比较慢,尤其是当交易需要有自己的个性化的功能时,很难达到自己的预期的效果。最后,实际的交易还是开发,知其然必知其所以然,如果只是用但不知道其中的原理,个人觉得并不是一种高明的思维,因此我坚持自己基于CTP原始的接口开发自己的高频量化交易系统。 7 | 8 | ## 开发交易系统难吗? 9 | 也许有一些人会觉得开发一个高频交易系统很难,这个问题也不能有一个明确的结论,我觉得量化交易系统可以分为几个部分:交易系统的架构,系统的实现以及交易的策略。首先架构上个人觉得大同小异,看了很多的交易系统的架构,比如火币,币安,QunantConnect等等,无论交易什么金融产品类型是什么,但是可以发现底层的架构大多的类似,比如分为:订单管理模块,策略引擎模块,持仓管理模块,行情模块,风控模块等,不用自己过多的设计,参考加优化即可。其次交易的实现,CTP原始的接口使用的C++,使用C++是顶尖投行交易的传统了,一直延续至今,毫无疑问C++确实是一门博大精深的语音,要想完全掌握成为一名C++的大神,并非一朝一夕的事情,但是如果开发一个金融类的高频交易系统可能并不需要成为一名顶级的C++的编程人员,学以致用也许才是准确的道路,从现有的交易系统来看,学会基本的编程知识加上面向对象编程,智能指针,多线程以及常见的几种程序设计模式的知识,我个人觉得是可以应付的过来的,这里可以参考一下quantnet上面的两门C++课程《C++ Programming for Financial Engineering》和《Advanced C++ and Modern Design》,学完这两门课程,应对编程应该问题不大。最后就是交易策略,这个是最重要的部分,就是将自己的交易思路转换为实际的代码,并且运用于实盘交易,这个因人而异,有好的策略也许就能从市场中获利,这也是交易我们做交易系统的目的。 10 | 11 | ## 如何建立自己的交易系统 12 | 有了架构图,C++编程基础加上自己还有策略时,便可以开始的CTP交易开发了,前期我每日每夜写了三个月代码,终于完成了自己的高频交易系统,目前还算稳定,因为之前自己摘CTP的开发过程中,走了不少的弯路,包括模拟环境,接口的调用,缺失行情的处理,回报信息字段的处理,因此我建立了这个代码库,并且开始自我归纳总结如何开发和开发过程中遇到的问题,一方面可以积累自己内在的储备,另外一方面,给后来开发者一些思路。 13 | 14 | ## 代码库哪些内容 15 | 主要包含如何使用CTP开发,包括行情和交易接口的连接,行情的订阅,订单回报和成交回报推送,不同订单类型的发送以及回报消息对象的解析;也许很多人认为交易策略是核心,个人也许并不认同这个观点,因为好的策略运用到实盘交易之间有着巨大的鸿沟,想法能真正实盘进行交易,并且避开各种坑,需要花费很大的很大的精力。因此这个代码库目前我想并不包含策略相关的内容。就如同战士上战场,这里只提供武器和弹药,但是具体的如何打战,运用的战术,需要大家自己思考。 16 | 17 | 更多的内容,大家可以关注我的微信公众账号:量化金融初学者 18 | -------------------------------------------------------------------------------- /Scripts/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 直接双击“check_TCP_connect.bat”脚本,检查Sinnow CTP环境是否接通 2 | -------------------------------------------------------------------------------- /Scripts/check_TCP_connect.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | cd %~dp0 3 | python tcp_connect.py -------------------------------------------------------------------------------- /Scripts/tcp_connect.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sat Jun 17 15:33:54 2023 4 | 5 | @author: Administrator 6 | """ 7 | 8 | import socket 9 | import time 10 | 11 | def check_tcp_connection(host, port, msg): 12 | try: 13 | # 创建TCP套接字 14 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 15 | # 设置超时时间为3秒 16 | sock.settimeout(3) 17 | # 尝试连接 18 | result = sock.connect_ex((host, port)) 19 | if result == 0: 20 | print(msg + "TCP连接正常" ) 21 | else: 22 | print(msg + "TCP连接异常") 23 | # 关闭套接字 24 | sock.close() 25 | except socket.error as e: 26 | print(msg + "发生错误:", e) 27 | 28 | trade_host_msg = "checking simnow 7x24 trade host: " 29 | trade_host = "180.168.146.187" 30 | trade_port = 10130 31 | 32 | market_host_msg = "checking simnow 7x24 market host: " 33 | market_host = "180.168.146.187" 34 | market_port = 10131 35 | 36 | # 检查TCP连接 37 | while True: 38 | check_tcp_connection(trade_host, trade_port, trade_host_msg) 39 | check_tcp_connection(market_host, market_port, market_host_msg) 40 | time.sleep(5) -------------------------------------------------------------------------------- /Scripts/tcp_connect.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MichaelFinance/CTP_DEV_NOTE/fb077c67f19f47861f0a22f7cb07f77a72f8c2bd/Scripts/tcp_connect.zip --------------------------------------------------------------------------------