示例#1
0
        private void UseSystemConfigForm_Load(object sender, EventArgs e)
        {
            try
            {
                USeSystemSetting setting = USeManager.Instance.SystemConfigManager.GetSystemSetting();
                Debug.Assert(setting != null);

                switch (setting.MarketPriceMethods)
                {
                case USeMarketPriceMethod.OpponentPrice: this.rbnMarketPriceMethod_OpponentPrice.Checked = true; break;

                case USeMarketPriceMethod.OnePriceTick: this.rbnMarketPriceMethod_OnePriceTick.Checked = true; break;

                case USeMarketPriceMethod.TwoPriceTick: this.rbnMarketPriceMethod_TwoPriceTick.Checked = true; break;

                case USeMarketPriceMethod.ThreePriceTick: this.rbnMarketPriceMethod_ThreePriceTick.Checked = true; break;
                }

                this.txtTaskOrder_TaskMaxTryCount.Text     = setting.TaskOrder.TaskMaxTryCount.ToString();
                this.txtTaskOrder_TryOrderMinInterval.Text = ((int)setting.TaskOrder.TryOrderMinInterval.TotalMilliseconds).ToString();

                this.txtOrderMargin_MaxUseRate.Text = (setting.OrderMargin.MaxUseRate * 100).ToString();
            }
            catch (Exception ex)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "加载系统配置信息失败," + ex.Message);
            }
        }
        private bool VerifyDataCheck(FrontSeverConfigViewModel data)
        {
            Debug.Assert(data != null);

            bool conditionStrIsNull = data.BrokerID == string.Empty ||
                                      data.BrokerName == string.Empty ||
                                      data.QuoteFrontAddress == string.Empty ||
                                      data.TradeFrontAddress == string.Empty;

            if (conditionStrIsNull)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "有选项为空,请填入信息......");
                return(false);
            }

            if (data.QuoteFrontPort <= 0 || data.QuoteFrontPort >= 65535)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "请填入正确的行情端口号......");
                return(false);
            }

            if (data.TradeFrontPort <= 0 || data.TradeFrontPort >= 65535)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "请填入正确的交易端口号......");
                return(false);
            }

            return(true);
        }
        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();
        }
