//逐笔委托 public TDBErrNo GetOrder(TDBReq reqOrder, out TDBOrder[] tdbOrder) { TDBErrNo nVerifyRet = SimpleVerifyReqInput(reqOrder); tdbOrder = new TDBOrder[0]; if (nVerifyRet != TDBErrNo.TDB_SUCCESS) { return(nVerifyRet); } LibTDBWrap.TDBDefine_ReqTransaction reqAPIOrder = reqOrder.ToAPIReqTransaction(); IntPtr pUnmanagedReqAPIOrder = LibWrapHelper.CopyStructToGlobalMem(reqAPIOrder, typeof(LibTDBWrap.TDBDefine_ReqTransaction)); IntPtr ppOrder = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); IntPtr pCount = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Int32))); int nRet = LibTDBWrap.TDB_GetOrder(m_hTdb, pUnmanagedReqAPIOrder, ppOrder, pCount); IntPtr pOrder = (IntPtr)Marshal.PtrToStructure(ppOrder, typeof(IntPtr)); int nCount = (Int32)Marshal.PtrToStructure(pCount, typeof(Int32)); if ((UInt64)pOrder != 0 && nCount > 0 && nRet == 0) { tdbOrder = new TDBOrder[nCount]; int nElemLen = Marshal.SizeOf(typeof(LibTDBWrap.TDBDefine_Order)); for (int i = 0; i < nCount; i++) { IntPtr pCurRecord = (IntPtr)((UInt64)pOrder + (UInt64)(nElemLen * i)); LibTDBWrap.TDBDefine_Order apiOrder = (LibTDBWrap.TDBDefine_Order)Marshal.PtrToStructure(pCurRecord, typeof(LibTDBWrap.TDBDefine_Order)); tdbOrder[i] = new TDBOrder(); tdbOrder[i].FromAPIOrder(ref apiOrder); } } else { //如果网络连接断掉,则关闭连接 if (nRet == (int)TDBErrNo.TDB_NETWORK_ERROR) { DisConnect(); } } if ((UInt64)pOrder != 0) { LibTDBWrap.TDB_Free(pOrder); } Marshal.FreeHGlobal(pUnmanagedReqAPIOrder); Marshal.FreeHGlobal(ppOrder); Marshal.FreeHGlobal(pCount); return((TDBErrNo)nRet); }
//获取普通股票的行情数据(不带买卖盘),本接口不支持期货,对于期货(CF市场和商品期货),需要调用GetFuture或GetFutureAB public TDBErrNo GetTick(TDBReq reqTick, out TDBTick[] tdbTick) { TDBErrNo nVerifyRet = SimpleVerifyReqInput(reqTick); tdbTick = new TDBTick[0]; if (nVerifyRet != TDBErrNo.TDB_SUCCESS) { return(nVerifyRet); } LibTDBWrap.TDBDefine_ReqTick reqAPITick = reqTick.ToAPIReqTick(); IntPtr pUnmanagedReqAPITick = LibWrapHelper.CopyStructToGlobalMem(reqAPITick, typeof(LibTDBWrap.TDBDefine_ReqTick)); IntPtr ppTick = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); IntPtr pCount = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Int32))); int nRet = LibTDBWrap.TDB_GetTick(m_hTdb, pUnmanagedReqAPITick, ppTick, pCount); IntPtr pTick = (IntPtr)Marshal.PtrToStructure(ppTick, typeof(IntPtr)); int nCount = (Int32)Marshal.PtrToStructure(pCount, typeof(Int32)); if ((UInt64)pTick != 0 && nCount > 0 && nRet == 0) { tdbTick = new TDBTick[nCount]; int nElemLen = Marshal.SizeOf(typeof(LibTDBWrap.TDBDefine_Tick)); for (int i = 0; i < nCount; i++) { IntPtr pCurRecord = (IntPtr)((UInt64)pTick + (UInt64)(nElemLen * i)); LibTDBWrap.TDBDefine_Tick apiTick = (LibTDBWrap.TDBDefine_Tick)Marshal.PtrToStructure(pCurRecord, typeof(LibTDBWrap.TDBDefine_Tick)); tdbTick[i] = new TDBTick(); tdbTick[i].FromAPITick(ref apiTick); } } else { //如果网络连接断掉,则关闭连接 if (nRet == (int)TDBErrNo.TDB_NETWORK_ERROR) { DisConnect(); } } if ((UInt64)pTick != 0) { LibTDBWrap.TDB_Free(pTick); } Marshal.FreeHGlobal(pUnmanagedReqAPITick); Marshal.FreeHGlobal(ppTick); Marshal.FreeHGlobal(pCount); return((TDBErrNo)nRet); }