示例#1
0
        public override void Subscribe(Instrument instrument)
        {
            //Task.Factory.StartNew(() => SubscribeForTest(instrument));
            //return;

            string altSymbol;
            string altExchange;
            string apiSymbol;
            string apiExchange;
            double apiTickSize;

            GetApi_Symbol_Exchange_TickSize(instrument, this.id,
                                            out altSymbol, out altExchange,
                                            out apiSymbol, out apiExchange,
                                            out apiTickSize);

            // 如果是对CTP接口,使用UFX的参数进行订阅是否有问题?IF1802.7,目前猜没有问题
            string Symbol_Dot_Exchange = string.Format("{0}.{1}", apiSymbol, apiExchange);
            string Symbol_Dot          = string.Format("{0}.", apiSymbol);
            string Symbol = apiSymbol;

            MarketDataRecord record;

            if (!marketDataRecords.TryGetValue(Symbol_Dot_Exchange, out record))
            {
                record = new MarketDataRecord();

                record.TradeRequested       = true;
                record.QuoteRequested       = true;
                record.MarketDepthRequested = true;

                record.Symbol              = apiSymbol;
                record.Exchange            = apiExchange;
                record.Symbol_Dot          = Symbol_Dot;
                record.Symbol_Dot_Exchange = Symbol_Dot_Exchange;

                // 可能没有交易所信息
                marketDataRecords[Symbol_Dot_Exchange] = record;
                marketDataRecords[Symbol_Dot]          = record;
                marketDataRecords[Symbol] = record;

                record.Instrument = instrument.Symbol;
                record.Ids.Add(instrument.Id);
                Subscribe(record);
            }
            else
            {
                record.Ids.Add(instrument.Id);
            }
        }
示例#2
0
        private void Unsubscribe(MarketDataRecord record)
        {
            if (IsApiConnected(_MdApi))
            {
                _MdApi.GetLog().Info("退订合约:Symbol:{0};InstrumentID:{1};ExchangeID:{2}", record.Instrument, record.Symbol, record.Exchange);

                _MdApi.Unsubscribe(record.Symbol, record.Exchange);
            }
            if (SubscribeQuote)
            {
                if (IsApiConnected(_QuoteRequestApi))
                {
                    _QuoteRequestApi.UnsubscribeQuote(record.Symbol, record.Exchange);
                }
            }
        }
