Skip to content

Commit

Permalink
更新:升级接口到6.5.1(lnx);大商所非交易合约数量庞大导致的问题
Browse files Browse the repository at this point in the history
Signed-off-by: haifengat <hubert28@qq.com>
  • Loading branch information
hubertwu1976 committed Jan 15, 2021
1 parent b1f24f4 commit 1d91a9d
Show file tree
Hide file tree
Showing 58 changed files with 24,071 additions and 2,181 deletions.
50 changes: 11 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,63 +16,35 @@
* 编译后生成的dll放在 `py_ctp/lib64` 目录下
* Linux
* 设置系统语言为:zh_CN.UTF-8
* 复制 ctp_20180109\\*.so到 `py_ctp/lib64` 目录下
* 进入 `py_ctp/lib64` 目录,执行以下指令, -Wl,rpath=指定so路径(需要与setup.py中的data_files配合使用)
* 6.3.15
* 执行以下指令, -Wl,rpath=指定so路径(需要与setup.py中的data_files配合使用)
* export VERSION=**v6.5.1**
1. 代码生成
```bash
pip uninstall py-ctp -y && python generate/run.py v6.3.15_20190220
pip uninstall py-ctp -y && python generate/run.py $VERSION
```
2. 编译 so
```bash
cd py_ctp/lib64/ \
&& \cp ../../v6.3.15_20190220/*.so . \
cd py_ctp/lib64 && \
\cp ../../$VERSION/lnx/*.so . \
&& g++ -shared -fPIC -Wl,-rpath . -o ./ctp_trade.so ../../ctp_c/trade.cpp thosttraderapi_se.so \
&& g++ -shared -fPIC -Wl,-rpath . -o ./ctp_quote.so ../../ctp_c/quote.cpp thostmduserapi_se.so \
&& cd ../..
```
3. 测试
```bash
sed -i "s#version=.*#version='$VERSION.`date '+%m%d'`',#g" setup.py && \
python setup.py install && python test_trade.py
```
4. 上传
```bash
sed -i "s#version=.*#version='6.3.15.`date '+%m%d'`',#g" setup.py \
&& python setup.py sdist && twine upload -u haifengat dist/*6.3.15.`date '+%m%d'`*.gz \
&& python setup.py bdist_wheel && twine upload -u haifengat dist/*6.3.15.`date '+%m%d'`*.whl
```
* 6.3.16
1. 代码生成
```bash
pip uninstall py-ctp -y && python generate/run.py v6.3.16_T1_20190508
```
2. 编译 so
```bash
cd py_ctp/lib64/ \
&& \cp ../../v6.3.16_T1_20190508/*.so . \
&& g++ -shared -fPIC -Wl,-rpath . -o ./ctp_trade.so ../../ctp_c/trade.cpp thosttraderapi_se.so \
&& g++ -shared -fPIC -Wl,-rpath . -o ./ctp_quote.so ../../ctp_c/quote.cpp thostmduserapi_se.so \
&& cd ../..
```
3. 测试
```bash
python setup.py install && python test_trade.py
```
4. 上传
```bash
sed -i "s#version=.*#version='6.3.16.`date '+%m%d'`',#g" setup.py \
&& python setup.py sdist && twine upload -u haifengat dist/*6.3.16.`date '+%m%d'`*.gz \
&& python setup.py bdist_wheel && twine upload -u haifengat dist/*6.3.16.`date '+%m%d'`*.whl
python setup.py sdist && twine upload -u haifengat dist/*$VERSION.`date '+%m%d'`*.gz && \
python setup.py bdist_wheel && twine upload -u haifengat dist/*$VERSION.`date '+%m%d'`*.whl
```

* 代码管理
```bash
eval `ssh-agent`
ssh-add /home/code/gitee_rsa
git push gitee
```

## 更新
### 20201104
更新:接口更新到6.3.15;不再支持32位; 解决lnx下so路径问题;解决合约过多导致的bug;

### 20210115
更新:接口更新到6.5.1;大商所非交易合约数量庞大导致的问题。

