예제 #1
0
        private ArbitrageOrderSettlement CalculateSettlementResult()
        {
            USeArbitrageOrder arbitrageOrder = null;

            lock (m_syncObj)
            {
                arbitrageOrder = m_arbitrageOrder.Clone();
            }

            List <USeOrderBook> orderBookList = arbitrageOrder.GetAllOrderBooks();

            USeInstrument buyInstrument  = arbitrageOrder.OpenArgument.BuyInstrument;
            USeInstrument sellInstrument = arbitrageOrder.OpenArgument.SellInstrument;

            USeMarketData       buyMarketData        = USeManager.Instance.QuoteDriver.Query(buyInstrument);
            USeMarketData       sellMarketData       = USeManager.Instance.QuoteDriver.Query(sellInstrument);
            USeInstrumentDetail buyInstrumentDetail  = USeManager.Instance.OrderDriver.QueryInstrumentDetail(buyInstrument);
            USeInstrumentDetail sellInstrumentDetail = USeManager.Instance.OrderDriver.QueryInstrumentDetail(sellInstrument);

            decimal buyProfit   = CalculateProfit(orderBookList, buyInstrumentDetail, buyMarketData);
            decimal sellProfit  = CalculateProfit(orderBookList, sellInstrumentDetail, sellMarketData);
            decimal totalProfit = buyProfit + sellProfit;

            ArbitrageOrderSettlement settlemt = new ArbitrageOrderSettlement()
            {
                BuyInstrumentProfit  = buyProfit,
                SellInstrumentProfit = sellProfit,
                Profit = totalProfit
            };

            return(settlemt);
        }
예제 #2
0
 /// <summary>
 /// 订阅行情
 /// </summary>
 /// <param name="products">订阅产品</param>
 public override void Subscribe(USeInstrument instrument)
 {
     lock (m_object)
     {
         m_instrumentDic[instrument.InstrumentCode] = instrument.Clone();
     }
 }
예제 #3
0
        /// <summary>
        /// 获取合约指定交易日日K线。
        /// </summary>
        public USeKLine GetMin1KLine(USeInstrument instrument, DateTime time)
        {
            string strSel = string.Format(@"select * from {0}.{1} 
where contract = '{1}' and date_time = '{3:yyyy-MM-dd HH:mm:00}';",
                                          m_alphaDBName, GetMin1KLineTableName(instrument.Market),
                                          instrument.InstrumentCode, time);

            DataTable table = MySQLDriver.GetTableFromDB(m_dbConnStr, strSel);

            if (table != null && table.Rows.Count > 0)
            {
                DataRow row = table.Rows[0];

                USeKLine kline = new USeKLine()
                {
                    InstrumentCode = row["contract"].ToString(),
                    Market         = USeTraderProtocol.ToUseMarket(row["exchange"].ToString()),
                    Cycle          = USeCycleType.Day,
                    DateTime       = Convert.ToDateTime(row["date_time"]),
                    Open           = row["price_open"].ToDecimal(),
                    High           = row["price_high"].ToDecimal(),
                    Low            = row["price_low"].ToDecimal(),
                    Close          = row["price_close"].ToDecimal(),
                    Volumn         = row["volumn"].ToInt(),
                    Turnover       = row["turnover"].ToDecimal(),
                    OpenInterest   = row["openinterest"].ToDecimal()
                };
                return(kline);
            }

            return(null);
        }