示例#4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            MessageBox.Show("开仓参数不允许修改");
            return;

            string errorMessage           = string.Empty;
            ArbitrageOpenArgument openArg = this.arbitrageOrderOpenArgumentViewControl1.GetOpenArgument(out errorMessage);

            if (openArg == null)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, errorMessage);
                return;
            }

            try
            {
                m_autoTrader.SetOpenArgument(openArg);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            this.DialogResult = DialogResult.Yes;
            this.Close();
        }
        /// <summary>
        /// 添加预警
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_AddNotify_Click(object sender, EventArgs e)
        {
            ArbitragePriceSpreadAlarmType monitorType = this.arbitragePriceSpreadMonitorTypeControl.MonitorType;
            PriceSpreadSide priceSpreadSide           = this.priceSpreadSideControl_Alarm.PriceSpreadSide;
            decimal         threshold = this.nudPriceSpreadThreshold_Alarm.Value;

            ArbitrageAlarmArgument args = new ArbitrageAlarmArgument();

            args.MonitorType          = monitorType;
            args.PriceSpreadSide      = priceSpreadSide;
            args.PriceSpreadThreshold = threshold;

            ArbitrageAlarmArgumentViewModel model    = ArbitrageAlarmArgumentViewModel.CreatViewModel(args);
            ArbitrageAlarmArgumentViewModel hasModel = (from m in m_dataSourceAlarm
                                                        where m.Equals(model)
                                                        select m).FirstOrDefault();

            if (hasModel != null)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "不能添加重复的预警");
                return;
            }

            m_dataSourceAlarm.Add(ArbitrageAlarmArgumentViewModel.CreatViewModel(args));
        }
        /// <summary>
        /// 撤单-选中的表中特定的委托单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_CancelOrder_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection rows_collection = this.gridOrder.SelectedRows;

            if (rows_collection.Count == 0)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "请选中可撤的委托单...");
                return;
            }
            ;

            foreach (DataGridViewRow row in rows_collection)
            {
                OrderBookViewModel orderBookView = row.DataBoundItem as OrderBookViewModel;
                if (orderBookView.IsFinish)
                {
                    USeFuturesSpiritUtility.ShowWarningMessageBox(this, "选中的委托单不可撤...");
                    return;
                }
                string error_info = string.Empty;
                bool   bResult    = USeManager.Instance.OrderDriver.CancelOrder(orderBookView.OrderNum, orderBookView.Instrument, out error_info);
                if (bResult == false)
                {
                    USeFuturesSpiritUtility.ShowWarningMessageBox(this, error_info);
                }
            }
        }
        /// <summary>
        /// 点击移除。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            int count = this.listBox_ArbitrageIns.Items.Count;

            if (count <= 0)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "套利组合合约列表为空");
                return;
            }
            else if (this.listBox_ArbitrageIns.SelectedItems.Count == 0)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "请选择需要从套利组合列表中移除的组合合约");
                return;
            }

            ArbitrageCombineInstrument combineIns = this.listBox_ArbitrageIns.SelectedItem as ArbitrageCombineInstrument;

            //控件删除
            this.listBox_ArbitrageIns.Items.Remove(combineIns);

            //内存删除
            Debug.Assert(m_arbitrageInstrumentList.Contains(combineIns));
            m_arbitrageInstrumentList.Remove(combineIns);

            //发布移除事件
            SafeFireOnArbitrageCombineInsRemoveChanged(combineIns);
        }
        private void button_User_Click(object sender, EventArgs e)
        {
            //对外发布更改事件
            SafeFireOnArbitrageCombineInsChanged(m_arbitrageInstrumentList);

            USeFuturesSpiritUtility.ShowWarningMessageBox(this, "已保存设置,可继续操作");
            return;
        }
        /// <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);
            }
        }
 private void tsmiOpen_CancelOrder_Click(object sender, EventArgs e)
 {
     try
     {
         m_autoTrader.CancelOpenHangingOrder();
     }
     catch (Exception ex)
     {
         USeFuturesSpiritUtility.ShowWarningMessageBox(this, ex.Message);
     }
 }
示例#11
0
        private void btnQuery_Click(object sender, EventArgs e)
        {
            List <ArbitrageOrderBookViewModel> modelList = CreateViewModelList();

            this.gridArbitrage.AutoGenerateColumns = false;
            this.gridArbitrage.DataSource          = modelList;
            if (modelList == null || modelList.Count <= 0)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "未找到历史套利单");
            }
        }
        /// <summary>
        /// 套利组合下单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpenArbitrageOrder_Click(object sender, EventArgs e)
        {
            string errorMessage = "";

            if (CheckArgument(out errorMessage) == false)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "[套利参数设定]" + "\n" + errorMessage);
                return;
            }

            if (CreateNewArbitrageOrder())
            {
                this.Close();
            }
        }
        /// <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;
            }
        }
        /// <summary>
        /// 移除预警
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_CancelNotify_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection selectRows = this.gridAlarmCondition.SelectedRows;

            if (selectRows == null || selectRows.Count == 0)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "请选择要移除的预警");
                return;
            }
            ;

            foreach (DataGridViewRow row in selectRows)
            {
                ArbitrageAlarmArgumentViewModel model = row.DataBoundItem as ArbitrageAlarmArgumentViewModel;
                m_dataSourceAlarm.Remove(model);
            }
        }
        /// <summary>
        /// 确定按键。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Ok_Click(object sender, EventArgs e)
        {
            //存文件,成功之后发布事件;存文件失败继续修改
            Debug.Assert(m_arbitrageInstrumentList != null);

            bool iDataAccesserStore = ArbitrageInstrumentsDataAccesserStore(m_arbitrageInstrumentList);

            if (iDataAccesserStore == false)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "保存套利合约单设置失败,请重试");
                return;
            }

            SafeFireOnArbitrageCombineInsChanged(m_arbitrageInstrumentList);

            this.DialogResult = DialogResult.Yes;
            this.Close();
        }
        /// <summary>
        /// 近远月比较
        /// </summary>
        /// <param name="firIns"></param>
        /// <param name="secIns"></param>
        /// <returns></returns>
        private bool CompareExpireDateSecUpperFir(USeInstrument nearInstrument, USeInstrument farInstrument)
        {
            if (nearInstrument == null || farInstrument == null)
            {
                return(false);
            }

            try
            {
                string productIDFir = USeTraderProtocol.GetVarieties(nearInstrument.InstrumentCode);
                string ProductIDSec = USeTraderProtocol.GetVarieties(farInstrument.InstrumentCode);
                Debug.Assert(productIDFir.Equals(ProductIDSec));

                List <USeInstrumentDetail> instrumentDetailList = USeManager.Instance.OrderDriver.QueryInstrumentDetail(productIDFir);

                USeInstrumentDetail nearDetail = (from d in instrumentDetailList
                                                  where nearInstrument.InstrumentCode == d.Instrument.InstrumentCode
                                                  select d).FirstOrDefault();

                USeInstrumentDetail farDetail = (from d in instrumentDetailList
                                                 where farInstrument.InstrumentCode == d.Instrument.InstrumentCode
                                                 select d).FirstOrDefault();

                Debug.Assert(nearDetail != null);
                Debug.Assert(farDetail != null);

                if (nearDetail.ExpireDate >= farDetail.ExpireDate)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "合约设定有误" + ex.Message);
                return(false);
            }
        }
