Пример #1
0
        //获取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);
        }
Пример #2
0
        public int m_nEndTime;          //结束时间:

        public LibTDBWrap.TDBDefine_ReqKLine ToAPIReqKLine()
        {
            LibTDBWrap.TDBDefine_ReqKLine reqAPIKLine = new LibTDBWrap.TDBDefine_ReqKLine();
            reqAPIKLine.chCode        = LibWrapHelper.String2AnsiArr(m_strWindCode, 32);
            reqAPIKLine.chMarketKey   = LibWrapHelper.String2AnsiArr(m_strMarketKey, 24);
            reqAPIKLine.nCQFlag       = (int)m_nCQFlag;
            reqAPIKLine.nCQDate       = m_nCQDate;
            reqAPIKLine.nQJFlag       = m_nQJFlag;
            reqAPIKLine.nCycType      = (int)m_nCycType;
            reqAPIKLine.nCycDef       = m_nCycDef;
            reqAPIKLine.nAutoComplete = m_nAutoComplete;
            reqAPIKLine.nBeginDate    = m_nBeginDate;
            reqAPIKLine.nBeginTime    = m_nBeginTime;
            reqAPIKLine.nEndDate      = m_nEndDate;
            reqAPIKLine.nEndTime      = m_nEndTime;
            return(reqAPIKLine);
        }