Example #1
0
        /// <summary>
        /// 检查交易账户是否有效
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        private bool CheckTraderAvalible(out string errMsg)
        {
            bool result = CheckFuncTraderAvalible(this.accountFundTypeId, out errMsg);

            if (result)
            {
                if (request.BuySell == Types.TransactionDirection.Selling)
                {
                    result = CheckHoldTraderAvalible(this.accountHoldTypeId, out errMsg);
                }
            }

            if (result)
            {
                HK_SpotCosts hkSpotCots = MCService.HKTradeRulesProxy.GetSpotCostsByBreedClassID(breedClass.BreedClassID);
                if (hkSpotCots != null)
                {
                    currencyTypeID = hkSpotCots.CurrencyTypeID.Value;
                }
                else
                {
                    errMsg = "GT-1207:无法获取港股交易费用实体,获取不到交易币种";
                    LogHelper.WriteInfo(errMsg);
                }
            }

            return(result);
        }
        /// <summary>
        /// 获取港股交易费用
        /// </summary>
        /// <param name="request">港股委托</param>
        /// <returns>港股交易费用结果</returns>
        public static HKCostResult ComputeHKCost(HKOrderRequest request)
        {
            int?         bc     = MCService.CommonPara.GetBreedClassIdByCommodityCode(request.Code, Types.BreedClassTypeEnum.HKStock);
            HKCostResult result = null;

            if (!bc.HasValue)
            {
                return(null);
            }
            int breedClassID = bc.Value;

            HK_SpotCosts cost = MCService.HKTradeRulesProxy.GetSpotCostsByBreedClassID(breedClassID);

            if (cost == null)
            {
                return(null);
            }
            try
            {
                result = InternalComputeHKCost(request, cost);
            }
            catch (Exception ex)
            {
                string      errCode   = "GT-1701";
                string      errMsg    = "无法获取港股交易费用。";
                VTException exception = new VTException(errCode, errMsg, ex);
                LogHelper.WriteError(exception.ToString(), exception);
                throw exception;
            }

            return(result);
        }
        /// <summary>
        /// 根据港股委托单和港股交易费用规则统计交易费用实体
        /// </summary>
        /// <param name="request">委托单</param>
        /// <param name="cost">交易费用规则</param>
        /// <returns>返回港股交易费统计实体</returns>
        private static HKCostResult InternalComputeHKCost(HKOrderRequest request, HK_SpotCosts cost)
        {
            CM_BreedClass breedClass = MCService.CommonPara.GetBreedClassByCommodityCode(request.Code, Types.BreedClassTypeEnum.HKStock);

            HKCostResult result = new HKCostResult();

            result.Code = request.Code;

            decimal orderPrice = (decimal)request.OrderPrice;

            decimal scale = MCService.GetTradeUnitScale(Types.BreedClassTypeEnum.HKStock, request.Code, request.OrderUnitType);
            //以计价单位计算的委托量
            var orderAmount = (decimal)request.OrderAmount * scale;

            //成交额
            var dealAmount = orderPrice * orderAmount;

            #region 1.印花税
            /// 1.印花税
            decimal stamp = cost.StampDuty.Value / 100;

            decimal stampStart = cost.StampDutyStartingpoint.Value;

            if (cost.StampDutyTypeID.HasValue)
            {
                int stampType = cost.StampDutyTypeID.Value;

                decimal stampVal = stamp * dealAmount;
                if (stampVal < stampStart)
                {
                    stampVal = stampStart;
                }
                stampVal = Utils.Round(stampVal);

                switch ((Types.GetValueTypeEnum)stampType)
                {
                case Types.GetValueTypeEnum.Single:
                    break;

                case Types.GetValueTypeEnum.Scope:
                    break;

                case Types.GetValueTypeEnum.Turnover:
                    break;

                case Types.GetValueTypeEnum.Thigh:
                    break;

                case Types.GetValueTypeEnum.SingleBuy:
                    if (request.BuySell == Types.TransactionDirection.Buying)
                    {
                        result.StampDuty = stampVal;
                    }
                    break;

                case Types.GetValueTypeEnum.SingleSell:
                    if (request.BuySell == Types.TransactionDirection.Selling)
                    {
                        result.StampDuty = stampVal;
                    }
                    break;

                case Types.GetValueTypeEnum.TwoEdge:
                    result.StampDuty = stampVal;
                    break;

                case Types.GetValueTypeEnum.No:
                    break;

                default:
                    break;
                }
            }
            #endregion

            #region 2.佣金
            /// 2.佣金
            if (cost.Commision.HasValue)
            {
                decimal comm      = cost.Commision.Value / 100;
                decimal commVal   = comm * dealAmount;
                decimal commStart = 0;
                if (cost.CommisionStartingpoint.HasValue)
                {
                    commStart = cost.CommisionStartingpoint.Value;
                }
                if (commVal < commStart)
                {
                    commVal = commStart;
                }
                commVal          = Utils.Round(commVal);
                result.Commision = commVal;
            }
            #endregion

            #region 过户费
            /// 3.过户费
            if (cost.TransferToll.HasValue)
            {
                decimal transVal = cost.TransferToll.Value / 100;
                transVal            = Utils.Round(transVal);
                result.TransferToll = transVal;
            }
            #endregion

            #region 4.交易手续费
            #region old code
            ///// 4.交易手续费
            ////public decimal PoundageSingleValue { get; set; }
            //if (cost.GetValueTypeID.HasValue)
            //{
            //    int poundType = cost.GetValueTypeID.Value;

            //    //交易手续费单值 single double
            //    switch (poundType)
            //    {
            //        case (int)Types.GetValueTypeEnum.Single:
            //            decimal pound = cost.PoundageValue.Value / 100;
            //            decimal poundValue = pound * dealAmount;
            //            poundValue = Utils.Round(poundValue);
            //            result.PoundageSingleValue = poundValue;
            //            break;
            //        case (int)Types.GetValueTypeEnum.Scope:
            //            IList<XH_SpotRangeCost> costs =
            //                MCService.SpotTradeRules.GetSpotRangeCostByBreedClassID(breedClass.BreedClassID);

            //            foreach (XH_SpotRangeCost spotRangeCost in costs)
            //            {
            //                int fieldRangeID = spotRangeCost.FieldRangeID;
            //                decimal pound2 = spotRangeCost.Value.Value;
            //                pound2 = Utils.Round(pound2);

            //                CM_FieldRange fieldRange = MCService.GetFieldRange(fieldRangeID);

            //                //是否在当前字段范围内
            //                bool isExist = MCService.CheckFieldRange(dealAmount, fieldRange);
            //                if (isExist)
            //                {
            //                    result.PoundageSingleValue = pound2;
            //                    break;
            //                }
            //            }
            //            break;
            //    }
            //}
            #endregion

            decimal pound      = cost.PoundageValue.Value / 100;
            decimal poundValue = dealAmount * pound;
            poundValue = Utils.Round(poundValue);
            result.PoundageSingleValue = poundValue;

            #endregion

            #region  5.监管费
            /// 5.监管费
            //public decimal MonitoringFee { get; set; }
            if (cost.MonitoringFee.HasValue)
            {
                decimal monitor    = cost.MonitoringFee.Value / 100;
                decimal monitorVal = monitor * dealAmount;
                monitorVal = Utils.Round(monitorVal);

                result.MonitoringFee = monitorVal;
            }
            #endregion

            #region  6.结算费(无)
            /// 6.结算费
            result.ClearingFees = 0;
            #endregion

            #region 7.交易系统使用费
            /// 7.交易系统使用费
            if (cost.SystemToll.HasValue)
            {
                result.TradeSystemFees = cost.SystemToll.Value;
            }
            #endregion

            string format = "港股费用计算[代码={0},价格={1},数量={2},单位={3},方向={4}]";
            string desc   = string.Format(format, request.Code, request.OrderPrice, request.OrderAmount,
                                          request.OrderUnitType, request.BuySell);
            LogHelper.WriteDebug(desc + result);
            return(result);
        }