示例#17
0
        private List <USeArbitrageOrder> LoadHistoryArbitrageOrderList()
        {
            //读取所有历史套利单信息
            List <USeArbitrageOrder> USeArbitrageOrderList = new List <USeArbitrageOrder>();

            try
            {
                Debug.Assert(USeManager.Instance.LoginUser != null);
                string brokerId = USeManager.Instance.LoginUser.BrokerId;
                string account  = USeManager.Instance.LoginUser.Account;

                DateTime?beginTime = null;
                if (this.dateTimePicker1.Checked)
                {
                    beginTime = this.dateTimePicker1.Value.Date;
                }
                DateTime?endTime = null;
                if (this.dateTimePicker2.Checked)
                {
                    endTime = this.dateTimePicker2.Value.Date.AddDays(1);
                }

                List <USeArbitrageOrder> HistoryArbitrageOrdersList = USeManager.Instance.DataAccessor.GetHistoryArbitrageOrders(brokerId, account, beginTime, endTime);

                if (HistoryArbitrageOrdersList == null)
                {
                    return(USeArbitrageOrderList);
                }
                else
                {
                    return(HistoryArbitrageOrdersList);
                }
            }
            catch (Exception ex)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "LoadHistoryArbitrageOrderList error :" + ex.Message);
                return(USeArbitrageOrderList);
            }
        }
        private void buttonOrder_Click(object sender, EventArgs e)
        {
            if (this.comboBoxInstrument.Text == string.Empty)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "合约项为空,请选入合约信息");
                return;
            }

            if (this.numericUpDownPrice.Value <= 0)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "价格为不能为0或负数");
                return;
            }

            if (this.numericUpDownVolume.Value <= 0)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "数量不能为0或负数");
                return;
            }

            decimal orderPrice = 0m;

            if (m_freshOrderPrice)
            {
                orderPrice = GetMarketOrderPrice();
            }
            else
            {
                orderPrice = this.numericUpDownPrice.Value;
            }

            string      error_info = string.Empty;
            USeOrderNum orderNum   = USeManager.Instance.OrderDriver.PlaceOrder(m_selectedInstrument, (int)this.numericUpDownVolume.Value, GetMarketOrderPrice(), GetChoiceOffsetType(), GetChoiceDirection(), out error_info);

            if (orderNum == null)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, error_info);
            }
        }
        private void btnStartOrStop_Click(object sender, EventArgs e)
        {
            try
            {
                this.btnStartOrStop.Enabled = false;

                if (m_autoTrader.State == AutoTraderState.Disable)
                {
                    Debug.Assert(this.btnStartOrStop.Text == "启动");
                    m_autoTrader.StartOpenOrCloseMonitor();
                    //启动
                }
                else if (m_autoTrader.State == AutoTraderState.Enable)
                {
                    Debug.Assert(this.btnStartOrStop.Text == "停止");
                    m_autoTrader.StopOpenOrCloseMonitor();
                }
            }
            catch (Exception ex)
            {
                this.btnStartOrStop.Enabled = true;
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, ex.Message);
            }
        }
