Ejemplo n.º 1
0
        /// <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);
                }
            }
        }
        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();
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
 private void BindData()
 {
     try
     {
         if (m_arbitrageOrder != null)
         {
             if (m_arbitrageOrder.State <= ArbitrageOrderState.Opened)
             {
                 this.tabControl1.SelectedTab = this.tpOpen;
             }
             else
             {
                 this.tabControl1.SelectedTab = this.tpClose;
             }
             this.Text = string.Format("套利单 [{0}] 详情", m_arbitrageOrder.Alias);
             this.arbitrageCloseArgumentView2Control1.SetCloseArgument(m_arbitrageOrder.CloseArgument);
             this.arbitrageOpenArgumentView2Control1.SetOpenArgument(m_arbitrageOrder.OpenArgument);
             this.openTaskGroupView.SetDataSource(m_arbitrageOrder.OpenTaskGroup);
             this.closeTaskGroupView.SetDataSource(m_arbitrageOrder.CloseTaskGroup);
         }
     }
     catch (Exception ex)
     {
         USeFuturesSpiritUtility.ShowErrrorMessageBox(this, ex.Message);
     }
 }
Ejemplo n.º 8
0
        /// <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));
        }
Ejemplo n.º 9
0
        private void SetDefaultAribtrageArgument()
        {
            ArbitrageCombineOrderSetting combineSetting = null;

            try
            {
                string brokerId = USeManager.Instance.LoginUser.BrokerId;
                string account  = USeManager.Instance.LoginUser.Account;
                combineSetting = USeManager.Instance.DataAccessor.GetCombineOrderSetting(brokerId, account, m_product.ProductCode);
            }
            catch (Exception ex)
            {
                USeFuturesSpiritUtility.ShowErrrorMessageBox(this, "获取套利下单参数异常:" + ex.Message);
                return;
            }

            if (combineSetting == null)
            {
                combineSetting = CreateDefaultCombineOrderSetting();
            }

            //开仓参数
            this.preferentialSideControl_OpenArg.PreferentialSide     = (combineSetting.OpenFirstDirection == USeDirection.Long) ? USeOrderSide.Buy : USeOrderSide.Sell;
            this.orderPriceTypeControl_OpenNearArg.OrderPriceType     = combineSetting.NearPriceStyle;
            this.orderPriceTypeControl_OpenFarArg.OrderPriceType      = combineSetting.FarPriceStyle;
            this.priceSpreadSideControl_OpenSpreadArg.PriceSpreadSide = PriceSpreadSide.LessOrEqual;
            this.nudPriceSpreadThreshold_OpenArg.Value = 0;
            this.nudDifferentialUnit_OpenArg.Value     = 0;
            this.nudOrderQtyUint_OpenArg.Value         = combineSetting.OpenVolumnPerNum;
            this.nudTotalOrderQty_OpenArg.Value        = combineSetting.OpenVolumn;

            //平仓参数
            this.preferentialSideControl_CloseArg.PreferentialSide     = (combineSetting.CloseFirstDirection == USeDirection.Long) ? USeOrderSide.Buy : USeOrderSide.Sell;
            this.orderPriceTypeControl_CloseNearArg.OrderPriceType     = combineSetting.NearPriceStyle;
            this.orderPriceTypeControl_CloseFarArg.OrderPriceType      = combineSetting.FarPriceStyle;
            this.priceSpreadSideControl_CloseSpreadArg.PriceSpreadSide = PriceSpreadSide.LessOrEqual;
            this.nudPriceSpreadThreshold_CloseArg.Value = 0;
            this.nudDifferentialUnit_CloseArg.Value     = 0;

            //止损
            this.priceSpreadSideControl_StopLossArg.PriceSpreadSide = PriceSpreadSide.LessOrEqual;
            this.nudPriceSpreadThreshold_StopLossArg.Value          = 0;

            //预警
            this.arbitragePriceSpreadMonitorTypeControl.MonitorType = ArbitragePriceSpreadAlarmType.Open;
            this.nudPriceSpreadThreshold_Alarm.Value = 0;

#if DEBUG
            this.arbitrageOperationSideControl.OperationSide = ArbitrageOperationSide.BuyNearSellFar;
            this.nudPriceSpreadThreshold_OpenArg.Value       = -50;
            this.nudPriceSpreadThreshold_CloseArg.Value      = -70;
            this.nudPriceSpreadThreshold_StopLossArg.Value   = -30;
            this.nudTotalOrderQty_OpenArg.Value     = 10;
            this.nudDifferentialUnit_OpenArg.Value  = 2;
            this.nudDifferentialUnit_CloseArg.Value = 2;
            this.nudOrderQtyUint_OpenArg.Value      = 2;
            this.nudOrderQtyUint_CloseArg.Value     = 2;
#endif
        }