157 changes: 156 additions & 1 deletion cs_ctp/proxy/ctp_enum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public enum TThostFtdcIdCardTypeType : byte
///</summary>
THOST_FTDC_ICT_OtherCard = (byte)'x',
/// <summary>
/// 机构成立证明文件
///</summary>
THOST_FTDC_ICT_CorporationCertNo = (byte)'O',
/// <summary>
/// 统一社会信用代码
///</summary>
THOST_FTDC_ICT_UniformSocialCreditCode = (byte)'N',
/// <summary>
/// 资管产品备案函
///</summary>
THOST_FTDC_ICT_CptMngPrdLetter = (byte)'L',
Expand Down Expand Up @@ -687,6 +695,14 @@ public enum TThostFtdcTradingRoleType : byte
///</summary>
public enum TThostFtdcProductClassType : byte
{
/// <summary>
/// 金属指数
///</summary>
THOST_FTDC_PC_MI = (byte)'I',
/// <summary>
/// TAS合约
///</summary>
THOST_FTDC_PC_TAS = (byte)'7',
/// <summary>
/// 现货期权
///</summary>
Expand All @@ -713,6 +729,45 @@ public enum TThostFtdcProductClassType : byte
THOST_FTDC_PC_Futures = (byte)'1',
}

/// <summary>
/// 产品类型类型
///</summary>
public enum TThostFtdcAPIProductClassType : byte
{
/// <summary>
/// 所有合约(包含不能交易合约 慎用)
///</summary>
THOST_FTDC_APC_All = (byte)'8',
/// <summary>
/// 所有可以交易合约
///</summary>
THOST_FTDC_APC_AllTrading = (byte)'7',
/// <summary>
/// 可申请的组合(dce可以申请的组合合约 包含dce可以交易的合约)
///</summary>
THOST_FTDC_APC_UnTradingComb = (byte)'6',
/// <summary>
/// 可下单组合(目前包含DCE和ZCE的期货组合)
///</summary>
THOST_FTDC_APC_TradingComb = (byte)'5',
/// <summary>
/// 可交易期权(含期权组合和期权单一合约)
///</summary>
THOST_FTDC_APC_Options = (byte)'4',
/// <summary>
/// 可交易期货(含期货组合和期货单一合约)
///</summary>
THOST_FTDC_APC_Futures = (byte)'3',
/// <summary>
/// 期权单一合约
///</summary>
THOST_FTDC_APC_OptionSingle = (byte)'2',
/// <summary>
/// 期货单一合约
///</summary>
THOST_FTDC_APC_FutureSingle = (byte)'1',
}

/// <summary>
/// 合约生命周期状态类型
///</summary>
Expand Down Expand Up @@ -1289,6 +1344,21 @@ public enum TThostFtdcTradeTypeType : byte
THOST_FTDC_TRDT_SplitCombinatio = (byte)'n',
}

/// <summary>
/// 特殊持仓明细标识类型
///</summary>
public enum TThostFtdcSpecPosiTypeType : byte
{
/// <summary>
/// TAS合约成交产生的标的合约持仓明细
///</summary>
THOST_FTDC_SPOST_Tas = (byte)'0',
/// <summary>
/// 普通持仓明细
///</summary>
THOST_FTDC_SPOST_Commo = (byte)'n',
}

