private void UpdatePriceLable()
        {
            decimal nearPrice = 0m;
            decimal farPrice  = 0m;

            ArbitrageOperationSide  operationSide      = this.arbitrageOperationSideControl.OperationSide;
            ArbitrageOrderPriceType nearOrderPriceType = this.orderPriceTypeControl_OpenNearArg.OrderPriceType;
            ArbitrageOrderPriceType farOrderPriceType  = this.orderPriceTypeControl_OpenFarArg.OrderPriceType;

            if (operationSide == ArbitrageOperationSide.BuyNearSellFar)
            {
                nearPrice = GetOrderPrice(m_nearMarketData, nearOrderPriceType, USeOrderSide.Buy);
                farPrice  = GetOrderPrice(m_farMarketData, farOrderPriceType, USeOrderSide.Sell);
            }
            else if (operationSide == ArbitrageOperationSide.SellNearBuyFar)
            {
                nearPrice = GetOrderPrice(m_nearMarketData, nearOrderPriceType, USeOrderSide.Sell);
                farPrice  = GetOrderPrice(m_farMarketData, farOrderPriceType, USeOrderSide.Buy);
            }

            this.lblNearInstrumentPrice.Text = nearPrice > 0m ? nearPrice.ToString() : "---";
            this.lblFarInstrumentPrice.Text  = farPrice > 0m ? farPrice.ToString() : "---";

            if (nearPrice > 0m && farPrice >= 0m)
            {
                decimal diffPrice = (nearPrice - farPrice);
                this.lblPriceSpread.Text      = diffPrice.ToString();
                this.lblPriceSpread.ForeColor = diffPrice >= 0m ? Color.Red : Color.Green;
            }
            else
            {
                this.lblPriceSpread.Text = "---";
            }
        }
Example #2
0
        public static ArbitrageOperationSide GetOppositeSide(this ArbitrageOperationSide operationSide)
        {
            switch (operationSide)
            {
            case ArbitrageOperationSide.SellNearBuyFar: return(ArbitrageOperationSide.BuyNearSellFar);

            case ArbitrageOperationSide.BuyNearSellFar: return(ArbitrageOperationSide.SellNearBuyFar);

            default: return(ArbitrageOperationSide.Unknown);
            }
        }
Example #3
0
        public static string ToDescription(this ArbitrageOperationSide operationSide)
        {
            switch (operationSide)
            {
            case ArbitrageOperationSide.SellNearBuyFar: return("卖近买远");

            case ArbitrageOperationSide.BuyNearSellFar: return("买近卖远");

            default: return("未知");
            }
        }