예제 #4
0
        /// <summary>
        /// 获取K线生成器。
        /// </summary>
        /// <param name="instrument"></param>
        /// <returns></returns>
        private List <KLineFactory> GetIndexKLineFactory(USeInstrument instrument)
        {
            Debug.Assert(instrument.Market != USeMarket.Unknown);
            string varieties = USeTraderProtocol.GetVarieties(instrument.InstrumentCode);


            List <KLineFactory> factoryList = null;

            if (m_indexkLineFactoryDic.TryGetValue(varieties, out factoryList) == false)
            {
                USeProduct product = m_productManager.GetPruduct(varieties);

                factoryList = new List <KLineFactory>();
                DayTradeRange tradeRange      = m_tradeRangeManager.CreateTradeRange(varieties);
                DateTime      tradeDay        = tradeRange.GetTradeDay(DateTime.Now);
                USeInstrument indexInstrument = USeTraderProtocol.GetVarietiesIndexCode(product);
                USeKLine      dayKLine        = GetDayKLine(tradeDay, indexInstrument);

                List <USeInstrument> instrumentList = m_instrumentManager.GetAllInstruments(varieties, product.Market);


                IndexDayKLineFactory dayFactory = new IndexDayKLineFactory(product, instrumentList, dayKLine, m_dayKLinePublishInterval, m_kLinePublisher, tradeRange, m_eventLogger, m_instrumentManager);
                factoryList.Add(dayFactory);
                IndexMinKLineFactory min1Factory = new IndexMinKLineFactory(product, instrumentList, USeCycleType.Min1, m_kLinePublisher, tradeRange, m_eventLogger, m_instrumentManager);
                factoryList.Add(min1Factory);

                m_indexkLineFactoryDic.Add(varieties, factoryList);
            }

            Debug.Assert(factoryList != null && factoryList.Count == 2);
            return(factoryList);
        }
        /// <summary>
        /// 更换品种。
        /// </summary>
        /// <param name="product"></param>
        private void ChangegProduct(USeProduct product)
        {
            if (string.IsNullOrEmpty(product.ProductCode))
            {
                return;
            }
            try
            {
                m_instrumentDetailList.Clear();
                m_instrumentList.Clear();

                List <USeInstrumentDetail> instrumentDetailList = USeManager.Instance.OrderDriver.QueryInstrumentDetail(product.ProductCode);
                if (instrumentDetailList == null)
                {
                    return;
                }

                foreach (USeInstrumentDetail instrumentDetail in instrumentDetailList)
                {
                    m_instrumentDetailList.Add(instrumentDetail);

                    USeInstrument instrument = instrumentDetail.Instrument;

                    m_instrumentList.Add(instrument);
                }

                m_product = product;
            }
            catch (Exception ex)
            {
                Debug.Assert(false, ex.Message);
            }
        }
예제 #6
0
        /// <summary>
        /// 获取K线生成器。
        /// </summary>
        /// <param name="instrument"></param>
        /// <returns></returns>
        private List <KLineFactory> GetKLineFactory(USeInstrument instrument)
        {
            Debug.Assert(instrument.Market != USeMarket.Unknown);
            List <KLineFactory> factoryList = null;

            if (m_kLineFactoryDic.TryGetValue(instrument.InstrumentCode, out factoryList) == false)
            {
                factoryList = new List <KLineFactory>();
                DayTradeRange tradeRange    = m_tradeRangeManager.CreateTradeRange(instrument);
                bool          isMainConract = m_mainContractManager.IsMainContract(instrument.InstrumentCode);
                DateTime      tradeDay      = tradeRange.GetTradeDay(DateTime.Now);
                USeKLine      dayKLine      = GetDayKLine(tradeDay, instrument);

                DayKLineFactory dayFactory = new DayKLineFactory(instrument, dayKLine, m_kLinePublisher, tradeRange, m_eventLogger, m_dayKLinePublishInterval, isMainConract, m_instrumentManager);
                factoryList.Add(dayFactory);
                MinKLineFactory min1Factory = new MinKLineFactory(instrument, m_kLinePublisher, tradeRange, m_eventLogger, USeCycleType.Min1, isMainConract);
                factoryList.Add(min1Factory);

                m_kLineFactoryDic.Add(instrument.InstrumentCode, factoryList);
            }

            Debug.Assert(factoryList != null && factoryList.Count == 2);

            return(new List <KLineFactory>(factoryList));
        }
예제 #7
0
 /// <summary>
 /// 构造方法。
 /// </summary>
 /// <param name="instrument">处理合约。</param>
 /// <param name="publisher">发布者。</param>
 /// <param name="tradeRange">交易时段。</param>
 public KLineFactory(USeInstrument instrument, IKLinePublisher publisher, DayTradeRange tradeRange, IAppLogger eventLogger)
 {
     m_instrument  = instrument;
     m_publisher   = publisher;
     m_tradeRange  = tradeRange;
     m_eventLogger = eventLogger;
 }
