/// <summary>
        /// 计算预成交金额和预成交费用
        /// </summary>
        /// <param name="strMessage">错误信息</param>
        /// <param name="predealCapital">预成交金额</param>
        /// <param name="predealCost">预成交费用</param>
        /// <returns>计算是否成功</returns>
        private bool PO_ComputePreCapital(ref string strMessage, ref decimal predealCapital, ref decimal predealCost)
        {
            bool result = false;

            predealCapital = 0;
            predealCost    = 0;

            //如果量为0,直接返回0
            if (Request.OrderAmount == 0)
            {
                return(true);
            }

            try
            {
                XHCostResult xhcr = null;
                //计价单位与交易单位倍数
                decimal unitMultiple = MCService.GetTradeUnitScale(Request.Code, Request.OrderUnitType);
                float   orderPrice   = 0;

                //市价委托
                if (Request.OrderWay == Types.OrderPriceType.OPTMarketPrice)
                {
                    decimal orderPriceD  = (decimal)Request.OrderPrice;
                    var     highLowRange = MCService.HLRangeProcessor.GetHighLowRangeValueByCommodityCode(Request.Code,
                                                                                                          orderPriceD);
                    if (highLowRange != null)
                    {
                        if (highLowRange.RangeType == GTA.VTS.Common.CommonObject.Types.HighLowRangeType.HongKongPrice) //港股类型处理
                        {
                            var hkrv = highLowRange.HongKongRangeValue;
                            if (Request.BuySell == GTA.VTS.Common.CommonObject.Types.TransactionDirection.Buying)
                            {
                                orderPrice = Convert.ToSingle(hkrv.BuyHighRangeValue);
                            }
                            else
                            {
                                orderPrice = Convert.ToSingle(hkrv.SellHighRangeValue);
                            }
                        }
                        else //其它类型处理
                        {
                            orderPrice = Convert.ToSingle(highLowRange.HighRangeValue);
                        }

                        //以计价单位计算的委托量
                        int orderAmount = Convert.ToInt32(Request.OrderAmount);//*Convert.ToDouble(unitMultiple));

                        //预成交总金额 委托量 * 计价单位与交易单位倍数 * 委托价
                        predealCapital = orderAmount * Convert.ToDecimal(orderPrice) * unitMultiple;
                        //预成交费用
                        xhcr = MCService.ComputeXHCost(Request.Code, orderPrice, orderAmount,
                                                       Request.OrderUnitType, Request.BuySell);
                        //预成交费用
                        predealCost = xhcr.CoseSum;
                        result      = true;
                    }
                    else
                    {
                        strMessage = "GT-2215:[现货委托持久化]商品无涨跌幅设置";
                    }
                }
                else //限价委托计算( 委托价*委托量 + 费用)
                {
                    //成本计算器
                    xhcr = MCService.ComputeXHCost(Request);
                    //预成交总金额 委托量 * 计价单位与交易单位倍数 * 委托价
                    predealCapital = Convert.ToDecimal(Request.OrderAmount) * unitMultiple *
                                     Convert.ToDecimal(Request.OrderPrice);
                    //预成交费用
                    predealCost = xhcr.CoseSum;
                    result      = true;
                }
            }
            catch (Exception ex)
            {
                if (ex is VTException)
                {
                    strMessage = ex.ToString();
                }
                else
                {
                    strMessage = "GT-2216:[现货委托持久化]成交金额及费用计算异常.";
                }

                LogHelper.WriteError(ex.Message, ex);
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// 构建现货成交回报
        /// </summary>
        /// <param name="tet"></param>
        /// <param name="sdbe"></param>
        /// <param name="xhcr"></param>
        /// <param name="dealCapital"></param>
        /// <param name="tm"></param>
        /// <returns></returns>
        public static XH_TodayTradeTableInfo BuildXHDealRpt(XH_TodayEntrustTableInfo tet, StockDealBackEntity sdbe,
                                                            XHCostResult xhcr, decimal dealCapital,
                                                            ReckoningTransaction tm)
        {
            string result = string.Empty;

            //成交回报实体
            var xhDealrpt = new XH_TodayTradeTableInfo();

            //xhDealrpt.TradeNumber = this.BuildXHDealOrderNo();
            xhDealrpt.TradeNumber = sdbe.Id; //不再自己构建id,使用成交回报的id,一一对应
            //成交时间
            xhDealrpt.TradeTime = sdbe.DealTime;
            //成交价
            xhDealrpt.TradePrice = sdbe.DealPrice;
            //成交单位
            xhDealrpt.TradeUnitId = tet.TradeUnitId;
            //成交量
            xhDealrpt.TradeAmount = Convert.ToInt32(sdbe.DealAmount);
            //股东代码
            xhDealrpt.StockAccount = tet.StockAccount;
            //资金帐户
            xhDealrpt.CapitalAccount = tet.CapitalAccount;
            //成交回报类型
            xhDealrpt.TradeTypeId = (int)Types.DealRptType.DRTDealed;
            //现货名称
            xhDealrpt.SpotCode = tet.SpotCode;
            //印花税
            xhDealrpt.StampTax = xhcr.StampDuty;
            //佣金
            xhDealrpt.Commission = xhcr.Commision;
            //过户费
            xhDealrpt.TransferAccountFee = xhcr.TransferToll;
            //交易系统使用费
            xhDealrpt.TradingSystemUseFee = xhcr.TradeSystemFees;
            //监管费
            xhDealrpt.MonitoringFee = xhcr.MonitoringFee;
            //结算费
            xhDealrpt.ClearingFee = xhcr.ClearingFees;
            //委托价格
            xhDealrpt.EntrustPrice = tet.EntrustPrice;
            //成交金额
            xhDealrpt.TradeCapitalAmount = dealCapital; // xhDealrpt.TradePrice*xhDealrpt.TradeAmount;//TODO:是否正确?没有算比例
            //投组标识
            xhDealrpt.PortfolioLogo = tet.PortfolioLogo;
            //货币类型
            xhDealrpt.CurrencyTypeId = tet.CurrencyTypeId;
            //买卖方向
            xhDealrpt.BuySellTypeId = tet.BuySellTypeId;

            xhDealrpt.EntrustNumber = tet.EntrustNumber;
            XH_TodayTradeTableDal xhTodayTradeTableDal = new XH_TodayTradeTableDal();

            if (xhTodayTradeTableDal.Exists(xhDealrpt.TradeNumber))
            {
                string format = "BuildXHDealRpt数据库已经存在TradeNumber={0}";
                string desc   = string.Format(format, xhDealrpt.TradeNumber);
                LogHelper.WriteDebug(desc);

                //xhDealrpt = xhTodayTradeTableDal.GetModel(xhDealrpt.TradeNumber);
                return(null);
            }

            try
            {
                xhTodayTradeTableDal.Add(xhDealrpt, tm);
            }
            catch (Exception ex)
            {
                LogHelper.WriteError(ex.Message, ex);
                xhDealrpt = null;
            }

            return(xhDealrpt);
        }