Example #4
0
        private void SafeFireArbitrageOperationSideChanged(ArbitrageOperationSide operationSide)
        {
            ArbitrageOperationChangedEventHandle handle = this.OnArbitrageOperationSideChanged;

            if (handle != null)
            {
                try
                {
                    handle(operationSide);
                }
                catch (Exception ex)
                {
                    Debug.Assert(false, ex.Message);
                }
            }
        }
        private decimal GetSecondTaskOrderPrice(ArbitrageOperationSide operationSide, USeOrderSide preferentialSide, decimal firstSubTaskAvgTradePrice, decimal priceSpread)
        {
            Debug.Assert(firstSubTaskAvgTradePrice > 0);

            if (operationSide == ArbitrageOperationSide.BuyNearSellFar)
            {
                if (preferentialSide == USeOrderSide.Buy)
                {
                    return(firstSubTaskAvgTradePrice - priceSpread);
                }
                else if (preferentialSide == USeOrderSide.Sell)
                {
                    return(firstSubTaskAvgTradePrice + priceSpread);
                }
                else
                {
                    Debug.Assert(false);
                }
            }
            else if (operationSide == ArbitrageOperationSide.SellNearBuyFar)
            {
                if (preferentialSide == USeOrderSide.Buy)
                {
                    return(firstSubTaskAvgTradePrice + priceSpread);
                }
                else if (preferentialSide == USeOrderSide.Sell)
                {
                    return(firstSubTaskAvgTradePrice - priceSpread);
                }
                else
                {
                    Debug.Assert(false);
                }
            }

            throw new Exception("无法计算反手子任务下单价格");
        }
        private void arbitrageOperationSideControl1_OnArbitrageOperationSideChanged(ArbitrageOperationSide operationSide)
        {
            switch (operationSide)
            {
            case ArbitrageOperationSide.SellNearBuyFar:
            {
                this.priceSpreadSideControl_OpenSpreadArg.PriceSpreadSide  = PriceSpreadSide.GreaterOrEqual;
                this.priceSpreadSideControl_CloseSpreadArg.PriceSpreadSide = PriceSpreadSide.LessOrEqual;
                this.priceSpreadSideControl_StopLossArg.PriceSpreadSide    = PriceSpreadSide.GreaterOrEqual;
                break;
            }

            case ArbitrageOperationSide.BuyNearSellFar:
            {
                this.priceSpreadSideControl_OpenSpreadArg.PriceSpreadSide  = PriceSpreadSide.LessOrEqual;
                this.priceSpreadSideControl_CloseSpreadArg.PriceSpreadSide = PriceSpreadSide.GreaterOrEqual;
                this.priceSpreadSideControl_StopLossArg.PriceSpreadSide    = PriceSpreadSide.LessOrEqual;
                break;
            }

            default:
                break;
            }
        }
        /// <summary>
        /// 创建组合套利单下单参数
        /// </summary>
        private bool CreateNewArbitrageOrder()
        {
            USeInstrument          nearInstrument = this.cbxNearInstrument.SelectedItem as USeInstrument;
            USeInstrument          farInstrument  = this.cbxFarInstrument.SelectedItem as USeInstrument;
            ArbitrageOperationSide operationSide  = this.arbitrageOperationSideControl.OperationSide;

            ArbitrageOpenArgument openArg = new ArbitrageOpenArgument();

            if (operationSide == ArbitrageOperationSide.BuyNearSellFar)
            {
                openArg.BuyInstrument  = nearInstrument;
                openArg.SellInstrument = farInstrument;
                openArg.BuyInstrumentOrderPriceType  = this.orderPriceTypeControl_OpenNearArg.OrderPriceType;
                openArg.SellInstrumentOrderPriceType = this.orderPriceTypeControl_OpenFarArg.OrderPriceType;
            }
            else if (operationSide == ArbitrageOperationSide.SellNearBuyFar)
            {
                openArg.BuyInstrument  = farInstrument;
                openArg.SellInstrument = nearInstrument;
                openArg.BuyInstrumentOrderPriceType  = this.orderPriceTypeControl_OpenFarArg.OrderPriceType;
                openArg.SellInstrumentOrderPriceType = this.orderPriceTypeControl_OpenNearArg.OrderPriceType;
            }
            else
            {
                Debug.Assert(false);
            }
            openArg.NearOrderPriceType = this.orderPriceTypeControl_OpenNearArg.OrderPriceType;
            openArg.FarOrderPriceType  = this.orderPriceTypeControl_OpenFarArg.OrderPriceType;

            openArg.PreferentialSide = this.preferentialSideControl_OpenArg.PreferentialSide;
            openArg.OpenCondition    = new PriceSpreadCondition()
            {
                PriceSpreadSide      = this.priceSpreadSideControl_OpenSpreadArg.PriceSpreadSide,
                PriceSpreadThreshold = this.nudPriceSpreadThreshold_OpenArg.Value
            };
            openArg.TotalOrderQty    = (int)this.nudTotalOrderQty_OpenArg.Value;
            openArg.OrderQtyUint     = (int)this.nudOrderQtyUint_OpenArg.Value;
            openArg.DifferentialUnit = (int)this.nudDifferentialUnit_OpenArg.Value;


            ArbitrageCloseArgument closeArg = new ArbitrageCloseArgument();

            if (operationSide == ArbitrageOperationSide.BuyNearSellFar)
            {
                closeArg.BuyInstrument  = farInstrument;
                closeArg.SellInstrument = nearInstrument;
                closeArg.BuyInstrumentOrderPriceType  = this.orderPriceTypeControl_CloseFarArg.OrderPriceType;
                closeArg.SellInstrumentOrderPriceType = this.orderPriceTypeControl_CloseNearArg.OrderPriceType;
            }
            else if (operationSide == ArbitrageOperationSide.SellNearBuyFar)
            {
                closeArg.BuyInstrument  = nearInstrument;
                closeArg.SellInstrument = farInstrument;
                closeArg.BuyInstrumentOrderPriceType  = this.orderPriceTypeControl_CloseNearArg.OrderPriceType;
                closeArg.SellInstrumentOrderPriceType = this.orderPriceTypeControl_CloseFarArg.OrderPriceType;
            }
            closeArg.NearOrderPriceType = this.orderPriceTypeControl_CloseNearArg.OrderPriceType;
            closeArg.FarOrderPriceType  = this.orderPriceTypeControl_CloseFarArg.OrderPriceType;

            closeArg.PreferentialSide = this.preferentialSideControl_CloseArg.PreferentialSide;
            closeArg.CloseCondition   = new PriceSpreadCondition()
            {
                PriceSpreadSide      = this.priceSpreadSideControl_CloseSpreadArg.PriceSpreadSide,
                PriceSpreadThreshold = this.nudPriceSpreadThreshold_CloseArg.Value
            };
            closeArg.OrderQtyUint     = (int)this.nudOrderQtyUint_CloseArg.Value;
            closeArg.DifferentialUnit = (int)this.nudDifferentialUnit_CloseArg.Value;

            ArbitrageStopLossArgument stopLossArg = null;

            if (this.cbxStopLossFlag.Checked)
            {
                stopLossArg = new ArbitrageStopLossArgument();
                stopLossArg.StopLossCondition = new PriceSpreadCondition()
                {
                    PriceSpreadSide      = this.priceSpreadSideControl_StopLossArg.PriceSpreadSide,
                    PriceSpreadThreshold = this.nudPriceSpreadThreshold_StopLossArg.Value
                };
            }


            List <ArbitrageAlarmArgument> alarmArgList = new List <ArbitrageAlarmArgument>();

            if (m_dataSourceAlarm != null && m_dataSourceAlarm.Count > 0)
            {
                foreach (ArbitrageAlarmArgumentViewModel alarmView in m_dataSourceAlarm)
                {
                    alarmArgList.Add(ArbitrageAlarmArgumentViewModel.CreatAlarmData(alarmView));
                }
            }

            ArbitrageArgument argument = new ArbitrageArgument();

            argument.ProductID      = m_product.ProductCode;
            argument.NearInstrument = nearInstrument;
            argument.FarInstrument  = farInstrument;
            argument.OperationSide  = operationSide;

            argument.OpenArg     = openArg;
            argument.CloseArg    = closeArg;
            argument.StopLossArg = stopLossArg;
            argument.AlarmArgs   = alarmArgList;

            string errorMessage = string.Empty;

            if (VerifyMargin(argument.OpenArg, out errorMessage) == false)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, errorMessage);
                return(false);
            }

            decimal evaluateMargin = EvaluateMargin(argument.OpenArg);
            string  text           = string.Format("套利单预计占用保证金 {0},确定跟单么?", evaluateMargin.ToString("#,0"));

            if (DialogResult.Yes != USeFuturesSpiritUtility.ShowYesNoMessageBox(this, text))
            {
                return(false);
            }

            try
            {
                AutoTraderManager traderManager = USeManager.Instance.AutoTraderManager;
                Debug.Assert(traderManager != null);

                AutoTrader trader = traderManager.CreateNewAutoTrader(argument, USeManager.Instance.LoginUser);
                trader.BeginOpen();
                //[yangming]创建后应该启动跟单
                trader.StartOpenOrCloseMonitor();

                USeManager.Instance.DataSaver.AddSaveTask(trader.GetArbitrageOrder());

                //同时保存所有的ArbitrageArgument便于下次修改
            }
            catch (Exception ex)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, ex.Message);
                return(false);
            }

            return(true);
        }
Example #8
0
 private void btnBuyNearSellFar_Click(object sender, EventArgs e)
 {
     this.OperationSide = ArbitrageOperationSide.BuyNearSellFar;
 }