示例#3
0
        public double FixPrice(MarketDataRecord record, double price, SmartQuant.OrderSide Side, double tickSize)
        {
            double LowerLimitPrice = record.DepthMarket.LowerLimitPrice;
            double UpperLimitPrice = record.DepthMarket.UpperLimitPrice;

            //没有设置就直接用
            if (tickSize > 0)
            {
                decimal remainder = ((decimal)price % (decimal)tickSize);
                if (remainder != 0)
                {
                    if (Side == SmartQuant.OrderSide.Buy)
                    {
                        price = Math.Round(Math.Ceiling(price / tickSize) * tickSize, 6);
                    }
                    else
                    {
                        price = Math.Round(Math.Floor(price / tickSize) * tickSize, 6);
                    }
                }
                else
                {
                    //正好能整除,不操作
                }
            }

            if (0 == UpperLimitPrice &&
                0 == LowerLimitPrice)
            {
                //涨跌停无效
                _TdApi.GetLog().Warn("Symbol:{0},Symbol_Dot_Exchange:{1},LowerLimitPrice && UpperLimitPrice 为0,没有进行价格修正",
                                     record.Symbol, record.Symbol_Dot_Exchange);
            }
            else
            {
                //防止价格超过涨跌停
                if (price >= UpperLimitPrice)
                {
                    price = UpperLimitPrice;
                }
                else if (price <= LowerLimitPrice)
                {
                    price = LowerLimitPrice;
                }
            }
            return(price);
        }
        //public double FixPrice(double price, SmartQuant.OrderSide Side, double tickSize, double LowerLimitPrice, double UpperLimitPrice)
        //{
        //    //没有设置就直接用
        //    if (tickSize > 0)
        //    {
        //        decimal remainder = ((decimal)price % (decimal)tickSize);
        //        if (remainder != 0)
        //        {
        //            if (Side == SmartQuant.OrderSide.Buy)
        //            {
        //                price = Math.Round(Math.Ceiling(price / tickSize) * tickSize, 6);
        //            }
        //            else
        //            {
        //                price = Math.Round(Math.Floor(price / tickSize) * tickSize, 6);
        //            }
        //        }
        //        else
        //        {
        //            //正好能整除,不操作
        //        }
        //    }

        //    if (0 == UpperLimitPrice
        //        && 0 == LowerLimitPrice)
        //    {
        //        //涨跌停无效
                
        //    }
        //    else
        //    {
        //        //防止价格超过涨跌停
        //        if (price >= UpperLimitPrice)
        //            price = UpperLimitPrice;
        //        else if (price <= LowerLimitPrice)
        //            price = LowerLimitPrice;
        //    }
        //    return price;
        //}

        public double FixPrice(MarketDataRecord record,double price, SmartQuant.OrderSide Side, double tickSize)
        {
            double LowerLimitPrice = record.DepthMarket.LowerLimitPrice;
            double UpperLimitPrice = record.DepthMarket.UpperLimitPrice;

            //没有设置就直接用
            if (tickSize > 0)
            {
                decimal remainder = ((decimal)price % (decimal)tickSize);
                if (remainder != 0)
                {
                    if (Side == SmartQuant.OrderSide.Buy)
                    {
                        price = Math.Round(Math.Ceiling(price / tickSize) * tickSize, 6);
                    }
                    else
                    {
                        price = Math.Round(Math.Floor(price / tickSize) * tickSize, 6);
                    }
                }
                else
                {
                    //正好能整除,不操作
                }
            }

            if (0 == UpperLimitPrice
                && 0 == LowerLimitPrice)
            {
                //涨跌停无效
                _TdApi.Log.Warn("Symbol:{0},Symbol_Dot_Exchange:{1},LowerLimitPrice && UpperLimitPrice 为0,没有进行价格修正",
                    record.Symbol,record.Symbol_Dot_Exchange);
            }
            else
            {
                //防止价格超过涨跌停
                if (price >= UpperLimitPrice)
                    price = UpperLimitPrice;
                else if (price <= LowerLimitPrice)
                    price = LowerLimitPrice;
            }
            return price;
        }
        public override void Subscribe(Instrument instrument)
        {
            //Task.Factory.StartNew(() => SubscribeForTest(instrument));
            //return;

            string altSymbol;
            string altExchange;
            string apiSymbol;
            string apiExchange;
            double apiTickSize;

            GetApi_Symbol_Exchange_TickSize(instrument,
                                            out altSymbol, out altExchange,
                                            out apiSymbol, out apiExchange,
                                            out apiTickSize);

            string Symbol_Dot_Exchange = string.Format("{0}.{1}", apiSymbol, apiExchange);
            string Symbol_Dot          = string.Format("{0}.", apiSymbol);
            string Symbol = apiSymbol;

            MarketDataRecord record;

            if (!marketDataRecords.TryGetValue(Symbol_Dot_Exchange, out record))
            {
                record                     = new MarketDataRecord(instrument);
                record.Symbol              = Symbol;
                record.Exchange            = apiExchange;
                record.Symbol_Dot          = Symbol_Dot;
                record.Symbol_Dot_Exchange = Symbol_Dot_Exchange;

                // 可能没有交易所信息
                marketDataRecords[Symbol_Dot_Exchange] = record;
                marketDataRecords[Symbol_Dot]          = record;
                marketDataRecords[Symbol] = record;
            }

            record.TradeRequested       = true;
            record.QuoteRequested       = true;
            record.MarketDepthRequested = true;

            Subscribe(record);
        }
示例#6
0
 private void Subscribe(MarketDataRecord record)
 {
     if (IsApiConnected(_MdApi))
     {
         _MdApi.GetLog().Info("订阅合约:Symbol:{0};InstrumentID:{1};ExchangeID:{2}", record.Instrument, record.Symbol, record.Exchange);
         _MdApi.Subscribe(record.Symbol, record.Exchange);
     }
     else
     {
         EmitError("行情服务器没有连接");
         xlog.Error("行情服务器没有连接");
     }
     if (SubscribeQuote)
     {
         if (IsApiConnected(_QuoteRequestApi))
         {
             _QuoteRequestApi.SubscribeQuote(record.Symbol, record.Exchange);
         }
     }
 }