示例#20
0
        /// <summary>
        /// 撤单-所有委托单中的未成交单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_CancelAllOrders_Click(object sender, EventArgs e)
        {
            List <USeOrderBook> orderBookList = USeManager.Instance.OrderDriver.QueryOrderBooks();

            List <USeOrderBook> allCancelOrdersList = new List <USeOrderBook>();

            foreach (USeOrderBook orderBook in orderBookList)
            {
                if (orderBook.IsFinish)
                {
                    continue;
                }
                allCancelOrdersList.Add(orderBook);
            }

            if (allCancelOrdersList.Count == 0)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "未查询到委托单可撤...");
                return;
            }

            CancelOrdersForm cancelOrderForm = new CancelOrdersForm(allCancelOrdersList);

            if (DialogResult.OK == cancelOrderForm.ShowDialog())
            {
                foreach (USeOrderBook orderCancel in allCancelOrdersList)
                {
                    string error_info = string.Empty;
                    bool   bResult    = USeManager.Instance.OrderDriver.CancelOrder(orderCancel.OrderNum, orderCancel.Instrument, out error_info);
                    if (bResult == false)
                    {
                        USeFuturesSpiritUtility.ShowWarningMessageBox(this, error_info);
                    }
                }
            }
        }
示例#21
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            USeMarketPriceMethod marketPriceMethod = USeMarketPriceMethod.Unknown;

            if (this.rbnMarketPriceMethod_OpponentPrice.Checked)
            {
                marketPriceMethod = USeMarketPriceMethod.OpponentPrice;
            }
            else if (this.rbnMarketPriceMethod_OnePriceTick.Checked)
            {
                marketPriceMethod = USeMarketPriceMethod.OnePriceTick;
            }
            else if (this.rbnMarketPriceMethod_TwoPriceTick.Checked)
            {
                marketPriceMethod = USeMarketPriceMethod.TwoPriceTick;
            }
            else if (this.rbnMarketPriceMethod_ThreePriceTick.Checked)
            {
                marketPriceMethod = USeMarketPriceMethod.ThreePriceTick;
            }
            else
            {
                USeFuturesSpiritUtility.ShowInformationMessageBox(this, "请选择市价定义");
                return;
            }

            int taskMaxTryCount = 0;

            if (int.TryParse(this.txtTaskOrder_TaskMaxTryCount.Text, out taskMaxTryCount) == false)
            {
                USeFuturesSpiritUtility.ShowInformationMessageBox(this, "请输入正确的下单设定-最大尝试次数");
                this.txtTaskOrder_TaskMaxTryCount.Focus();
                return;
            }
            if (taskMaxTryCount <= 0 || taskMaxTryCount > 20)
            {
                USeFuturesSpiritUtility.ShowInformationMessageBox(this, "请输入正确的下单设定-最大尝试次数,合法范围[1~20]");
                this.txtTaskOrder_TaskMaxTryCount.Focus();
                return;
            }

            int tryOrderMinInterval = 0;

            if (int.TryParse(this.txtTaskOrder_TryOrderMinInterval.Text, out tryOrderMinInterval) == false)
            {
                USeFuturesSpiritUtility.ShowInformationMessageBox(this, "请输入正确的下单设定-两次下单最小间隔");
                this.txtTaskOrder_TaskMaxTryCount.Focus();
                return;
            }
            if (tryOrderMinInterval < 0)
            {
                USeFuturesSpiritUtility.ShowInformationMessageBox(this, "请输入正确的下单设定-两次下单最小间隔");
                this.txtTaskOrder_TaskMaxTryCount.Focus();
                return;
            }

            decimal maxMarginUseRate = 0;

            if (decimal.TryParse(this.txtOrderMargin_MaxUseRate.Text, out maxMarginUseRate) == false)
            {
                USeFuturesSpiritUtility.ShowInformationMessageBox(this, "请输入正确的套利单保证金占用最大比例,合法范围(0~100]");
                return;
            }
            if (maxMarginUseRate <= 0 || maxMarginUseRate > 100)
            {
                USeFuturesSpiritUtility.ShowInformationMessageBox(this, "套利单保证金占用最大比例");
                return;
            }
            maxMarginUseRate = maxMarginUseRate / 100m;

            try
            {
                USeSystemSetting setting = new USeSystemSetting();
                setting.MarketPriceMethods = marketPriceMethod;

                setting.TaskOrder = new TaskOrderSetting()
                {
                    TaskMaxTryCount     = taskMaxTryCount,
                    TryOrderMinInterval = new TimeSpan(0, 0, 0, 0, tryOrderMinInterval)
                };

                setting.OrderMargin = new OrderMarginSetting()
                {
                    MaxUseRate = maxMarginUseRate
                };

                USeManager.Instance.SystemConfigManager.SaveSystemSetting(setting);
            }
            catch (Exception ex)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, ex.Message);
                return;
            }

            this.DialogResult = DialogResult.Yes;
            this.Close();
        }