예제 #8
0
            private decimal InternalCalculateFee(USeInstrument instrument, USeOffsetType offsetType, int qty, decimal price)
            {
                USeFee fee = InternalGetFee(instrument);

                if (fee == null)
                {
                    return(0m);
                }

                int volumeMultiple = InternalGetVolumeMultiple(instrument);

                switch (offsetType)
                {
                case USeOffsetType.Open: return(fee.OpenRatioByMoney * qty * price * volumeMultiple + fee.OpenRatioByVolume * qty);

                case USeOffsetType.CloseHistory:
                case USeOffsetType.Close: return(fee.CloseRatioByMoney * qty * price * volumeMultiple + fee.CloseRatioByVolume * qty);

                case USeOffsetType.CloseToday: return(fee.CloseTodayRatioByMoney * qty * price * volumeMultiple + fee.CloseTodayRatioByVolume * qty);

                default:
                    Debug.Assert(false);
                    return(0m);
                }
            }
예제 #9
0
        /// <summary>
        /// 获取主力合约。
        /// </summary>
        /// <param name="varieties"></param>
        /// <returns></returns>
        public USeInstrument GetMainContract(string varieties)
        {
            USeInstrument instrument = null;

            m_mainContractDic.TryGetValue(varieties, out instrument);
            return(instrument);
        }
예제 #10
0
        /// <summary>
        /// 构造方法。
        /// </summary>
        /// <param name="instrument">合约。</param>
        /// <param name="publisher">发布者。</param>
        /// <param name="tradeRange">交易时段。</param>
        /// <param name="publishInterval">发布间隔(单位:秒)。</param>
        public DayKLineFactory(USeInstrument instrument, USeKLine initKLine, IKLinePublisher publisher, DayTradeRange tradeRange, IAppLogger eventLogger, TimeSpan publishInterval, bool isMainContract, USeTradingInstrumentManager instrumentManager)
            : base(instrument, publisher, tradeRange, eventLogger)
        {
            m_publishInterval = publishInterval;
            m_nextPublishTime = DateTime.Now.AddTicks(publishInterval.Ticks);

            m_isMainContract = isMainContract;

            if (initKLine != null)
            {
                Debug.Assert(initKLine.InstrumentCode == instrument.InstrumentCode);
                m_kLine = initKLine;
            }

            if (isMainContract)
            {
                string varieties = USeTraderProtocol.GetVarieties(instrument.InstrumentCode);
                m_mainContractCode = USeTraderProtocol.GetMainContractCode(varieties, instrument.Market);
            }

            //获取该数据库下的合约详细信息
            try
            {
                Debug.Assert(instrumentManager != null);
                m_insDetailList = instrumentManager.GetAllInstrumentDetails();
            }
            catch (Exception ex)
            {
                throw new Exception("IndexDayKLineFactory 获取全部合约详细信息异常:" + ex.Message);
            }
        }
 /// <summary>
 /// 查询产品行情
 /// </summary>
 /// <param name="product">被查询产品</param>
 /// <returns>被查询产品行情信息</returns>
 public override USeMarketData QuickQuery(USeInstrument product)
 {
     try
     {
         USeMarketData marketData = null;
         lock (m_object)
         {
             m_marketDataDic.TryGetValue(product.InstrumentCode, out marketData);
         }
         if (marketData != null)
         {
             return(marketData.Clone());
         }
         else
         {
             USeMarketData nullMarketData = new USeMarketData();
             nullMarketData.Instrument = product.Clone();
             return(nullMarketData);
         }
     }
     catch (Exception ex)
     {
         m_logger.WriteError(string.Format("{0} QuickQuery failed,Error: {1}.", ToString(), ex.Message));
         USeMarketData nullMarketData = new USeMarketData();
         nullMarketData.Instrument = product.Clone();
         return(nullMarketData);
     }
 }
        private void cbxSellInstrument_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.cbxSellInstrument.SelectedIndex < 0)
            {
                //Debug.Assert(false);
                return;
            }

            USeInstrument sellInstrument = GetSellInstrumentFromUI();

            if (sellInstrument == null || m_sellInstrument == sellInstrument)
            {
                return;
            }

            m_sellInstrument = sellInstrument;
            m_sellMarketData = null;

            try
            {
                USeManager.Instance.QuoteDriver.Subscribe(sellInstrument);
                USeMarketData marketData = USeManager.Instance.QuoteDriver.QuickQuery(sellInstrument);
                UpdateMarketData(marketData);
            }
            catch (Exception ex)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "订阅行情失败," + ex.Message);
            }
            SetPriceControlValue();
        }
