Hi. I've been tortured by this problem for a long time.
This is a callback function provided by a dll.
I will put this function in pyx file, and pyx is compiled by cython ,I could call it from python.
But the program crashed in function OnRtnOrder, Now I know it must be wrong when I try to assign c++ struct member to a python dict.
I don't know how to do. Please help.
cdef cppclass CUserSpi(CThostFtdcUserSpi):
void OnRtnOrder(CThostFtdcOrderField *pOrder):
if not pOrder:
return
dictSpi = {}
dictSpi['InvestorID'] = pOrder.InvestorID
dictSpi['BrokerID'] = pOrder.BrokerID
.........
dictSpi['InstrumentID'] = pOrder.InstrumentID
this.CallPythonPutQ(dictSpi)
CThostFtdcOrderField is a struct, most of its members char arrays. It is defined in .h files.
struct CThostFtdcOrderField
{
///经纪公司代码
TThostFtdcBrokerIDType BrokerID;
///投资者代码
TThostFtdcInvestorIDType InvestorID;
///合约代码
TThostFtdcInstrumentIDType InstrumentID;
///报单价格条件
TThostFtdcOrderPriceTypeType OrderPriceType;
///买卖方向
TThostFtdcDirectionType Direction;
///组合开平标志
TThostFtdcCombOffsetFlagType CombOffsetFlag;
///组合投机套保标志
TThostFtdcCombHedgeFlagType CombHedgeFlag;
///价格
TThostFtdcPriceType LimitPrice;
///数量
TThostFtdcVolumeType VolumeTotalOriginal;
///有效期类型
TThostFtdcTimeConditionType TimeCondition;
///GTD日期
TThostFtdcDateType GTDDate;
///最小成交量
TThostFtdcVolumeType MinVolume;
///今成交数量
TThostFtdcVolumeType VolumeTraded;
///剩余数量
TThostFtdcVolumeType VolumeTotal;
///报单日期
TThostFtdcDateType InsertDate;
///委托时间
TThostFtdcTimeType InsertTime;
///IP地址
TThostFtdcIPAddressType IPAddress;
///Mac地址
TThostFtdcMacAddressType MacAddress;
};
the datatypes is like this:
typedef char TThostFtdcBrokerIDType[11];
typedef char TThostFtdcInvestorIDType[13];
typedef int TThostFtdcVolumeType;
typedef char TThostFtdcDateType[9];
typedef char TThostFtdcTimeType[9];
typedef double TThostFtdcPriceType;