Beispiel #1
0
        //获取普通股票的行情数据(不带买卖盘),本接口不支持期货,对于期货(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);
        }
Beispiel #2
0
        public int m_nHoldLines;              //持平品种数

        public void FromAPITick(ref LibTDBWrap.TDBDefine_Tick apiTick)
        {
            m_strWindCode = LibWrapHelper.AnsiArr2String(apiTick.chWindCode, 0, apiTick.chWindCode.Length);
            m_strCode     = LibWrapHelper.AnsiArr2String(apiTick.chCode, 0, apiTick.chCode.Length);
            m_nDate       = apiTick.nDate;
            m_nTime       = apiTick.nTime;
            m_nPrice      = apiTick.nPrice;
            m_iVolume     = apiTick.iVolume;
            m_iTurover    = apiTick.iTurover;
            m_nMatchItems = apiTick.nMatchItems;
            m_nInterest   = apiTick.nInterest;
            m_chTradeFlag = (char)apiTick.chTradeFlag;
            m_chBSFlag    = (char)apiTick.chBSFlag;
            m_iAccVolume  = apiTick.iAccVolume;
            m_iAccTurover = apiTick.iAccTurover;
            m_nHigh       = apiTick.nHigh;
            m_nLow        = apiTick.nLow;
            m_nOpen       = apiTick.nOpen;
            m_nPreClose   = apiTick.nPreClose;

            //期货字段
            m_nSettle      = apiTick.nSettle;
            m_nPosition    = apiTick.nPosition;
            m_nCurDelta    = apiTick.nCurDelta;
            m_nPreSettle   = apiTick.nPreSettle;
            m_nPrePosition = apiTick.nPrePosition;

            //买卖盘字段
            m_nAskPrice       = LibWrapHelper.CopyIntArr(apiTick.nAskPrice);
            m_nAskVolume      = LibWrapHelper.CopyUIntArr(apiTick.nAskVolume);
            m_nBidPrice       = LibWrapHelper.CopyIntArr(apiTick.nBidPrice);
            m_nBidVolume      = LibWrapHelper.CopyUIntArr(apiTick.nBidVolume);
            m_nAskAvPrice     = apiTick.nAskAvPrice;
            m_nBidAvPrice     = apiTick.nBidAvPrice;
            m_iTotalAskVolume = apiTick.iTotalAskVolume;
            m_iTotalBidVolume = apiTick.iTotalBidVolume;

            //指数字段
            m_nIndex     = apiTick.nIndex;
            m_nStocks    = apiTick.nStocks;
            m_nUps       = apiTick.nUps;
            m_nDowns     = apiTick.nDowns;
            m_nHoldLines = apiTick.nHoldLines;
        }