//获取K线 public TDBErrNo GetKLine(TDBReqKLine reqKLine, out TDBKLine[] tdbKLine) { TDBErrNo nVerifyRet = SimpleVerifyReqInput(reqKLine); tdbKLine = new TDBKLine[0]; if (nVerifyRet != TDBErrNo.TDB_SUCCESS) { return(nVerifyRet); } LibTDBWrap.TDBDefine_ReqKLine reqKLineInner = reqKLine.ToAPIReqKLine(); IntPtr pUnmanagedAPIReqK = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LibTDBWrap.TDBDefine_ReqKLine))); Marshal.StructureToPtr(reqKLineInner, pUnmanagedAPIReqK, false); IntPtr ppKLine = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); IntPtr pCount = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Int32))); int nRet = LibTDBWrap.TDB_GetKLine(m_hTdb, pUnmanagedAPIReqK, ppKLine, pCount); IntPtr PKLine = (IntPtr)Marshal.PtrToStructure(ppKLine, typeof(IntPtr)); int nCount = (int)Marshal.PtrToStructure(pCount, typeof(Int32)); if ((UInt64)PKLine != 0 && nRet == 0 && nCount > 0) { tdbKLine = new TDBKLine[nCount]; int nElemLen = Marshal.SizeOf(typeof(LibTDBWrap.TDBDefine_KLine)); for (int i = 0; i < nCount; i++) { LibTDBWrap.TDBDefine_KLine apiKLine = (LibTDBWrap.TDBDefine_KLine)Marshal.PtrToStructure((IntPtr)((UInt64)PKLine + (UInt64)(nElemLen * i)), typeof(LibTDBWrap.TDBDefine_KLine)); tdbKLine[i] = new TDBKLine(); tdbKLine[i].FromAPIKLine(ref apiKLine); } } else { //如果网络连接断掉,则关闭连接 if (nRet == (int)TDBErrNo.TDB_NETWORK_ERROR) { DisConnect(); } } if ((UInt64)PKLine != 0) { LibTDBWrap.TDB_Free(PKLine); } Marshal.FreeHGlobal(pUnmanagedAPIReqK); Marshal.FreeHGlobal(ppKLine); Marshal.FreeHGlobal(pCount); return((TDBErrNo)nRet); }
public int m_nInterest; //持仓量(期货)、IOPV(基金)、利息(债券) public void FromAPIKLine(ref LibTDBWrap.TDBDefine_KLine apiKLine) { m_strWindCode = LibWrapHelper.AnsiArr2String(apiKLine.chWindCode, 0, apiKLine.chWindCode.Length); m_strCode = LibWrapHelper.AnsiArr2String(apiKLine.chCode, 0, apiKLine.chCode.Length); m_nDate = apiKLine.nDate; m_nTime = apiKLine.nTime; m_nOpen = apiKLine.nOpen; m_nHigh = apiKLine.nHigh; m_nLow = apiKLine.nLow; m_nClose = apiKLine.nClose; m_iVolume = apiKLine.iVolume; m_iTurover = apiKLine.iTurover; m_nMatchItems = apiKLine.nMatchItems; m_nInterest = apiKLine.nInterest; }