Ejemplo n.º 10
0
        private void button_User_Click(object sender, EventArgs e)
        {
            //对外发布更改事件
            SafeFireOnArbitrageCombineInsChanged(m_arbitrageInstrumentList);

            USeFuturesSpiritUtility.ShowWarningMessageBox(this, "已保存设置,可继续操作");
            return;
        }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
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, "未找到历史套利单");
            }
        }
 private void tsmiOpen_StopOpenChaseOrder_Click(object sender, EventArgs e)
 {
     try
     {
         m_autoTrader.StopOpenChaseOrder();
     }
     catch (Exception ex)
     {
         USeFuturesSpiritUtility.ShowErrrorMessageBox(this, ex.Message);
     }
 }
 private void tsmiOpen_ForceOpenFinish_Click(object sender, EventArgs e)
 {
     try
     {
         m_autoTrader.ForceOpenFinish();
     }
     catch (Exception ex)
     {
         USeFuturesSpiritUtility.ShowErrrorMessageBox(this, ex.Message);
     }
 }
 private void tsmiOpen_CancelOrder_Click(object sender, EventArgs e)
 {
     try
     {
         m_autoTrader.CancelOpenHangingOrder();
     }
     catch (Exception ex)
     {
         USeFuturesSpiritUtility.ShowWarningMessageBox(this, ex.Message);
     }
 }
Ejemplo n.º 16
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            List <FrontSeverConfig> serverList   = new List <FrontSeverConfig>();
            GlobalFontServerConfig  globalConfig = new GlobalFontServerConfig();

            try
            {
                foreach (FrontSeverConfigViewModel data in m_dataSource)
                {
                    if (VerifyDataCheck(data) == false)
                    {
                        return;
                    }

                    FrontSeverConfig itemConfig = new FrontSeverConfig();
                    itemConfig.BrokerID          = data.BrokerID;                            //经纪商代码
                    itemConfig.BrokerName        = data.BrokerName;                          //经纪商
                    itemConfig.QuoteFrontAddress = data.QuoteFrontAddress;                   //行情地址
                    itemConfig.QuoteFrontPort    = data.QuoteFrontPort;                      //行情端口
                    itemConfig.TradeFrontAddress = data.TradeFrontAddress;                   //交易地址
                    itemConfig.TradeFrontPort    = data.TradeFrontPort;                      //交易端口
                    itemConfig.AuthCode          = data.AuthCode;
                    itemConfig.UserProductInfo   = data.UserProductInfo;
                    serverList.Add(itemConfig);
                }

                globalConfig.ServerList = serverList;

                if (serverList.Count > 0)
                {
                    globalConfig.DefaultBrokerId = serverList[serverList.Count - 1].BrokerID;
                }
            }
            catch (Exception ex)
            {
                USeFuturesSpiritUtility.ShowErrrorMessageBox(this, "保存服务信息失败," + ex.Message);
                return;
            }

            try
            {
                USeManager.Instance.DataAccessor.SaveGlobalFontServerConfig(globalConfig);
            }
            catch (Exception ex)
            {
                USeFuturesSpiritUtility.ShowErrrorMessageBox(this, "保存服务信息失败," + ex.Message);
                return;
            }

            this.DialogResult = DialogResult.Yes;
            this.Close();
        }
 private void tsmClose_TransferToHistory_Click(object sender, EventArgs e)
 {
     try
     {
         m_autoTrader.TransferToHistoryArbitrage();
         System.Threading.Thread.Sleep(200);  // [yangming]加个延时,防止还未保存文件
         USeManager.Instance.AutoTraderManager.RemoveAutoTrader(m_autoTrader.TraderIdentify);
     }
     catch (Exception ex)
     {
         USeFuturesSpiritUtility.ShowErrrorMessageBox(this, ex.Message);
     }
 }
Ejemplo n.º 18
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (USeManager.Instance.AutoTraderManager.HasUnfinishOrderBook())
     {
         string text = "当前有挂单中的委托单,退出后可能不能正常处理套利单状态";
         if (DialogResult.Yes != USeFuturesSpiritUtility.ShowYesNoMessageBox(this, text))
         {
             e.Cancel = true;
             return;
         }
     }
     this.investorFundControl1.Stop();
     this.arbitrageOrderListControl1.Stop();
 }
Ejemplo n.º 19
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;
            }
        }
Ejemplo n.º 20
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                m_orderDriver.SettlementInfoConfirm();
            }
            catch (Exception ex)
            {
                USeFuturesSpiritUtility.ShowErrrorMessageBox(this, "结算单确认失败," + ex.Message);
                return;
            }

            this.DialogResult = DialogResult.Yes;
            this.Close();
        }
Ejemplo n.º 21
0
        /// <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();
            }
        }
Ejemplo n.º 22
0
        /// <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);
            }
        }
Ejemplo n.º 23
0
        /// <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();
        }
Ejemplo n.º 24
0
        /// <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);
            }
        }
Ejemplo n.º 25
0
        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);
            }
        }
Ejemplo n.º 26
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);
            }
        }
Ejemplo n.º 27
0
        private void ArbitrageQuoteChoiceForm_Load(object sender, EventArgs e)
        {
            try
            {
                Initialize();

                InitializeAccountInfo();

                InitializeProductCombox();

                //先到文件中读取所有之前存在的品种套利组合
                m_arbitrageInstrumentList = GetArbitrageCombineInsList();

                //默认品种选择
                SetDefultProduct();
            }
            catch (Exception ex)
            {
                Debug.Assert(false, ex.Message);
                USeFuturesSpiritUtility.ShowErrrorMessageBox(this, ex.Message);
                this.Close();
            }
        }
Ejemplo n.º 28
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);
                    }
                }
            }
        }
        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);
            }
        }
Ejemplo n.º 30
0
        /// <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);
        }