/// <summary>
/// 成交价来源类型
///</summary>
Expand Down Expand Up @@ -2694,6 +2764,14 @@ public enum TThostFtdcUserEventTypeType : byte
///</summary>
THOST_FTDC_UET_Other = (byte)'9',
/// <summary>
/// 转账
///</summary>
THOST_FTDC_UET_Transfer = (byte)'8',
/// <summary>
/// 终端信息上报
///</summary>
THOST_FTDC_UET_SubmitSysInfo = (byte)'7',
/// <summary>
/// 客户端认证
///</summary>
THOST_FTDC_UET_Authenticate = (byte)'6',
Expand Down Expand Up @@ -6474,10 +6552,26 @@ public enum TThostFtdcExecResultType : byte
///</summary>
public enum TThostFtdcCombinationTypeType : byte
{
/// <summary>
/// 卖出期权垂直价差组合
///</summary>
THOST_FTDC_COMBT_BES = (byte)'a',
/// <summary>
/// 买入期权垂直价差组合
///</summary>
THOST_FTDC_COMBT_BLS = (byte)'9',
/// <summary>
/// 买备兑组合
///</summary>
THOST_FTDC_COMBT_BFO = (byte)'8',
/// <summary>
/// 期权对锁组合
///</summary>
THOST_FTDC_COMBT_OPL = (byte)'7',
/// <summary>
/// 时间价差组合
///</summary>
THOST_FTDC_COMBT_CLD = (byte)'6',
THOST_FTDC_COMBT_CAS = (byte)'6',
/// <summary>
/// 备兑组合
///</summary>
Expand Down Expand Up @@ -6812,6 +6906,10 @@ public enum TThostFtdcCFFEXUploadFileNameType : byte
///</summary>
public enum TThostFtdcCombDirectionType : byte
{
/// <summary>
/// 操作员删组合单
///</summary>
THOST_FTDC_CMDR_DelComb = (byte)'2',
/// <summary>
/// 申请拆分
///</summary>
Expand Down Expand Up @@ -6996,3 +7094,60 @@ public enum TThostFtdcMatchTypeType : byte
THOST_FTDC_OTC_MT_DV01 = (byte)'1',
}

/// <summary>
/// 用户终端认证方式类型
///</summary>
public enum TThostFtdcAuthTypeType : byte
{
/// <summary>
/// 黑名单校验
///</summary>
THOST_FTDC_AU_BLACK = (byte)'1',
/// <summary>
/// 白名单校验
///</summary>
THOST_FTDC_AU_WHITE = (byte)'0',
}

/// <summary>
/// 合约分类方式类型
///</summary>
public enum TThostFtdcClassTypeType : byte
{
/// <summary>
/// 组合合约
///</summary>
THOST_FTDC_INS_COMB = (byte)'3',
/// <summary>
/// 期货、现货期权合约
///</summary>
THOST_FTDC_INS_OPTION = (byte)'2',
/// <summary>
/// 期货、即期、期转现、Tas、金属指数合约
///</summary>
THOST_FTDC_INS_FUTURE = (byte)'1',
/// <summary>
/// 所有合约
///</summary>
THOST_FTDC_INS_ALL = (byte)'0',
}

/// <summary>
/// 合约交易状态分类方式类型
///</summary>
public enum TThostFtdcTradingTypeType : byte
{
/// <summary>
/// 非交易
///</summary>
THOST_FTDC_TD_UNTRADE = (byte)'2',
/// <summary>
/// 交易
///</summary>
THOST_FTDC_TD_TRADE = (byte)'1',
/// <summary>
/// 所有状态
///</summary>
THOST_FTDC_TD_ALL = (byte)'0',
}

36 changes: 27 additions & 9 deletions cs_ctp/proxy/ctp_quote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ public ctp_quote()
string curPath = Environment.CurrentDirectory;
var dll_path = new FileInfo(this.GetType().Assembly.Location).DirectoryName;
Environment.CurrentDirectory = dll_path;
dll_path = Path.Combine(dll_path, "lib64");
if (!Directory.Exists(dll_path))
{
File.WriteAllBytes("lib.zip", Properties.Resources.lib64);
ZipFile.ExtractToDirectory("lib.zip", ".");
File.Delete("lib.zip");
}
dll_path = Path.Combine(dll_path, "lib64");
if (!Directory.Exists(dll_path))
{
File.WriteAllBytes("lib.zip", Properties.Resources.lib64);
ZipFile.ExtractToDirectory("lib.zip", ".");
File.Delete("lib.zip");
}
Environment.CurrentDirectory = dll_path;
_handle = LoadLibrary(Path.Combine(dll_path, "ctp_quote.dll"));
if (_handle == IntPtr.Zero)
Expand Down Expand Up @@ -114,6 +114,8 @@ public ctp_quote()
public delegate IntPtr DeleReqUserLogin(IntPtr api, ref CThostFtdcReqUserLoginField pReqUserLoginField, int nRequestID);
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
public delegate IntPtr DeleReqUserLogout(IntPtr api, ref CThostFtdcUserLogoutField pUserLogout, int nRequestID);
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
public delegate IntPtr DeleReqQryMulticastInstrument(IntPtr api, ref CThostFtdcQryMulticastInstrumentField pQryMulticastInstrument, int nRequestID);
public IntPtr Release()
{
return (Invoke(_handle, "Release", typeof(DeleRelease)) as DeleRelease)(_api);
Expand Down Expand Up @@ -190,7 +192,7 @@ public IntPtr UnSubscribeForQuoteRsp(IntPtr ppInstrumentID,int nCount = 1)
}


public IntPtr ReqUserLogin(string TradingDay = "",string BrokerID = "",string UserID = "",string Password = "",string UserProductInfo = "",string InterfaceProductInfo = "",string ProtocolInfo = "",string MacAddress = "",string OneTimePassword = "",string ClientIPAddress = "",string LoginRemark = "",int ClientIPPort = 0)
public IntPtr ReqUserLogin(string TradingDay = "",string BrokerID = "",string UserID = "",string Password = "",string UserProductInfo = "",string InterfaceProductInfo = "",string ProtocolInfo = "",string MacAddress = "",string OneTimePassword = "",string reserve1 = "",string LoginRemark = "",int ClientIPPort = 0,string ClientIPAddress = "")
{
CThostFtdcReqUserLoginField pReqUserLoginField = new CThostFtdcReqUserLoginField
{
Expand All @@ -203,9 +205,10 @@ public IntPtr ReqUserLogin(string TradingDay = "",string BrokerID = "",string Us
ProtocolInfo = ProtocolInfo,
MacAddress = MacAddress,
OneTimePassword = OneTimePassword,
ClientIPAddress = ClientIPAddress,
reserve1 = reserve1,
LoginRemark = LoginRemark,
ClientIPPort = ClientIPPort,
ClientIPAddress = ClientIPAddress,
};
return (Invoke(_handle, "ReqUserLogin", typeof(DeleReqUserLogin)) as DeleReqUserLogin)(_api, ref pReqUserLoginField, this.nRequestID++);
}
Expand All @@ -221,6 +224,18 @@ public IntPtr ReqUserLogout(string BrokerID = "",string UserID = "")
return (Invoke(_handle, "ReqUserLogout", typeof(DeleReqUserLogout)) as DeleReqUserLogout)(_api, ref pUserLogout, this.nRequestID++);
}


public IntPtr ReqQryMulticastInstrument(int TopicID = 0,string reserve1 = "",string InstrumentID = "")
{
CThostFtdcQryMulticastInstrumentField pQryMulticastInstrument = new CThostFtdcQryMulticastInstrumentField
{
TopicID = TopicID,
reserve1 = reserve1,
InstrumentID = InstrumentID,
};
return (Invoke(_handle, "ReqQryMulticastInstrument", typeof(DeleReqQryMulticastInstrument)) as DeleReqQryMulticastInstrument)(_api, ref pQryMulticastInstrument, this.nRequestID++);
}

[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
delegate void DeleSet(IntPtr spi, Delegate func);
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
Expand All @@ -234,6 +249,8 @@ public IntPtr ReqUserLogout(string BrokerID = "",string UserID = "")
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
public delegate void DeleOnRspUserLogout(ref CThostFtdcUserLogoutField pUserLogout,ref CThostFtdcRspInfoField pRspInfo,int nRequestID,bool bIsLast);
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
public delegate void DeleOnRspQryMulticastInstrument(ref CThostFtdcMulticastInstrumentField pMulticastInstrument,ref CThostFtdcRspInfoField pRspInfo,int nRequestID,bool bIsLast);
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
public delegate void DeleOnRspError(ref CThostFtdcRspInfoField pRspInfo,int nRequestID,bool bIsLast);
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
public delegate void DeleOnRspSubMarketData(ref CThostFtdcSpecificInstrumentField pSpecificInstrument,ref CThostFtdcRspInfoField pRspInfo,int nRequestID,bool bIsLast);
Expand All @@ -252,6 +269,7 @@ public IntPtr ReqUserLogout(string BrokerID = "",string UserID = "")
public void SetOnHeartBeatWarning(DeleOnHeartBeatWarning func) {(Invoke(_handle, "SetOnHeartBeatWarning", typeof(DeleSet)) as DeleSet)(_spi, func);}
public void SetOnRspUserLogin(DeleOnRspUserLogin func) {(Invoke(_handle, "SetOnRspUserLogin", typeof(DeleSet)) as DeleSet)(_spi, func);}
public void SetOnRspUserLogout(DeleOnRspUserLogout func) {(Invoke(_handle, "SetOnRspUserLogout", typeof(DeleSet)) as DeleSet)(_spi, func);}
public void SetOnRspQryMulticastInstrument(DeleOnRspQryMulticastInstrument func) {(Invoke(_handle, "SetOnRspQryMulticastInstrument", typeof(DeleSet)) as DeleSet)(_spi, func);}
public void SetOnRspError(DeleOnRspError func) {(Invoke(_handle, "SetOnRspError", typeof(DeleSet)) as DeleSet)(_spi, func);}
public void SetOnRspSubMarketData(DeleOnRspSubMarketData func) {(Invoke(_handle, "SetOnRspSubMarketData", typeof(DeleSet)) as DeleSet)(_spi, func);}
public void SetOnRspUnSubMarketData(DeleOnRspUnSubMarketData func) {(Invoke(_handle, "SetOnRspUnSubMarketData", typeof(DeleSet)) as DeleSet)(_spi, func);}
Expand Down
Loading

0 comments on commit 1d91a9d

Please sign in to comment.