/// <summary> /// 获取现货交易费用 /// </summary> /// <param name="request">现货委托</param> /// <returns>现货交易费用结果</returns> public static XHCostResult ComputeXHCost(StockOrderRequest request) { int?bc = MCService.CommonPara.GetBreedClassIdByCommodityCode(request.Code); XHCostResult result = null; if (!bc.HasValue) { return(null); } int breedClassID = bc.Value; XH_SpotCosts cost = MCService.SpotTradeRules.GetSpotCostsByBreedClassID(breedClassID); if (cost == null) { return(null); } try { result = InternalComputeXHCost(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); }
//================================ 事件 ================================ #region 现货交易费用窗体 AddSpotCostsUI_Load /// <summary> /// 现货交易费用窗体 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddSpotCostsUI_Load(object sender, EventArgs e) { try { if (EditType == (int)UITypes.EditTypeEnum.AddUI) { m_XH_SpotCosts = new XH_SpotCosts(); this.cmbBreedClassID.Enabled = true; } this.InitBindData(); if (EditType == (int)UITypes.EditTypeEnum.UpdateUI) { this.UpdateInitData(); //this.btnAddPoundage.Text = "修改手续费"; //this.Text = "修改现货交易费用"; this.cmbBreedClassID.Enabled = false; } } catch (Exception ex) { string errCode = "GL-5400"; string errMsg = "现货交易费用窗体加载失败!"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); } }
/// <summary> /// 获取需要更新的现货交易费用数据 UpdateSpotCosts /// </summary> /// <param name="handle"></param> private void UpdateSpotCosts(int handle) { try { if (handle < 0) { return; } //显示添加现货交易费用窗体 AddSpotCostsUI addSpotCostsUI = new AddSpotCostsUI(); addSpotCostsUI.EditType = (int)UITypes.EditTypeEnum.UpdateUI; DataRow _dr = this.gdvSpotCostsSelect.GetDataRow(handle); int breedClassID = Convert.ToInt32(_dr["BreedClassID"]); XH_SpotCosts xH_SpotCosts = SpotManageCommon.GetXHSpotCostsModel(breedClassID); addSpotCostsUI.XHSpotCosts = xH_SpotCosts; if (addSpotCostsUI.ShowDialog(this) == DialogResult.OK) { this.QuerySpotCosts(); this.gdvSpotCostsSelect.FocusedRowHandle = handle; } } catch (Exception ex) { string errCode = "GL-5423"; string errMsg = "获取需要更新的现货交易费用数据失败!"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); return; } }
/// <summary> ///Title:根据BreedClassID获取交易费用所属货币类型 ///Desc.:此方法内部是先根据商品类别查询到现货的交易费用实体然后再通过费用所属的货币类型返回相应的货币实体. /// 因为现在有港股加入,费用表不在现货所以此方法使用时要与注意与港股分开 /// </summary> /// <param name="breedClassID">breedClassID</param> /// <returns>货币类型</returns> public CM_CurrencyType GetCurrencyTypeByBreedClassID(int breedClassID) { XH_SpotCosts spotCosts = GetSpotCostsByBreedClassID(breedClassID); CM_CurrencyType currencyType = null; if (spotCosts != null) { int?currencyTypeID = spotCosts.CurrencyTypeID; if (currencyTypeID.HasValue) { currencyType = MCService.CommonPara.GetCurrencyTypeByID(currencyTypeID.Value); } } return(currencyType); }
/// <summary> /// 获取现货保本价 /// </summary> /// <param name="code">商品代码</param> /// <param name="costPrice">成本价</param> /// <param name="amount">总持仓量</param> /// <returns>保本价</returns> private static decimal GetStockHoldPrice(string code, decimal costPrice, decimal amount) { int?bc = MCService.CommonPara.GetBreedClassIdByCommodityCode(code); if (!bc.HasValue) { return(-1); } int breedClassID = bc.Value; XH_SpotCosts cost = MCService.SpotTradeRules.GetSpotCostsByBreedClassID(breedClassID); /// 1.印花税 decimal stamp = cost.StampDuty / 100; stamp = Utils.Round(stamp, 4); /// 2.佣金 decimal comm = cost.Commision.Value / 100; comm = Utils.Round(comm, 4); /// 3.过户费 decimal trans = cost.TransferToll / 100; trans = Utils.Round(trans, 4); int transType = cost.TransferTollTypeID; /// 4.交易手续费 decimal pound = cost.PoundageSingleValue.Value / 100; pound = Utils.Round(pound, 4); /// 5.监管费 decimal monitor = cost.MonitoringFee.Value / 100; monitor = Utils.Round(monitor, 4); /// 6.结算费 decimal clear = cost.ClearingFees.Value / 100; clear = Utils.Round(clear, 4); /// 7.交易系统使用费(港股)--->与价格无关,每笔0.5港元 decimal tradeSystemFees = cost.SystemToll.Value; tradeSystemFees = Utils.Round(tradeSystemFees, 4); //所有与价格有关的费用百分比之和 decimal scale = stamp + comm + pound + monitor + clear; scale = Utils.Round(scale, 4); //所有与价格无关的费用(单笔) decimal others = 0; //过户费类型 [按股] [按成交额] switch (transType) { case (int)Types.GetValueTypeEnum.Thigh: others = tradeSystemFees + trans * amount; break; case (int)Types.GetValueTypeEnum.Turnover: others = tradeSystemFees; scale += trans; break; } others = Utils.Round(others); //计算公式:保本价=[进价*(1+佣金)+过户费*2]/(1-佣金)基中佣金、过户费均为费率。 //以上面成交为例计算,保本价=[5.08*(1+3‰)+0]/(1-3‰)=5.11057约为5.11或5.12 //保本价holdPrice //单股费用=所有与价格有关的费用百分比之和 × holdPrice + 所有与价格无关的费用(单笔)/amount //singleCost = scale * holdPrice + others/amount //holdPrice - singleCost = costPrice => holdPrice -(scale*holdPrice + others/amount) = costPrice //=>holdPrice = (costPrice + others/amount)/(1-scale) decimal holdPrice = (costPrice + others / amount) / (1 - scale); holdPrice = Utils.Round(holdPrice); return(holdPrice); }
private static XHCostResult InternalComputeXHCost(StockOrderRequest request, XH_SpotCosts cost) { CM_BreedClass breedClass = MCService.CommonPara.GetBreedClassByCommodityCode(request.Code); XHCostResult result = new XHCostResult(); 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; /// 1.印花税 decimal stamp = cost.StampDuty / 100; decimal stampStart = cost.StampDutyStartingpoint; if (cost.StampDutyTypeID.HasValue) { int stampType = cost.StampDutyTypeID.Value; #region old code //if (stampType == (int)Types.GetValueTypeEnum.SingleSell && // request.BuySell == Types.TransactionDirection.Selling) //{ // decimal stampVal = stamp * dealAmount; // if (stampVal < stampStart) // stampVal = stampStart; // stampVal = Utils.Round(stampVal); // result.StampDuty = stampVal; //} #endregion 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; } } /// 2.佣金 //public decimal Commision { get; set; } if (cost.Commision.HasValue) { decimal comm = cost.Commision.Value / 100; decimal commVal = comm * dealAmount; decimal commStart = cost.CommisionStartingpoint; if (commVal < commStart) { commVal = commStart; } commVal = Utils.Round(commVal); result.Commision = commVal; } /// 3.过户费 //public decimal TransferToll { get; set; } decimal trans = cost.TransferToll / 100; int transType = cost.TransferTollTypeID; decimal transVal = 0; //过户费类型 [按股] [按成交额] switch (transType) { case (int)Types.GetValueTypeEnum.Thigh: transVal = trans * orderAmount; break; case (int)Types.GetValueTypeEnum.Turnover: transVal = trans * dealAmount; break; } transVal = Utils.Round(transVal); if (cost.TransferTollStartingpoint.HasValue) { decimal transStart = cost.TransferTollStartingpoint.Value; if (transVal < transStart) { transVal = transStart; } } transVal = Utils.Round(transVal); result.TransferToll = transVal; /// 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.PoundageSingleValue.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; } } /// 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; } /// 6.结算费 if (cost.ClearingFees.HasValue) { decimal clear = cost.ClearingFees.Value / 100; decimal clearval = clear * dealAmount; clearval = Utils.Round(clearval); result.ClearingFees = clearval; } /// 7.交易系统使用费(港股) if (cost.SystemToll.HasValue) { result.TradeSystemFees = cost.SystemToll.Value; } 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); }
/// <summary> /// 添加或修改现货交易费用 /// 说明:根据需求,当以下值,分别是(印花税,印花税起点,佣金起点,过户费,过户费起点,结算费)用户没有填写时,默认值是0; /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOK_Click(object sender, EventArgs e) { try { if (EditType == (int)UITypes.EditTypeEnum.AddUI) { if ( SpotManageCommon.ExistsSpotCosts( ((UComboItem)this.cmbBreedClassID.SelectedItem).ValueIndex)) { ShowMessageBox.ShowInformation("此品种的交易费用已存在!"); return; } } XH_SpotCosts xH_SpotCosts = new XH_SpotCosts(); if (XHSpotCosts != null) { ManagementCenter.Model.CommonClass.UtilityClass.CopyEntityToEntity(XHSpotCosts, xH_SpotCosts); } if (!string.IsNullOrEmpty(this.cmbBreedClassID.Text)) { xH_SpotCosts.BreedClassID = ((UComboItem)this.cmbBreedClassID.SelectedItem).ValueIndex; } else { ShowMessageBox.ShowInformation("品种名称不能为空!"); return; } xH_SpotCosts.CurrencyTypeID = ((UComboItem)this.cmbCurrencyType.SelectedItem).ValueIndex; xH_SpotCosts.GetValueTypeID = (int)GTA.VTS.Common.CommonObject.Types.GetValueTypeEnum.Single; //根据需求指定默认值 //((UComboItem)this.cmbGetValueType.SelectedItem).ValueIndex; xH_SpotCosts.StampDutyTypeID = ((UComboItem)this.cmbStampDutyType.SelectedItem).ValueIndex; xH_SpotCosts.TransferTollTypeID = ((UComboItem)this.cmbTransferTollType.SelectedItem).ValueIndex; if (!string.IsNullOrEmpty(this.txtClearingFees.Text)) { if (InputTest.DecimalTest(this.txtClearingFees.Text)) { xH_SpotCosts.ClearingFees = Convert.ToDecimal(this.txtClearingFees.Text); } else { ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!"); return; } } else { xH_SpotCosts.ClearingFees = 0; // AppGlobalVariable.INIT_DECIMAL; } if (!string.IsNullOrEmpty(this.txtCommision.Text)) { if (InputTest.DecimalTest(this.txtCommision.Text)) { xH_SpotCosts.Commision = Convert.ToDecimal(this.txtCommision.Text); //null; } else { ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!"); return; } } else { xH_SpotCosts.Commision = 0; //?现货所有品种都有拥金 AppGlobalVariable.INIT_DECIMAL; } if (!string.IsNullOrEmpty(this.txtCommisionStartpoint.Text)) { if (InputTest.DecimalTest(this.txtCommisionStartpoint.Text)) { xH_SpotCosts.CommisionStartingpoint = Convert.ToDecimal(this.txtCommisionStartpoint.Text); } else { ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!"); return; } } else { xH_SpotCosts.CommisionStartingpoint = 0; // AppGlobalVariable.INIT_DECIMAL; } xH_SpotCosts.MonitoringFee = 0; //根据需求指定默认值 //Convert.ToDecimal(this.txtMonitoringFee.Text); xH_SpotCosts.PoundageSingleValue = 0; //根据需求改成默认值 //Convert.ToDecimal(this.txtPoundageSingleValue.Text); if (!string.IsNullOrEmpty(this.txtStampDuty.Text)) { if (InputTest.DecimalTest(this.txtStampDuty.Text)) { xH_SpotCosts.StampDuty = Convert.ToDecimal(this.txtStampDuty.Text); } else { ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!"); return; } } else { xH_SpotCosts.StampDuty = 0; // AppGlobalVariable.INIT_DECIMAL; } if (!string.IsNullOrEmpty(this.txtStampDutyStartpoint.Text)) { if (InputTest.DecimalTest(this.txtStampDutyStartpoint.Text)) { xH_SpotCosts.StampDutyStartingpoint = Convert.ToDecimal(this.txtStampDutyStartpoint.Text); } else { ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!"); return; } } else { xH_SpotCosts.StampDutyStartingpoint = 0; // AppGlobalVariable.INIT_DECIMAL; } xH_SpotCosts.SystemToll = 0; //根据需求指定默认值// Convert.ToDecimal(this.txtSystemToll.Text); if (!string.IsNullOrEmpty(this.txtTransferToll.Text)) { if (InputTest.DecimalTest(this.txtTransferToll.Text)) { xH_SpotCosts.TransferToll = Convert.ToDecimal(this.txtTransferToll.Text); } else { ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!"); return; } } else { xH_SpotCosts.TransferToll = 0; // AppGlobalVariable.INIT_DECIMAL; } if (!string.IsNullOrEmpty(this.txtTransferTollStartpoint.Text)) { if (InputTest.DecimalTest(this.txtTransferTollStartpoint.Text)) { xH_SpotCosts.TransferTollStartingpoint = Convert.ToDecimal(this.txtTransferTollStartpoint.Text); } else { ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!"); return; } } else { xH_SpotCosts.TransferTollStartingpoint = 0; // AppGlobalVariable.INIT_DECIMAL; } if (EditType == (int)UITypes.EditTypeEnum.AddUI) { m_Result = SpotManageCommon.AddSpotCosts(xH_SpotCosts); if (m_Result) { //m_ValueType = Convert.ToInt32(xH_SpotCosts.ValueTypeMinChangePrice); //if (m_ValueType == (int)Types.GetValueTypeEnum.Scope) //{ // btnMinChangePriceV.Visible = true; //} m_BreedClassID = Convert.ToInt32(xH_SpotCosts.BreedClassID); ShowMessageBox.ShowInformation("添加成功!"); this.ClearAll(); this.DialogResult = DialogResult.OK; this.Close(); } else { ShowMessageBox.ShowInformation("添加失败!"); } } else if (EditType == (int)UITypes.EditTypeEnum.UpdateUI) { m_Result = SpotManageCommon.UpdateSpotCosts(xH_SpotCosts); if (m_Result) { ShowMessageBox.ShowInformation("修改成功!"); this.DialogResult = DialogResult.OK; this.Close(); } else { ShowMessageBox.ShowInformation("修改失败!"); } } } catch (Exception ex) { string errCode = "GL-5402"; string errMsg = "添加或修改现货交易费用失败!"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); return; } }