Пример #1
0
        private void OnRtnDepthMarketData_callback(object sender, [In] ref XAPI.DepthMarketDataNClass marketData)
        {
            DepthMarketDataNClass cls = new DepthMarketDataNClass();

            XAPI.DepthMarketDataNClass field = marketData;

            cls.TradingDay          = field.TradingDay;
            cls.ActionDay           = field.ActionDay;
            cls.UpdateTime          = field.UpdateTime;
            cls.UpdateMillisec      = field.UpdateMillisec;
            cls.Exchange            = (int)field.Exchange;
            cls.Symbol              = field.Symbol;
            cls.InstrumentID        = field.InstrumentID;
            cls.ExchangeID          = field.ExchangeID;
            cls.LastPrice           = field.LastPrice;
            cls.Volume              = field.Volume;
            cls.Turnover            = field.Turnover;
            cls.OpenInterest        = field.OpenInterest;
            cls.AveragePrice        = field.AveragePrice;
            cls.OpenPrice           = field.OpenPrice;
            cls.HighestPrice        = field.HighestPrice;
            cls.LowestPrice         = field.LowestPrice;
            cls.ClosePrice          = field.ClosePrice;
            cls.SettlementPrice     = field.SettlementPrice;
            cls.UpperLimitPrice     = field.UpperLimitPrice;
            cls.LowerLimitPrice     = field.LowerLimitPrice;
            cls.PreClosePrice       = field.PreClosePrice;
            cls.PreSettlementPrice  = field.PreSettlementPrice;
            cls.PreOpenInterest     = field.PreOpenInterest;
            cls.TradingPhase        = (int)field.TradingPhase;
            cls.TradingPhase_String = Enum <XAPI.TradingPhaseType> .ToString(field.TradingPhase);

            if (field.Bids != null && field.Bids.Length > 0)
            {
                cls.BidPrice1 = field.Bids[0].Price;
                cls.BidSize   = field.Bids[0].Size;
            }

            if (field.Asks != null && field.Asks.Length > 0)
            {
                cls.AskPrice1 = field.Asks[0].Price;
                cls.AskSize   = field.Asks[0].Size;
            }

            if (null == OnRtnDepthMarketData)
            {
                QueueData qd = new QueueData();
                qd.Type        = (int)ResponseType.OnRtnDepthMarketData;
                qd.Type_String = Enum <XAPI.ResponseType> .ToString(ResponseType.OnRtnDepthMarketData);

                qd.Sender = this;
                qd.Data1  = cls;

                MessageQueue.Enqueue(qd);
            }
            else
            {
                OnRtnDepthMarketData(this, cls);
            }
        }
Пример #2
0
        private void XApi_OnRtnDepthMarketData(object sender, ref XAPI.DepthMarketDataNClass marketData)
        {
            if (onReturnMarketData == null)
            {
                return;
            }
            if (!IsInOpenPeriod(marketData.UpdateTime))
            {
                return;
            }
            ITickBar tickBar = StructTransfer.TransferTickBar(marketData);

            onReturnMarketData(sender, ref tickBar);
        }
Пример #3
0
        //public static MarketData TransferMarketData(XAPI.DepthMarketDataNClass marketData)
        //{
        //    MarketData rspMarketData = new MarketData();
        //    XAPI.DepthField bidField = marketData.Bids[0];
        //    XAPI.DepthField askField = marketData.Asks[0];
        //    rspMarketData.BuyMount = askField.Size;
        //    rspMarketData.BuyPrice = (float)askField.Price;
        //    rspMarketData.SellMount = bidField.Size;
        //    rspMarketData.SellPrice = (float)bidField.Price;
        //    rspMarketData.Price = (float)marketData.OpenPrice;
        //    rspMarketData.Time = marketData.ActionDay + Math.Round(((double)marketData.UpdateTime) / 100000, 6);

        //    return rspMarketData;
        //}

        public static ITickBar TransferTickBar(XAPI.DepthMarketDataNClass xapiMarketData)
        {
            TickBar tickBar = new TickBar();

            //tickBar.Code = transferCode(xapiMarketData.InstrumentID);
            tickBar.Code       = xapiMarketData.InstrumentID;
            tickBar.Time       = xapiMarketData.ActionDay + Math.Round((double)xapiMarketData.UpdateTime / 1000000, 6);
            tickBar.Price      = (float)xapiMarketData.LastPrice;
            tickBar.Mount      = 0;
            tickBar.TotalMount = (int)xapiMarketData.Volume;
            tickBar.Add        = 0;
            tickBar.Hold       = (int)xapiMarketData.OpenInterest;
            tickBar.BuyMount   = xapiMarketData.Bids.Length == 0 ? 0 : xapiMarketData.Bids[0].Size;
            tickBar.BuyPrice   = xapiMarketData.Bids.Length == 0 ? 0 : (float)xapiMarketData.Bids[0].Price;
            tickBar.IsBuy      = xapiMarketData.LastPrice == tickBar.BuyPrice;
            tickBar.SellMount  = xapiMarketData.Asks.Length == 0 ? 0 : xapiMarketData.Asks[0].Size;
            tickBar.SellPrice  = xapiMarketData.Asks.Length == 0 ? 0 : (float)xapiMarketData.Asks[0].Price;
            return(tickBar);
        }