예제 #13
0
        /// <summary>
        /// 从数据库中获得合约表。
        /// </summary>
        /// <param name="monitorMarketes"></param>
        /// <returns></returns>
        private List <USeInstrument> GetSubscribeInstruments(List <USeMarket> monitorMarketes)
        {
            List <USeInstrument> instrumentList = new List <USeInstrument>();

            string strSel = string.Format(@"select contract,contract_name,exchange, open_date,expire_date,is_trading from {0}.contracts 
                              where product_class ='Futures' and UNIX_TIMESTAMP(CURDATE()) >= UNIX_TIMESTAMP(open_date) and  UNIX_TIMESTAMP(CURDATE()) <= UNIX_TIMESTAMP(expire_date);", m_dbName);

            DataTable table = new DataTable();

            using (MySqlConnection connection = new MySqlConnection(m_dbConnStr))
            {
                connection.Open();
                MySqlDataAdapter adapter = new MySqlDataAdapter(strSel, connection);
                adapter.Fill(table);
            }

            foreach (DataRow row in table.Rows)
            {
                USeMarket market = (USeMarket)Enum.Parse(typeof(USeMarket), row["exchange"].ToString());

                USeInstrument instrument = new USeInstrument(row["contract"].ToString(),
                                                             row["contract_name"].ToString(),
                                                             market);

                instrumentList.Add(instrument);
            }
            return(instrumentList);
        }
예제 #14
0
        /// <summary>
        /// 委托下单。
        /// </summary>
        /// <param name="instrument">委托产品。</param>
        /// <param name="qty">委托量。</param>
        /// <param name="price">委托价格。</param>
        /// <param name="offsetType">开平仓方向。</param>
        /// <param name="orderSide">买卖方向。</param>
        /// <param name="error">[out]委托失败原因。</param>
        /// <returns>委托单号。</returns>
        /// <remarks>返回为null代表失败,否则为委托单号。</remarks>
        public override USeOrderNum PlaceOrder(USeInstrument instrument, int qty, decimal price, USeOffsetType offsetType, USeOrderSide orderSide, out string error)
        {
            error = "";
            System.Diagnostics.Debug.Assert(instrument != null);

            int orderNumValue = m_orderNumCreateor.Next();

            USeOrderBook orderBook = new USeOrderBook();

            orderBook.OrderNum    = new TestOrderNum(orderNumValue);
            orderBook.Account     = m_investorID;
            orderBook.Instrument  = instrument;
            orderBook.OrderQty    = qty;
            orderBook.OrderPrice  = price;
            orderBook.TradeQty    = 0;
            orderBook.TradeAmount = 0;
            orderBook.TradePrice  = 0;
            orderBook.TradeFee    = 0;
            orderBook.OrderStatus = USeOrderStatus.Unknown;
            orderBook.CancelQty   = 0;
            orderBook.OrderSide   = orderSide;
            orderBook.OffsetType  = offsetType;
            orderBook.Memo        = "";
            orderBook.OrderTime   = DateTime.Now;

            string error_orderInfo = string.Empty;

            VerfiyPlaceOrderToReturn(orderBook, out error_orderInfo);

            if (error_orderInfo == "开仓")
            {
                m_dataBuffer.OrderBookList.Add(orderBook);

                m_pushOrderBookList.Enqueue(orderBook);
                error = "Place Order Ok";

                return(orderBook.OrderNum);
            }
            else if (error_orderInfo == "CloseSuccessed")
            {
                //开仓
                orderBook.Memo = "平仓委托成功";
                m_dataBuffer.OrderBookList.Add(orderBook);

                m_pushOrderBookList.Enqueue(orderBook);
                error = "Place Order Ok";
                return(orderBook.OrderNum);
            }
            else
            {
                //平仓委托失败
                orderBook.Memo        = error_orderInfo;
                orderBook.OrderStatus = USeOrderStatus.BlankOrder;

                m_pushOrderBookList.Enqueue(orderBook);
                error = "Place Order Failed";
                return(orderBook.OrderNum);
            }
        }
예제 #15
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Add_Click(object sender, EventArgs e)
        {
            Debug.Assert(this.listBox_InsOne.Items.Count != 0);
            Debug.Assert(this.listBox_InsTwo.Items.Count != 0);

            USeInstrument firstIns = (USeInstrument)this.listBox_InsOne.SelectedItem;
            USeInstrument SecIns   = (USeInstrument)this.listBox_InsTwo.SelectedItem;


            if (firstIns == null)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "请选择近月合约");
                return;
            }
            if (SecIns == null)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "请选择远月合约");
                return;
            }
            if (firstIns.InstrumentCode == SecIns.InstrumentCode)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "不能选择相同的合约");
                return;
            }

            if (firstIns.InstrumentCode.CompareTo(SecIns.InstrumentCode) > 0)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "请选择较近月的远月合约");
                return;
            }
            else
            {
                ArbitrageCombineInstrument arbitrageCombineInstrument = new ArbitrageCombineInstrument();
                arbitrageCombineInstrument.FirstInstrument  = firstIns;
                arbitrageCombineInstrument.SecondInstrument = SecIns;
                arbitrageCombineInstrument.ProductID        = m_product.ProductCode;

                foreach (object o in this.listBox_ArbitrageIns.Items)
                {
                    ArbitrageCombineInstrument combineInstrument = o as ArbitrageCombineInstrument;
                    if (combineInstrument.FirstInstrument.Equals(arbitrageCombineInstrument.FirstInstrument) &&
                        combineInstrument.SecondInstrument.Equals(arbitrageCombineInstrument.SecondInstrument))
                    {
                        USeFuturesSpiritUtility.ShowWarningMessageBox(this, "已经存在该套利组合合约,不能重复添加");
                        return;
                    }
                }

                //添加到界面
                this.listBox_ArbitrageIns.Items.Add(arbitrageCombineInstrument);

                //添加到内存
                m_arbitrageInstrumentList.Add(arbitrageCombineInstrument);

                //发布添加事件通知
                SafeFireOnArbitrageCombineInsAddChanged(arbitrageCombineInstrument);
            }
        }
        /// <summary>
        /// 更改产品。
        /// </summary>
        /// <param name="product">产品名称。</param>
        public void ChangeProduct(string product)
        {
            if (string.IsNullOrEmpty(product) || m_productId == product)
            {
                return;
            }

            this.cbxBuyInstrument.Items.Clear();
            this.cbxSellInstrument.Items.Clear();

            m_buyInstrument  = null;
            m_sellInstrument = null;
            m_buyMarketData  = null;
            m_sellMarketData = null;
            m_productId      = product;

            SetNoticeInfo();
            try
            {
                List <USeInstrumentDetail> instrumentDetailList = USeManager.Instance.OrderDriver.QueryInstrumentDetail(product);
                if (instrumentDetailList == null)
                {
                    return;
                }

                List <USeInstrument> instrumentList = (from e in instrumentDetailList
                                                       orderby e.Instrument.InstrumentCode
                                                       select e.Instrument).ToList();
                USeInstrument emptyInstrument = new USeInstrument("", "选择合约", USeMarket.Unknown);
                this.cbxBuyInstrument.Items.Add(emptyInstrument);
                this.cbxSellInstrument.Items.Add(emptyInstrument);

                foreach (USeInstrument instrument in instrumentList)
                {
                    this.cbxBuyInstrument.Items.Add(instrument);
                    this.cbxSellInstrument.Items.Add(instrument);
                }

                this.cbxBuyInstrument.SelectedIndex  = 0;
                this.cbxSellInstrument.SelectedIndex = 0;

#if DEBUG
                if (this.cbxBuyInstrument.Items.Count > 2)
                {
                    this.cbxBuyInstrument.SelectedIndex = 1;
                }
                if (this.cbxSellInstrument.Items.Count > 3)
                {
                    this.cbxSellInstrument.SelectedIndex = 2;
                }
#endif
            }
            catch (Exception ex)
            {
                Debug.Assert(false, ex.Message);
            }
        }