Example #4
0
        /// <summary>
        /// 确定按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            //通过状态值来进行判断是进行那种操作 1:添加 2:修改
            if (m_EditType == 1)
            {
                #region 添加操作

                try
                {
                    if (
                        HKManageCommon.ExistsHKSpotCosts(
                            ((UComboItem)this.cmbBreedClassID.SelectedItem).ValueIndex))
                    {
                        ShowMessageBox.ShowInformation("此品种的交易费用已存在!");
                        return;
                    }
                    HK_SpotCosts hK_SpotCosts = new HK_SpotCosts();
                    if (!string.IsNullOrEmpty(this.cmbBreedClassID.Text))
                    {
                        hK_SpotCosts.BreedClassID = ((UComboItem)this.cmbBreedClassID.SelectedItem).ValueIndex;
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("品种名称不能为空!");
                        return;
                    }
                    hK_SpotCosts.CurrencyTypeID  = ((UComboItem)this.cmbCurrencyType.SelectedItem).ValueIndex;
                    hK_SpotCosts.StampDutyTypeID = ((UComboItem)this.cmbStampDutyType.SelectedItem).ValueIndex;
                    if (!string.IsNullOrEmpty(this.txtStampDuty.Text)) //印花税
                    {
                        if (InputTest.DecimalTest(this.txtStampDuty.Text))
                        {
                            hK_SpotCosts.StampDuty = Convert.ToDecimal(this.txtStampDuty.Text);
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        //hK_SpotCosts.StampDuty = 0; // AppGlobalVariable.INIT_DECIMAL;
                        ShowMessageBox.ShowInformation("印花税不能为空!");
                        return;
                    }
                    if (!string.IsNullOrEmpty(this.txtStampDutyStartpoint.Text)) //印花税起点
                    {
                        if (InputTest.DecimalTest(this.txtStampDutyStartpoint.Text))
                        {
                            hK_SpotCosts.StampDutyStartingpoint = Convert.ToDecimal(this.txtStampDutyStartpoint.Text);
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        hK_SpotCosts.StampDutyStartingpoint = 0;       //默认为0
                    }
                    if (!string.IsNullOrEmpty(this.txtCommision.Text)) //佣金
                    {
                        if (InputTest.DecimalTest(this.txtCommision.Text))
                        {
                            hK_SpotCosts.Commision = Convert.ToDecimal(this.txtCommision.Text); //null;
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        //hK_SpotCosts.Commision = 0; //
                        ShowMessageBox.ShowInformation("佣金不能为空!");
                        return;
                    }
                    if (!string.IsNullOrEmpty(this.txtCommisionStartpoint.Text)) //佣金起点
                    {
                        if (InputTest.DecimalTest(this.txtCommisionStartpoint.Text))
                        {
                            hK_SpotCosts.CommisionStartingpoint = Convert.ToDecimal(this.txtCommisionStartpoint.Text);
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        hK_SpotCosts.CommisionStartingpoint = 0;           // //默认为0AppGlobalVariable.INIT_DECIMAL;
                    }
                    if (!string.IsNullOrEmpty(this.txtPoundageValue.Text)) //交易费
                    {
                        if (InputTest.DecimalTest(this.txtPoundageValue.Text))
                        {
                            hK_SpotCosts.PoundageValue = Convert.ToDecimal(this.txtPoundageValue.Text);
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("交易费不能为空!");
                        return;
                    }
                    if (!string.IsNullOrEmpty(this.txtMonitoringFee.Text)) //监管费
                    {
                        if (InputTest.DecimalTest(this.txtMonitoringFee.Text))
                        {
                            hK_SpotCosts.MonitoringFee = Convert.ToDecimal(this.txtMonitoringFee.Text);
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("监管费不能为空!");
                        return;
                    }
                    if (!string.IsNullOrEmpty(this.txtSystemToll.Text)) //交易系统使用费
                    {
                        if (InputTest.DecimalTest(this.txtSystemToll.Text))
                        {
                            hK_SpotCosts.SystemToll = Convert.ToDecimal(this.txtSystemToll.Text);
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("交易系统使用费不能为空!");
                        return;
                    }

                    if (!string.IsNullOrEmpty(this.txtTransferToll.Text)) //过户费
                    {
                        if (InputTest.DecimalTest(this.txtTransferToll.Text))
                        {
                            hK_SpotCosts.TransferToll = Convert.ToDecimal(this.txtTransferToll.Text);
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        hK_SpotCosts.TransferToll = 0; //默认为0
                    }
                    m_Result = HKManageCommon.AddHKSpotCosts(hK_SpotCosts);
                    if (m_Result)
                    {
                        ShowMessageBox.ShowInformation("添加成功!");
                        this.ClearAll();
                        this.QueryHKCosts();
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("添加失败!");
                    }
                }
                catch (Exception ex)
                {
                    string      errCode   = "GL-7803";
                    string      errMsg    = "添加港股交易费用失败!";
                    VTException exception = new VTException(errCode, errMsg, ex);
                    LogHelper.WriteError(exception.ToString(), exception.InnerException);
                    return;
                }

                #endregion 添加操作
            }
            else if (m_EditType == 2)
            {
                #region 修改操作

                try
                {
                    HK_SpotCosts hK_SpotCosts = new HK_SpotCosts();
                    hK_SpotCosts.BreedClassID    = ((UComboItem)this.cmbBreedClassID.SelectedItem).ValueIndex; //品种名称不能修改
                    hK_SpotCosts.CurrencyTypeID  = ((UComboItem)this.cmbCurrencyType.SelectedItem).ValueIndex;
                    hK_SpotCosts.StampDutyTypeID = ((UComboItem)this.cmbStampDutyType.SelectedItem).ValueIndex;
                    if (!string.IsNullOrEmpty(this.txtStampDuty.Text)) //印花税
                    {
                        if (InputTest.DecimalTest(this.txtStampDuty.Text))
                        {
                            hK_SpotCosts.StampDuty = Convert.ToDecimal(this.txtStampDuty.Text);
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        //hK_SpotCosts.StampDuty = 0; // AppGlobalVariable.INIT_DECIMAL;
                        ShowMessageBox.ShowInformation("印花税不能为空!");
                        return;
                    }
                    if (!string.IsNullOrEmpty(this.txtStampDutyStartpoint.Text)) //印花税起点
                    {
                        if (InputTest.DecimalTest(this.txtStampDutyStartpoint.Text))
                        {
                            hK_SpotCosts.StampDutyStartingpoint = Convert.ToDecimal(this.txtStampDutyStartpoint.Text);
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        hK_SpotCosts.StampDutyStartingpoint = 0;       //默认为0
                    }
                    if (!string.IsNullOrEmpty(this.txtCommision.Text)) //佣金
                    {
                        if (InputTest.DecimalTest(this.txtCommision.Text))
                        {
                            hK_SpotCosts.Commision = Convert.ToDecimal(this.txtCommision.Text); //null;
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        //hK_SpotCosts.Commision = 0; //
                        ShowMessageBox.ShowInformation("佣金不能为空!");
                        return;
                    }
                    if (!string.IsNullOrEmpty(this.txtCommisionStartpoint.Text)) //佣金起点
                    {
                        if (InputTest.DecimalTest(this.txtCommisionStartpoint.Text))
                        {
                            hK_SpotCosts.CommisionStartingpoint = Convert.ToDecimal(this.txtCommisionStartpoint.Text);
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        hK_SpotCosts.CommisionStartingpoint = 0;           ////默认为0 AppGlobalVariable.INIT_DECIMAL;
                    }
                    if (!string.IsNullOrEmpty(this.txtPoundageValue.Text)) //交易费
                    {
                        if (InputTest.DecimalTest(this.txtPoundageValue.Text))
                        {
                            hK_SpotCosts.PoundageValue = Convert.ToDecimal(this.txtPoundageValue.Text);
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("交易费不能为空!");
                        return;
                    }
                    if (!string.IsNullOrEmpty(this.txtMonitoringFee.Text)) //监管费
                    {
                        if (InputTest.DecimalTest(this.txtMonitoringFee.Text))
                        {
                            hK_SpotCosts.MonitoringFee = Convert.ToDecimal(this.txtMonitoringFee.Text);
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("监管费不能为空!");
                        return;
                    }
                    if (!string.IsNullOrEmpty(this.txtSystemToll.Text)) //交易系统使用费
                    {
                        if (InputTest.DecimalTest(this.txtSystemToll.Text))
                        {
                            hK_SpotCosts.SystemToll = Convert.ToDecimal(this.txtSystemToll.Text);
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("交易系统使用费不能为空!");
                        return;
                    }

                    if (!string.IsNullOrEmpty(this.txtTransferToll.Text)) //过户费
                    {
                        if (InputTest.DecimalTest(this.txtTransferToll.Text))
                        {
                            hK_SpotCosts.TransferToll = Convert.ToDecimal(this.txtTransferToll.Text);
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        hK_SpotCosts.TransferToll = 0; //默认为0
                    }
                    m_Result = HKManageCommon.UpdateHKSpotCosts(hK_SpotCosts);
                    if (m_Result)
                    {
                        ShowMessageBox.ShowInformation("修改成功!");
                        this.ClearAll();
                        this.QueryHKCosts();
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("修改失败!");
                    }
                }
                catch (Exception ex)
                {
                    string      errCode   = "GL-7804";
                    string      errMsg    = "修改港股交易费用失败!";
                    VTException exception = new VTException(errCode, errMsg, ex);
                    LogHelper.WriteError(exception.ToString(), exception.InnerException);
                    return;
                }

                #endregion 修改操作
            }
        }