/// <summary>
        /// 获取股指期货交易费用
        /// </summary>
        /// <param name="request">股指期货委托</param>
        /// <returns>股指期货交易费用结果</returns>
        public static QHCostResult ComputeGZQHCost(StockIndexFuturesOrderRequest request)
        {
            int?bc = MCService.CommonPara.GetBreedClassIdByCommodityCode(request.Code);

            QHCostResult result = null;

            if (!bc.HasValue)
            {
                return(result);
            }

            int            breedClassID = bc.Value;
            QH_FutureCosts cost         = MCService.FuturesTradeRules.GetFutureCostsByBreedClassID(breedClassID);

            if (cost == null)
            {
                return(null);
            }


            try
            {
                result = InternalComputeGZQHCost(request, cost);
            }
            catch (Exception ex)
            {
                string      errCode   = "GT-1703";
                string      errMsg    = "无法获取股指期货货交易费用。";
                VTException exception = new VTException(errCode, errMsg, ex);
                LogHelper.WriteError(exception.ToString(), exception);
                throw exception;
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// 根据BreedClassID获取货币类型
        /// </summary>
        /// <param name="breedClassID">breedClassID</param>
        /// <returns>货币类型</returns>
        public CM_CurrencyType GetCurrencyTypeByBreedClassID(int breedClassID)
        {
            QH_FutureCosts costs = GetFutureCostsByBreedClassID(breedClassID);

            CM_CurrencyType currencyType = null;

            if (costs != null)
            {
                int?currencyTypeID = costs.CurrencyTypeID;

                if (currencyTypeID.HasValue)
                {
                    currencyType = MCService.CommonPara.GetCurrencyTypeByID(currencyTypeID.Value);
                }
            }

            return(currencyType);
        }
        /// <summary>
        /// 确定按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (m_EditType == 1)
            {
                #region 添加操作
                try
                {
                    if (
                        FuturesManageCommon.ExistsFutureCosts(
                            ((UComboItem)this.cmbBreedClassID.SelectedItem).ValueIndex))
                    {
                        ShowMessageBox.ShowInformation("此品种的交易费用已存在!");
                        return;
                    }
                    QH_FutureCosts qH_FutureCosts = new QH_FutureCosts();

                    if (!string.IsNullOrEmpty(this.cmbBreedClassID.Text))
                    {
                        qH_FutureCosts.BreedClassID = ((UComboItem)this.cmbBreedClassID.SelectedItem).ValueIndex;
                    }
                    else
                    {
                        qH_FutureCosts.BreedClassID = AppGlobalVariable.INIT_INT;
                    }
                    qH_FutureCosts.CurrencyTypeID = ((UComboItem)this.cmbCurrencyTypeID.SelectedItem).ValueIndex;
                    qH_FutureCosts.CostType       = ((UComboItem)this.cmbCostType.SelectedItem).ValueIndex;
                    //if (this.cmbCostType.SelectedIndex == (int)GTA.VTS.Common.CommonObject.Types.FutrueCostType.TradeUnitCharge - 1)
                    //{
                    //    if (!string.IsNullOrEmpty(this.txtCost.Text))
                    //    {
                    //        if (InputTest.DecimalTest(this.txtCost.Text))
                    //        {
                    //            qH_FutureCosts.TradeUnitCharge = Convert.ToDecimal(this.txtCost.Text);
                    //        }
                    //        else
                    //        {
                    //            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                    //            return;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        //qH_FutureCosts.TradeUnitCharge = AppGlobalVariable.INIT_DECIMAL;
                    //        ShowMessageBox.ShowInformation("请填写手续费!");
                    //        return;
                    //    }
                    //}
                    //else
                    //{
                    if (!string.IsNullOrEmpty(this.txtCost.Text))
                    {
                        if (InputTest.DecimalTest(this.txtCost.Text))
                        {
                            qH_FutureCosts.TurnoverRateOfServiceCharge = Convert.ToDecimal(this.txtCost.Text);
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        //qH_FutureCosts.TurnoverRateOfServiceCharge = AppGlobalVariable.INIT_DECIMAL;
                        ShowMessageBox.ShowInformation("请填写手续费!");
                        return;
                    }
                    //}
                    m_Result = FuturesManageCommon.AddQHFutureCosts(qH_FutureCosts);
                    if (m_Result)
                    {
                        ShowMessageBox.ShowInformation("添加成功!");
                        this.ClearAll();
                        this.QueryQHFutureCosts();
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("添加失败!");
                    }
                }
                catch (Exception ex)
                {
                    string      errCode   = "GL-6201";
                    string      errMsg    = "添加品种_期货_交易费用失败!";
                    VTException exception = new VTException(errCode, errMsg, ex);
                    LogHelper.WriteError(exception.ToString(), exception.InnerException);
                    return;
                }
                #endregion
            }
            else if (m_EditType == 2)
            {
                #region 修改操作
                try
                {
                    QH_FutureCosts qH_FutureCosts = new QH_FutureCosts();
                    if (m_BreedClassID == AppGlobalVariable.INIT_INT)
                    {
                        ShowMessageBox.ShowInformation("请选择更新数据!");
                        return;
                    }
                    this.cmbBreedClassID.Enabled  = false;
                    qH_FutureCosts.BreedClassID   = m_BreedClassID;
                    qH_FutureCosts.BreedClassID   = ((UComboItem)this.cmbBreedClassID.SelectedItem).ValueIndex;
                    qH_FutureCosts.CurrencyTypeID = ((UComboItem)this.cmbCurrencyTypeID.SelectedItem).ValueIndex;
                    qH_FutureCosts.CostType       = ((UComboItem)this.cmbCostType.SelectedItem).ValueIndex;

                    //if (this.cmbCostType.SelectedIndex == (int)GTA.VTS.Common.CommonObject.Types.FutrueCostType.TradeUnitCharge - 1)
                    //{
                    //    if (!string.IsNullOrEmpty(this.txtCost.Text))
                    //    {
                    //        if (InputTest.DecimalTest(this.txtCost.Text))
                    //        {
                    //            qH_FutureCosts.TradeUnitCharge = Convert.ToDecimal(this.txtCost.Text);
                    //        }
                    //        else
                    //        {
                    //            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                    //            return;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        //qH_FutureCosts.TradeUnitCharge = AppGlobalVariable.INIT_DECIMAL;
                    //        ShowMessageBox.ShowInformation("请填写手续费!");
                    //        return;
                    //    }
                    //}
                    //else
                    //{
                    if (!string.IsNullOrEmpty(this.txtCost.Text))
                    {
                        if (InputTest.DecimalTest(this.txtCost.Text))
                        {
                            qH_FutureCosts.TurnoverRateOfServiceCharge = Convert.ToDecimal(this.txtCost.Text);
                        }
                        else
                        {
                            ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                            return;
                        }
                    }
                    else
                    {
                        //qH_FutureCosts.TurnoverRateOfServiceCharge = AppGlobalVariable.INIT_DECIMAL;
                        ShowMessageBox.ShowInformation("请填写手续费!");
                        return;
                    }
                    //}
                    m_Result = FuturesManageCommon.UpdateQHFutureCosts(qH_FutureCosts);
                    if (m_Result)
                    {
                        ShowMessageBox.ShowInformation("修改成功!");
                        this.cmbBreedClassID.Enabled = true;
                        this.ClearAll();
                        m_BreedClassID = AppGlobalVariable.INIT_INT;
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("修改失败!");
                    }
                    this.QueryQHFutureCosts();
                }
                catch (Exception ex)
                {
                    string      errCode   = "GL-6202";
                    string      errMsg    = "更新品种_期货_交易费用失败!";
                    VTException exception = new VTException(errCode, errMsg, ex);
                    LogHelper.WriteError(exception.ToString(), exception.InnerException);
                    return;
                }
                #endregion
            }
        }
        /// <summary>
        /// 获取股指期货交易费用的实际方法,目前使用商品期货的计算方法
        /// </summary>
        /// <param name="request">股指期货委托</param>
        /// <param name="cost">费用实体</param>
        /// <returns>股指期货交易费用结果</returns>
        private static QHCostResult InternalComputeGZQHCost(StockIndexFuturesOrderRequest request, QH_FutureCosts cost)
        {
            QHCostResult result = new QHCostResult();

            //result.Code = result.Code;
            result.Code = request.Code;
            decimal orderPrice = (decimal)request.OrderPrice;
            //期货合约乘数300
            decimal scale = MCService.GetTradeUnitScale(request.Code, request.OrderUnitType);
            //以计价单位计算的委托量
            var orderAmount = (decimal)request.OrderAmount * scale;

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

            decimal cosing = 0;

            //按类型计算比例
            switch ((Types.FutrueCostType)Enum.Parse(typeof(Types.FutrueCostType), cost.CostType.ToString()))
            {
            case Types.FutrueCostType.TradeUnitCharge:
                //与量有关的都是撮合单位,所以这里不用再把委托量*转换比例
                //为了不改上面的代码这里直接再把原来转了的值再除
                orderAmount = (decimal)orderAmount / scale;
                cosing      = orderAmount * cost.TurnoverRateOfServiceCharge;
                break;

            case Types.FutrueCostType.TurnoverRateOfSerCha:
                //比例
                decimal cosingScale = cost.TurnoverRateOfServiceCharge / 100;
                cosing = dealAmount * cosingScale;
                break;
            }
            cosing = Utils.Round(cosing);

            #region old code
            //decimal tradeVal = 0;
            ////成交单位比率
            //if (cost.TradeUnitCharge.HasValue)
            //{
            //    decimal trade = cost.TradeUnitCharge.Value / 100;
            //    tradeVal = orderAmount * trade;
            //    tradeVal = Utils.Round(tradeVal);
            //}

            //decimal turnVal = 0;
            ////成交金额比率
            //if (cost.TurnoverRateOfServiceCharge.HasValue)
            //{
            //    decimal turn = cost.TurnoverRateOfServiceCharge.Value / 100;
            //    turnVal = turn * dealAmount;
            //    turnVal = Utils.Round(turnVal);
            //}
            //result.Cosing = tradeVal + turnVal;
            #endregion

            result.Cosing = cosing;


            string format = "股指期货费用计算[代码={0},价格={1},数量={2},单位={3},方向={4},合约乘数={5},股指期货交易费用类型={6},费用比率={7}]";
            string desc   = string.Format(format, request.Code, request.OrderPrice, request.OrderAmount,
                                          request.OrderUnitType, request.BuySell, scale
                                          , cost.CostType + "--" + (cost.CostType == (int)Types.FutrueCostType.TradeUnitCharge ? "按成交量" : "按成交额")
                                          , cost.TurnoverRateOfServiceCharge);
            LogHelper.WriteDebug(desc + result);

            return(result);
        }
        /// <summary>
        /// 获取期货保本价
        /// </summary>
        /// <param name="code">商品代码</param>
        /// <param name="costPrice">成本价</param>
        /// <param name="amount">总持仓量</param>
        /// <param name="buySellType">买卖方向</param>
        /// <returns>保本价</returns>
        private static decimal GetFutureHoldPrice(string code, decimal costPrice, decimal amount, Types.TransactionDirection buySellType)
        {
            int?bc = MCService.CommonPara.GetBreedClassIdByCommodityCode(code);

            //QHCostResult result = null;

            if (!bc.HasValue)
            {
                return(0);
            }

            int            breedClassId = bc.Value;
            QH_FutureCosts cost         = MCService.FuturesTradeRules.GetFutureCostsByBreedClassID(breedClassId);

            #region old code

            ////成交单位比率
            //decimal trade = 0;
            //if (cost.TradeUnitCharge.HasValue)
            //{
            //    trade = cost.TradeUnitCharge.Value / 100;
            //    trade = Utils.Round(trade);
            //}
            ////decimal tradeVal = trade;

            ////成交金额比率
            //decimal turn = 0;
            //if (cost.TurnoverRateOfServiceCharge.HasValue)
            //{
            //    turn = cost.TurnoverRateOfServiceCharge.Value / 100;
            //    turn = Utils.Round(turn);
            //}
            ////decimal turnVal = turn * orderPrice ;
            //decimal holdPrice = 0;

            //if (buySellType == Types.TransactionDirection.Buying)
            //{
            //    holdPrice = (costPrice + trade) / (1 - turn);
            //}
            //else
            //{
            //    holdPrice = (costPrice + trade) / (1 + turn);
            //}

            //holdPrice = Utils.Round(holdPrice);

            //return holdPrice;
            #endregion

            //单笔费用
            decimal cosing = 0;

            //按类型计算比例
            //计算笔费用=费用比例*成交量*成交价/成交量--->费用比例*成交价
            switch ((Types.FutrueCostType)Enum.Parse(typeof(Types.FutrueCostType), cost.CostType.ToString()))
            {
            case Types.FutrueCostType.TradeUnitCharge:
                //cosing = cost.TurnoverRateOfServiceCharge * amount / amount;////按成交额计算笔费用=费用比例*总持仓量*成交价/总持仓量--->费用比例*成交价
                cosing = cost.TurnoverRateOfServiceCharge;
                break;

            case Types.FutrueCostType.TurnoverRateOfSerCha:
                cosing = cost.TurnoverRateOfServiceCharge / 100;
                //cosing = cosing * amount * costPrice / amount;//按成交额计算笔费用=费用比例*总持仓量*成交价/总持仓量--->费用比例*成交价
                cosing = cosing * costPrice;
                break;
            }

            decimal holdPrice = 0;

            //买
            //保本价=(成本价*持仓量+费用)/持仓量
            //卖
            //保本价=(成本价*持仓量-费用)/持仓量
            if (buySellType == Types.TransactionDirection.Buying)
            {
                //保本价=(成本价*持仓量+成交单位比率*持仓量<或者成交金额比率*成本价*持仓量>)/持仓量
                //==>保本价=(成本价+成交单位比率<或者成交金额比率*成本价>)
                holdPrice = costPrice + cosing;
            }
            else
            {
                //保本价=(成本价*持仓量-成交单位比率*持仓量<或者成交金额比率*成本价*持仓量>)/持仓量
                //==>保本价=(成本价-成交单位比率<或者成交金额比率*成本价>)
                holdPrice = costPrice - cosing;
            }

            //holdPrice = costPrice + cosing;

            holdPrice = Utils.Round(holdPrice);

            return(holdPrice);
        }