예제 #17
0
        /// <summary>
        /// 获取指定品种指定日期成交量最大的合约。[hanyu]2017//11/03修正为持仓量最大
        /// </summary>
        /// <param name="varieties"></param>
        /// <param name="settlementDate"></param>
        /// <returns></returns>
        private string GetMaxVolumeInstrument(USeProduct varieties, DateTime settlementDate)
        {
            string cmdText = string.Format(@"select dk.contract,dk.date_time,dk.openinterest from {0}.day_kline dk
where dk.date_time = '{1:yyyy-MM-dd}' and dk.contract like '{2}%' and dk.exchange = '{3}'
order by dk.openinterest desc,dk.contract asc;",
                                           m_alpahDBName, settlementDate, varieties.ProductCode, varieties.Market.ToString());

            DataTable table = new DataTable();

            using (MySqlConnection connection = new MySqlConnection(m_dbConnStr))
            {
                connection.Open();
                MySqlDataAdapter adapter = new MySqlDataAdapter(cmdText, connection);
                adapter.Fill(table);
                adapter.Dispose();
            }

            if (table != null && table.Rows.Count > 0)
            {
                USeInstrument mainContractCode = USeTraderProtocol.GetMainContractCode(varieties.ProductCode, varieties.Market);
                USeInstrument indexCode        = USeTraderProtocol.GetVarietiesIndexCode(varieties.ProductCode, varieties.Market);

                int    maxOpeninterest = 0;
                string mainContract    = string.Empty;
                foreach (DataRow row in table.Rows)
                {
                    string contract           = row["contract"].ToString();
                    string constractVarieties = USeTraderProtocol.GetVarieties(contract);
                    if (constractVarieties == varieties.ProductCode)
                    {
                        if (contract == mainContractCode.InstrumentCode || contract == indexCode.InstrumentCode)
                        {
                            //过滤掉指数编码和主力合约编码
                            string text = string.Format("{0}@{1:yyyy-MM-dd}计算主力合约被过滤的指数编码和主力合约,{2}", varieties.ProductCode, settlementDate, contract);
                            Debug.WriteLine(text);
                            m_logger.WriteInformation(text);

                            continue;
                        }
                        else
                        {
                            if (Convert.ToInt32(row["openinterest"]) > maxOpeninterest)
                            {
                                maxOpeninterest = Convert.ToInt32(row["openinterest"]);
                                mainContract    = row["contract"].ToString();
                            }
                        }
                    }
                }

                return(mainContract);
            }
            else
            {
                return(string.Empty);
            }
        }
        public bool ContainsInstrument(USeInstrument instument)
        {
            if (this.m_arbitrageCombineInstrument.FirstInstrument.Equals(instument) ||
                this.m_arbitrageCombineInstrument.SecondInstrument.Equals(instument))
            {
                return(true);
            }

            return(false);
        }