示例#22
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            List <ErrorUSeOrderBook> result = new List <ErrorUSeOrderBook>();

            try
            {
                //如果存在未被处理的委托单,提示处理
                foreach (DataRow row in m_dataTable.Rows)
                {
                    string errorMessage = string.Empty;
                    if (IsMatchRule(row, out errorMessage) == false)
                    {
                        USeFuturesSpiritUtility.ShowErrrorMessageBox(this, "请处理异常委托单");
                        return;
                    }
                }

                USeOrderDriver orderDriver = USeManager.Instance.OrderDriver;
                Debug.Assert(orderDriver != null);

                //根据界面生成结果保存到Result
                foreach (DataRow row in m_dataTable.Rows)
                {
                    USeInstrument instrument = row["Instrument"] as USeInstrument;
                    Debug.Assert(instrument != null);

                    USeInstrumentDetail instrumentDetail = orderDriver.QueryInstrumentDetail(instrument);
                    //[yangming]合约过期后可能查不到了,此处可以考虑用品种信息获取合约乘数
                    Debug.Assert(instrumentDetail != null);
                    int orderQty  = Convert.ToInt32(row["OrderQty"]);
                    int tradeQty  = Convert.ToInt32(row["TradeQty"]);
                    int cancelQty = orderQty - tradeQty;
                    Debug.Assert(cancelQty >= 0);

                    decimal tradePrice  = Convert.ToDecimal(row["TradePrice"]);
                    decimal tradeFee    = Convert.ToDecimal(row["TradeFee"]);
                    decimal tradeAmount = tradePrice * tradeQty * instrumentDetail.VolumeMultiple;

                    USeOrderStatus selectedOrderStatus = (USeOrderStatus)row["SelectedOrderStatus"];
                    USeOrderStatus status = USeOrderStatus.Unknown;
                    if (selectedOrderStatus == USeOrderStatus.AllTraded)
                    {
                        status = USeOrderStatus.AllTraded;
                    }
                    else if (selectedOrderStatus == USeOrderStatus.AllCanceled)
                    {
                        if (cancelQty == orderQty)
                        {
                            status = USeOrderStatus.AllCanceled;
                        }
                        else
                        {
                            status = USeOrderStatus.PartCanceled;
                        }
                    }

                    USeOrderNum       orderNum      = row["OrderNum"] as USeOrderNum;
                    ErrorUSeOrderBook erroOrderBook = row["ErrorUSeOrderBook"] as ErrorUSeOrderBook;
                    erroOrderBook.OrderBook.OrderStatus = status;
                    erroOrderBook.OrderBook.CancelQty   = cancelQty;
                    erroOrderBook.OrderBook.TradeQty    = tradeQty;
                    erroOrderBook.OrderBook.TradePrice  = tradePrice;
                    erroOrderBook.OrderBook.TradeAmount = tradeAmount;
                    erroOrderBook.OrderBook.TradeFee    = tradeFee;

                    result.Add(erroOrderBook);
                }

                this.Result = result;
            }
            catch (Exception ex)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, ex.Message);
                return;
            }

            this.DialogResult = DialogResult.Yes;
            this.Close();
        }
