libcctp.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // libcctp.h
  2. // libcctp是把CTP的C++接口转换为C接口, 这样方便其他语言(比如go, python, java等)调用
  3. // 同时对原有的接口进行封装和简化, 但不影响原有功能. 达到使用简单, 功能完全的目的。
  4. // 本文件定义了libcctp的导出函数
  5. #pragma once
  6. #ifdef _WINDOWS
  7. #ifdef LIBCCTP_EXPORTS
  8. #define LIBCCTP_API __declspec(dllexport)
  9. #else
  10. #define LIBCCTP_API __declspec(dllimport)
  11. #endif
  12. #else
  13. #define LIBCCTP_API
  14. #endif
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #else
  18. typedef int bool;
  19. #endif
  20. #include "CTP/ThostFtdcUserApiStruct.h"
  21. // c only
  22. typedef struct CThostFtdcRspUserLoginField CThostFtdcRspUserLoginField;
  23. typedef struct CThostFtdcRspInfoField CThostFtdcRspInfoField;
  24. typedef struct CThostFtdcUserLogoutField CThostFtdcUserLogoutField;
  25. typedef struct CThostFtdcRspAuthenticateField CThostFtdcRspAuthenticateField;
  26. typedef struct CThostFtdcReqUserLoginField CThostFtdcReqUserLoginField;
  27. typedef struct CThostFtdcSpecificInstrumentField CThostFtdcSpecificInstrumentField;
  28. typedef struct CThostFtdcUserPasswordUpdateField CThostFtdcUserPasswordUpdateField;
  29. typedef struct CThostFtdcTradingAccountPasswordUpdateField CThostFtdcTradingAccountPasswordUpdateField;
  30. typedef struct CThostFtdcInputOrderField CThostFtdcInputOrderField;
  31. typedef struct CThostFtdcParkedOrderField CThostFtdcParkedOrderField;
  32. typedef struct CThostFtdcParkedOrderActionField CThostFtdcParkedOrderActionField;
  33. typedef struct CThostFtdcQueryMaxOrderVolumeField CThostFtdcQueryMaxOrderVolumeField;
  34. typedef struct CThostFtdcOrderField CThostFtdcOrderField;
  35. typedef struct CThostFtdcTradeField CThostFtdcTradeField;
  36. typedef struct CThostFtdcExchangeField CThostFtdcExchangeField;
  37. typedef struct CThostFtdcInstrumentField CThostFtdcInstrumentField;
  38. typedef struct CThostFtdcDepthMarketDataField CThostFtdcDepthMarketDataField;
  39. typedef struct CThostFtdcSettlementInfoField CThostFtdcSettlementInfoField;
  40. typedef struct CThostFtdcTransferBankField CThostFtdcTransferBankField;
  41. typedef struct CThostFtdcInvestorPositionDetailField CThostFtdcInvestorPositionDetailField;
  42. typedef struct CThostFtdcNoticeField CThostFtdcNoticeField;
  43. typedef struct CThostFtdcSettlementInfoConfirmField CThostFtdcSettlementInfoConfirmField;
  44. typedef struct CThostFtdcRemoveParkedOrderField CThostFtdcRemoveParkedOrderField;
  45. typedef struct CThostFtdcRemoveParkedOrderActionField CThostFtdcRemoveParkedOrderActionField;
  46. typedef struct CThostFtdcInvestorPositionField CThostFtdcInvestorPositionField;
  47. typedef struct CThostFtdcTradingAccountField CThostFtdcTradingAccountField;
  48. typedef struct CThostFtdcInvestorField CThostFtdcInvestorField;
  49. typedef struct CThostFtdcTradingCodeField CThostFtdcTradingCodeField;
  50. typedef struct CThostFtdcInstrumentMarginRateField CThostFtdcInstrumentMarginRateField;
  51. typedef struct CThostFtdcInstrumentCommissionRateField CThostFtdcInstrumentCommissionRateField;
  52. typedef struct CThostFtdcCFMMCTradingAccountKeyField CThostFtdcCFMMCTradingAccountKeyField;
  53. typedef struct CThostFtdcEWarrantOffsetField CThostFtdcEWarrantOffsetField;
  54. typedef struct CThostFtdcContractBankField CThostFtdcContractBankField;
  55. typedef struct CThostFtdcInvestorPositionCombineDetailField CThostFtdcInvestorPositionCombineDetailField;
  56. typedef struct CThostFtdcCancelAccountField CThostFtdcCancelAccountField;
  57. typedef struct CThostFtdcChangeAccountField CThostFtdcChangeAccountField;
  58. typedef struct CThostFtdcTransferSerialField CThostFtdcTransferSerialField;
  59. typedef struct CThostFtdcAccountregisterField CThostFtdcAccountregisterField;
  60. typedef struct CThostFtdcOrderActionField CThostFtdcOrderActionField;
  61. typedef struct CThostFtdcInstrumentStatusField CThostFtdcInstrumentStatusField;
  62. typedef struct CThostFtdcErrorConditionalOrderField CThostFtdcErrorConditionalOrderField;
  63. typedef struct CThostFtdcTradingNoticeInfoField CThostFtdcTradingNoticeInfoField;
  64. typedef struct CThostFtdcTradingNoticeField CThostFtdcTradingNoticeField;
  65. typedef struct CThostFtdcBrokerTradingParamsField CThostFtdcBrokerTradingParamsField;
  66. typedef struct CThostFtdcBrokerTradingAlgosField CThostFtdcBrokerTradingAlgosField;
  67. typedef struct CThostFtdcRspTransferField CThostFtdcRspTransferField;
  68. typedef struct CThostFtdcQryInstrumentField CThostFtdcQryInstrumentField;
  69. typedef struct CThostFtdcQryOrderField CThostFtdcQryOrderField;
  70. ///期货发起查询银行余额通知
  71. typedef struct CThostFtdcNotifyQueryAccountField CThostFtdcNotifyQueryAccountField;
  72. typedef struct CThostFtdcQryInvestorPositionField CThostFtdcQryInvestorPositionField;
  73. ///期货发起银行资金转期货错误回报
  74. typedef struct CThostFtdcReqTransferField CThostFtdcReqTransferField;
  75. ///系统运行时期货端手工发起冲正银行转期货错误回报
  76. typedef struct CThostFtdcReqRepealField CThostFtdcReqRepealField;
  77. ///系统运行时期货端手工发起冲正期货转银行错误回报
  78. typedef struct OnErrRtnRepealFutureToBankByFutureManual OnErrRtnRepealFutureToBankByFutureManual;
  79. ///期货发起查询银行余额错误回报
  80. typedef struct CThostFtdcReqQueryAccountField CThostFtdcReqQueryAccountField;
  81. typedef struct CThostFtdcQryInvestorField CThostFtdcQryInvestorField;
  82. ///期货发起冲正期货转银行请求,银行处理完毕后报盘发回的通知
  83. typedef struct CThostFtdcRspRepealField CThostFtdcRspRepealField;
  84. ///期货发起银行资金转期货应答
  85. ///期货发起期货资金转银行应答
  86. ///期货发起查询银行余额应答
  87. typedef struct CThostFtdcQryTradingAccountField CThostFtdcQryTradingAccountField;
  88. ///银行发起银期开户通知
  89. typedef struct CThostFtdcOpenAccountField CThostFtdcOpenAccountField;
  90. typedef struct CThostFtdcReqAuthenticateField CThostFtdcReqAuthenticateField;
  91. typedef struct CThostFtdcQryTradingCodeField CThostFtdcQryTradingCodeField;
  92. typedef struct CThostFtdcQryTradeField CThostFtdcQryTradeField;
  93. typedef struct CThostFtdcQryInstrumentCommissionRateField CThostFtdcQryInstrumentCommissionRateField;
  94. typedef struct CThostFtdcQryInstrumentMarginRateField CThostFtdcQryInstrumentMarginRateField;
  95. typedef struct CThostFtdcQrySettlementInfoField CThostFtdcQrySettlementInfoField;
  96. typedef struct CThostFtdcQryExchangeField CThostFtdcQryExchangeField;
  97. typedef struct CThostFtdcQryDepthMarketDataField CThostFtdcQryDepthMarketDataField;
  98. typedef struct CThostFtdcQryInvestorPositionDetailField CThostFtdcQryInvestorPositionDetailField;
  99. typedef struct CThostFtdcQryTransferBankField CThostFtdcQryTransferBankField;
  100. ///请求查询客户通知
  101. typedef struct CThostFtdcQryNoticeField CThostFtdcQryNoticeField;
  102. ///请求查询结算信息确认
  103. typedef struct CThostFtdcQrySettlementInfoConfirmField CThostFtdcQrySettlementInfoConfirmField;
  104. ///请求查询投资者持仓明细
  105. typedef struct CThostFtdcQryInvestorPositionCombineDetailField CThostFtdcQryInvestorPositionCombineDetailField;
  106. ///请求查询保证金监管系统经纪公司资金账户密钥
  107. typedef struct CThostFtdcQryCFMMCTradingAccountKeyField CThostFtdcQryCFMMCTradingAccountKeyField;
  108. ///请求查询仓单折抵信息
  109. typedef struct CThostFtdcQryEWarrantOffsetField CThostFtdcQryEWarrantOffsetField;
  110. ///请求查询转帐流水
  111. typedef struct CThostFtdcQryTransferSerialField CThostFtdcQryTransferSerialField;
  112. ///请求查询银期签约关系
  113. typedef struct CThostFtdcQryAccountregisterField CThostFtdcQryAccountregisterField;
  114. ///请求查询签约银行
  115. typedef struct CThostFtdcQryContractBankField CThostFtdcQryContractBankField;
  116. ///请求查询预埋单
  117. typedef struct CThostFtdcQryParkedOrderField CThostFtdcQryParkedOrderField;
  118. ///请求查询预埋撤单
  119. typedef struct CThostFtdcQryParkedOrderActionField CThostFtdcQryParkedOrderActionField;
  120. ///请求查询交易通知
  121. typedef struct CThostFtdcQryTradingNoticeField CThostFtdcQryTradingNoticeField;
  122. ///请求查询经纪公司交易参数
  123. typedef struct CThostFtdcQryBrokerTradingParamsField CThostFtdcQryBrokerTradingParamsField;
  124. ///请求查询经纪公司交易算法
  125. typedef struct CThostFtdcQryBrokerTradingAlgosField CThostFtdcQryBrokerTradingAlgosField;
  126. ///登录请求响应
  127. typedef void(*fnOnRspUserLogin)(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast, void* ctx);
  128. ///登出请求响应
  129. typedef void(*fnOnRspUserLogout)(CThostFtdcUserLogoutField *pUserLogout, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast, void* ctx);
  130. ///错误应答
  131. typedef void(*fnOnRspError)(CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast, void* ctx);
  132. ///深度行情通知
  133. typedef void(*fnOnRtnDepthMarketData)(CThostFtdcDepthMarketDataField *pDepthMarketData, void* ctx);
  134. ///请求查询交易所响应
  135. typedef void(*fnOnRspQryExchange)(CThostFtdcExchangeField *pExchange, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast, void* ctx);
  136. ///请求查询合约响应
  137. typedef void(*fnOnRspQryInstrument)(CThostFtdcInstrumentField *pInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast, void* ctx);
  138. ///请求查询结算信息确认响应
  139. typedef void(*fnOnRspSettlementInfoConfirm)(CThostFtdcSettlementInfoConfirmField *pSettlementInfoConfirm, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast, void* ctx);
  140. /// 注册行情服务回调函数
  141. LIBCCTP_API void CCTP_RegOnMdRspUserLogin(void* mdapi, fnOnRspUserLogin call_back, void* ctx);
  142. LIBCCTP_API void CCTP_RegOnMdRspUserLogout(void* mdapi, fnOnRspUserLogout call_back, void* ctx);
  143. LIBCCTP_API void CCTP_RegOnMdRspError(void* mdapi, fnOnRspError call_back, void* ctx);
  144. LIBCCTP_API void CCTP_RegOnRtnDepthMarketData(void* mdapi, fnOnRtnDepthMarketData call_back, void* ctx);
  145. // 注册交易服务回调函数
  146. LIBCCTP_API void CCTP_RegOnTdRspUserLogin(void* tdapi, fnOnRspUserLogin call_back, void* ctx);
  147. LIBCCTP_API void CCTP_RegOnTdRspUserLogout(void* tdapi, fnOnRspUserLogout call_back, void* ctx);
  148. LIBCCTP_API void CCTP_RegOnTdRspError(void* tdapi, fnOnRspError call_back, void* ctx);
  149. LIBCCTP_API void CCTP_RegOnRspQryExchange(void* tdapi, fnOnRspQryExchange call_back, void* ctx);
  150. LIBCCTP_API void CCTP_RegOnRspQryInstrument(void* tdapi, fnOnRspQryInstrument call_back, void* ctx);
  151. /// 创建行情Api, 返回void*指针, 以下行情部分接口此指针作为行情上下文
  152. LIBCCTP_API void* CCTP_MdApiCreate(const char* dir);
  153. /// 释放行情接口
  154. LIBCCTP_API void CCTP_MdRelease(void* mdapi);
  155. /// 登录行情
  156. LIBCCTP_API int CCTP_MdLogin(
  157. void* mdapi,
  158. const char* addr,
  159. const char* brokerId,
  160. const char* userId,
  161. const char* password);
  162. /// 登出行情
  163. LIBCCTP_API int CCTP_MdLogout(void* mdapi, const char* brokerId, const char* userId);
  164. /// 订阅合约
  165. LIBCCTP_API int CCTP_SubscribeMarketData(void* mdapi, char* instrumentIds[], int n);
  166. /// 取消订阅合约
  167. LIBCCTP_API int CCTP_UnSubscribeMarketData(void* mdapi, char* instrumentIds[], int n);
  168. /// 创建交易Api, 返回void*指针, 以下行情部分接口此指针作为上下文信息
  169. LIBCCTP_API void* CCTP_TdApiCreate(const char* dir);
  170. /// 释放交易接口
  171. LIBCCTP_API void CCTP_TdRelease(void* tdapi);
  172. /// 登录交易
  173. LIBCCTP_API int CCTP_TdLogin(
  174. void* tdapi,
  175. const char* addr,
  176. const char* brokerId,
  177. const char* userId,
  178. const char* password,
  179. const char* authCode,
  180. const char* userProductInfo);
  181. //// 登出交易
  182. LIBCCTP_API int CCTP_TdLogout(void* tdapi, const char* brokerId, const char* userId);
  183. /// 查询合约, 如果instrmentId==nullptr, 查询所有合约
  184. LIBCCTP_API int CCTP_ReqQryInstrument(void* tdapi, const char* instrumentId);
  185. /// 查询交易所, 如果instrmentId==nullptr, 查询所有合约
  186. LIBCCTP_API int CCTP_ReqQryExchange(void* tdapi, const char* exchangeId);
  187. #ifdef __cplusplus
  188. }
  189. #endif