예제 #19
0
 private void QuoteListControl1_OnSelectInstrumentChanged(USeInstrument instrument)
 {
     try
     {
         //this.simpleOrderPanelControl1.ChangeInstrument(instrument);
     }
     catch (Exception ex)
     {
     }
 }
        /// <summary>
        /// 获取卖出合约。
        /// </summary>
        /// <returns></returns>
        private USeInstrument GetSellInstrumentFromUI()
        {
            USeInstrument instrument = this.cbxSellInstrument.SelectedItem as USeInstrument;

            if (instrument != null && string.IsNullOrEmpty(instrument.InstrumentCode))
            {
                instrument = null;
            }

            return(instrument);
        }
예제 #21
0
 private USeKLine GetDayKLine(DateTime day, USeInstrument instrument)
 {
     try
     {
         USeKLine kline = m_alphaDBVistor.GetDayKLine(instrument, day);
         return(kline);
     }
     catch (Exception ex)
     {
         m_eventLogger.WriteError(string.Format("获取{0}@{1:yyyy-MM-dd}日K线数据失败,{2}", instrument, day, ex.Message));
         return(null);
     }
 }
예제 #22
0
        /// <summary>
        /// 查询合约的合约乘数。
        /// </summary>
        /// <param name="instrument">合约。</param>
        /// <returns>合约乘数。</returns>
        public override int QueryInstrumentVolumeMultiple(USeInstrument instrument)
        {
            USeInstrumentDetail detail = QueryInstrumentDetail(instrument);

            if (detail != null)
            {
                return(detail.VolumeMultiple);
            }
            else
            {
                return(0);
            }
            //return m_dataBuffer.GetVolumeMultiple(instrument);
        }
        /// <summary>
        /// 是否关心合约。
        /// </summary>
        /// <param name="instrument"></param>
        /// <returns></returns>
        private bool IsMyCareInstrument(USeInstrument instrument)
        {
            if (m_buyInstrument != null && m_buyInstrument == instrument)
            {
                return(true);
            }

            if (m_sellInstrument != null && m_sellInstrument == instrument)
            {
                return(true);
            }

            return(false);
        }