示例#23
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            List <ArbitrageCombineOrderSetting> arbitrageCombineOrderList = new List <ArbitrageCombineOrderSetting>();

            try
            {
                //保存之前数据校验
                foreach (DataRow row in m_dataTable.Rows)
                {
                    string errorMessage = string.Empty;
                    if (VerifyDataTable(row, out errorMessage) == false)
                    {
                        USeFuturesSpiritUtility.ShowErrrorMessageBox(this, "请填写完整的默认信息:" + errorMessage);
                        return;
                    }
                }

                //根据界面生成结果保存
                foreach (DataRow row in m_dataTable.Rows)
                {
                    string productCode = row["ProductName"] as string;
                    Debug.Assert(productCode != string.Empty);

                    int openVolumn    = Convert.ToInt32(row["OpenVolumn"]);
                    int perOpenVolumn = Convert.ToInt32(row["PerOpenVolumn"]);

                    USeDirection openDirection = (USeDirection)row["OpenFirstDirectionID"];

                    USeDirection closeDirection    = (USeDirection)row["CloseFirstDirectionID"];
                    USeDirection stoplossDirection = (USeDirection)row["StopLossFirstDirectionID"];

                    ArbitrageOrderPriceType nearOpenPriceStyle = (ArbitrageOrderPriceType)row["NearOpenPriceStyleID"];
                    ArbitrageOrderPriceType farOpenPriceStyle  = (ArbitrageOrderPriceType)row["FarOpenPriceStyleID"];

                    ArbitrageCombineOrderSetting order = new ArbitrageCombineOrderSetting();
                    USeProduct product = new USeProduct()
                    {
                        ProductCode = productCode
                    };
                    order.Product = product;

                    order.OpenVolumn             = openVolumn;
                    order.OpenVolumnPerNum       = perOpenVolumn;
                    order.OpenFirstDirection     = openDirection;
                    order.CloseFirstDirection    = closeDirection;
                    order.StoplossFirstDirection = stoplossDirection;
                    order.NearPriceStyle         = nearOpenPriceStyle;
                    order.FarPriceStyle          = farOpenPriceStyle;

                    arbitrageCombineOrderList.Add(order);
                }
            }
            catch (Exception ex)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, ex.Message);
                return;
            }

            string brokerId = USeManager.Instance.LoginUser.BrokerId;
            string account  = USeManager.Instance.LoginUser.Account;

            USeManager.Instance.DataAccessor.SaveCombineOrderSettings(brokerId, account, arbitrageCombineOrderList);

            this.DialogResult = DialogResult.Yes;
            this.Close();
        }
        private void btnOpenArbitrageOrder_Click(object sender, EventArgs e)
        {
            string errorMessage = string.Empty;

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

            USeInstrument buyInstrument  = this.cbxBuyInstrument.SelectedItem as USeInstrument;
            USeInstrument sellInstrument = this.cbxSellInstrument.SelectedItem as USeInstrument;

            ArbitrageOrderPriceType buyOrderPriceType  = GetBuyOrderPriceTypeFromUI();
            ArbitrageOrderPriceType sellOrderPriceType = GetSellOrderPriceTypeFromUI();
            USeOrderSide            preferentialSide   = GetPreferentialSideFromUI();
            PriceSpreadSide         priceSpreadSide    = GetPriceSpreadSideFromUI();

            ArbitrageOpenArgument openArg = new ArbitrageOpenArgument();

            openArg.BuyInstrument = buyInstrument;
            openArg.BuyInstrumentOrderPriceType = buyOrderPriceType;
            openArg.SellInstrument = sellInstrument;
            openArg.SellInstrumentOrderPriceType = sellOrderPriceType;
            openArg.PreferentialSide             = preferentialSide;
            openArg.OpenCondition = new PriceSpreadCondition()
            {
                PriceSpreadSide      = priceSpreadSide,
                PriceSpreadThreshold = this.nudPriceSpreadThreshold.Value
            };
            openArg.TotalOrderQty    = (int)this.nudTotalOrderQty.Value;
            openArg.OrderQtyUint     = (int)this.nudOrderQtyUint.Value;
            openArg.DifferentialUnit = (int)this.nudDifferentialUnit.Value;

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

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

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

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

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

            //    USeManager.Instance.DataSaver.AddSaveTask(trader.GetArbitrageOrder());
            //}
            //catch (Exception ex)
            //{
            //    USeFuturesSpiritUtility.ShowWarningMessageBox(this, ex.Message);
            //    return;
            //}
        }
        /// <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);
        }