예제 #24
0
 /// <summary>
 /// 退订行情
 /// </summary>
 /// <param name="instrument">退订产品</param>
 public override void Unsubscribe(USeInstrument instrument)
 {
     //try
     //{
     //    string[] instruments = new string[] { instrument.InstrumentCode };
     //    Debug.WriteLine(string.Format("Unsubscribe [{0}].", instrument.InstrumentCode));
     //    m_ctpFeed.UnsubscribeMarketData(instruments);
     //}
     //catch (Exception ex)
     //{
     //    m_logger.WriteError(string.Format("{0} unsubscribeMarketData failed,Error: {1}.", ToString(), ex.Message));
     //    throw ex;
     //}
 }
예제 #25
0
        /// <summary>
        /// 获取优先合约下单价格。
        /// </summary>
        /// <param name="instrument">优先合约。</param>
        /// <param name="orderPriceType">下单价格类型。</param>
        /// <param name="orderSide">买卖方向。</param>
        /// <returns></returns>
        private decimal GetFirstInstrumentOrderPrice(USeInstrument instrument, ArbitrageOrderPriceType orderPriceType, USeOrderSide orderSide)
        {
            USeMarketData marketData = m_quoteDriver.Query(instrument);

            Debug.Assert(marketData != null);

            switch (orderPriceType)
            {
            case ArbitrageOrderPriceType.LastPrice: return(marketData.LastPrice);

            case ArbitrageOrderPriceType.OpponentPrice:
            {
                if (orderSide == USeOrderSide.Buy)
                {
                    return(marketData.AskPrice);
                }
                else if (orderSide == USeOrderSide.Sell)
                {
                    return(marketData.BidPrice);
                }
                else
                {
                    Debug.Assert(false);
                    return(0m);
                }
            }

            case ArbitrageOrderPriceType.QueuePrice:
            {
                if (orderSide == USeOrderSide.Buy)
                {
                    return(marketData.BidPrice);
                }
                else if (orderSide == USeOrderSide.Sell)
                {
                    return(marketData.AskPrice);
                }
                else
                {
                    Debug.Assert(false);
                    return(0m);
                }
            }

            default:
                Debug.Assert(false);
                return(0m);
            }
        }
예제 #26
0
        /// <summary>
        /// 初始化合约。
        /// </summary>
        private void InitializeInstrument()
        {
            this.cbxNearInstrument.Items.Clear();
            this.cbxFarInstrument.Items.Clear();
            this.cbxNearInstrument.DisplayMember = "InstrumentCode";
            this.cbxNearInstrument.DisplayMember = "InstrumentCode";

            if (m_product != null)
            {
                List <USeInstrumentDetail> instrumentList = USeManager.Instance.OrderDriver.QueryInstrumentDetail(m_product.ProductCode);
                foreach (USeInstrumentDetail item in instrumentList)
                {
                    this.cbxNearInstrument.Items.Add(item.Instrument);
                    this.cbxFarInstrument.Items.Add(item.Instrument);
                }
            }

            USeInstrument nearInstrument = null;
            USeInstrument farInstrument  = null;

            if (m_arbitrageArgument != null)
            {
                nearInstrument = m_arbitrageArgument.NearInstrument;
                farInstrument  = m_arbitrageArgument.FarInstrument;
            }
            else if (m_combineInstrument != null)
            {
                nearInstrument = m_combineInstrument.FirstInstrument;
                farInstrument  = m_combineInstrument.SecondInstrument;
            }

            if (nearInstrument != null)
            {
                this.cbxNearInstrument.SelectedItem = nearInstrument;
            }
            else if (this.cbxNearInstrument.Items.Count > 0)
            {
                this.cbxNearInstrument.SelectedIndex = 0;
            }

            if (farInstrument != null)
            {
                this.cbxFarInstrument.SelectedItem = farInstrument;
            }
            else if (this.cbxFarInstrument.Items.Count > 1)
            {
                this.cbxFarInstrument.SelectedIndex = 1;
            }
        }
예제 #27
0
        /// <summary>
        /// 查询合约保证金。
        /// </summary>
        /// <param name="instrument"></param>
        /// <returns></returns>
        public override USeMargin QueryInstrumentMargin(USeInstrument instrument)
        {
            USeMargin margin = new USeMargin()
            {
                Instrument = instrument.Clone(),
                ExchangeLongMarginRatio        = 0.09m,
                ExchangeShortMarginRatio       = 0.09m,
                BrokerLongMarginRatioByMoney   = 0.09m,
                BrokerLongMarginRatioByVolume  = 0,
                BrokerShortMarginRatioByMoney  = 0.09m,
                BrokerShortMarginRatioByVolume = 0
            };

            return(margin);
        }
예제 #28
0
 public void ChangeInstrument(USeInstrument instrument)
 {
     if (instrument == null)
     {
         return;
     }
     lock (m_syncObj)
     {
         m_selectedInstrument = instrument;
         this.comboBoxInstrument.SelectedItem = instrument;
     }
     //信息清空
     this.numericUpDownPrice.Value  = 0;
     this.numericUpDownVolume.Value = 0;
 }
예제 #29
0
        /// <summary>
        /// 校验近远月合约选项
        /// </summary>
        /// <param name="errorMessage"></param>
        /// <returns></returns>
        private bool VerifyCombineInstrumentArgument(out string errorMessage)
        {
            errorMessage = "";

            USeInstrument nearInstrument = this.cbxNearInstrument.SelectedItem as USeInstrument;
            USeInstrument farInstrument  = this.cbxFarInstrument.SelectedItem as USeInstrument;

            if (nearInstrument.InstrumentCode.CompareTo(farInstrument.InstrumentCode) >= 0)
            {
                errorMessage = "请选择正确的近月合约和远月合约";
                return(false);
            }

            return(true);
        }
예제 #30
0
        /// <summary>
        /// 远月合约组合框选择更改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Cbx_FarInstrumentSelectChanged(object sender, EventArgs e)
        {
            USeInstrument instrument = this.cbxFarInstrument.SelectedItem as USeInstrument;

            Debug.Assert(instrument != null);
            try
            {
                USeManager.Instance.QuoteDriver.Subscribe(instrument);
            }
            catch (Exception ex)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "行情订阅异常:" + ex.Message);
                return;
            }
        }