示例#1
0
        public bool UpdateChance(ExchangeChance ec, out double Gained)
        {
            string sqlmodule = "{0}='{1}'";
            string sql       = string.Format(sqlmodule, "Id", ec.Id);

            DataRow[] drs = this.Select(sql, "");
            if (drs.Length != 1)
            {
                throw new  Exception("需要更新的下注Id不存在");
            }
            DataRow dr       = drs[0];
            double  CurrOdds = double.Parse(dr["Odds"].ToString());
            double  dGained  = CurrOdds * ec.ExchangeAmount * ec.MatchChips;
            double  dCost    = (double)ec.Cost;

            Gained = 0;
            if (ec.MatchChips > 0)
            {
                Gained = dGained;
            }
            dr["Gained"]     = dGained;
            dr["Profit"]     = dGained - dCost;
            dr["UpdateTime"] = DateTime.Now.ToString();
            return(true);
        }
示例#2
0
        /// <summary>
        /// 记录交易,可以可视化查看交易结果及查看资金曲线,同时复利策略的计划必须绑定资产单元
        /// </summary>
        /// <param name="list"></param>
        /// <param name="newList"></param>
        /// <returns></returns>
        bool ExChange(List <ChanceClass> list)
        {
            ////List<ChanceClass> list = new List<ChanceClass>();
            ////Oldlist.Values.ToList<ChanceClass>().ForEach(p => list.Add(p));
            ////newList.ForEach(p => list.Add(p));
            for (int i = 0; i < list.Count; i++)
            {
                ChanceClass cc = list[i];
                StragClass  sc = UseStrags[cc.StragId];
                if (sc.AssetUnitId == null)
                {
                    continue; //所属计划未指定资产单元,不记录交易信息
                }
                if (!UseAssetUnits.ContainsKey(sc.AssetUnitId))
                {
                    continue;//所属分类无记录的资产单元,不记录信息
                }
                AssetUnitClass uu = UseAssetUnits[sc.AssetUnitId];
                ExchangeChance ec = new ExchangeChance(uu.ExchangeServer, sc, cc.ExpectCode, cc);

                ec.ExchangeAmount = cc.UnitCost;
                ec.ExchangeRate   = cc.UnitCost / uu.ExchangeServer.summary;
                if (uu.ExchangeServer.Push(ref ec))
                {
                    AllExchance.Add(ec);
                }
            }
            return(true);
        }
示例#3
0
        //////void ExchangeTheChance(object sender, ElapsedEventArgs e)
        //////{
        //////    ////ExchangeLock = true;
        //////    //////ToAdd 交易内容
        //////    ////ExchangeLock = false;
        //////}


        public bool Push(ref ExchangeChance ec)
        {
            lock (ed)
            {
                if (ec.OwnerChance == null)
                {
                    return(false);
                }
                if (ec.OccurStrag == null)
                {
                    return(false);
                }
                #region 单位金额由外面传入
                ////////////if (ec.OwnerChance.IncrementType == InterestType.CompoundInterest)//如果是复利
                ////////////{
                ////////////    if (ec.OccurStrag is ProbWaveSelectStragClass)//由外面传入
                ////////////    {
                ////////////    }
                ////////////    else
                ////////////    {
                ////////////        if (ec.OwnerChance.Tracerable)
                ////////////        {
                ////////////            ec.ExchangeAmount = (ec.OwnerChance as ISpecAmount).getChipAmount(CurrMoney, ec.OwnerChance, ec.OccurStrag.CommSetting.GetGlobalSetting().DefaultHoldAmtSerials);
                ////////////        }
                ////////////        else
                ////////////        {
                ////////////            ec.ExchangeAmount = (ec.OccurStrag as ChanceTraceStragClass).getChipAmount(CurrMoney, ec.OwnerChance, ec.OccurStrag.CommSetting.GetGlobalSetting().DefaultHoldAmtSerials);
                ////////////            ec.ExchangeRate = ec.ExchangeAmount * ec.OwnerChance.ChipCount / CurrMoney;
                ////////////        }
                ////////////    }
                ////////////    //ec.ExchangeAmount = (int)Math.Floor(CurrMoney * ec.OccurStrag.StagSetting.BaseType.ChipRate);
                ////////////}
                ////////////else
                ////////////{
                ////////////    if (ec.OwnerChance.Tracerable)
                ////////////    {
                ////////////        ec.ExchangeAmount = (ec.OwnerChance as ISpecAmount).getChipAmount(CurrMoney, ec.OwnerChance, ec.OccurStrag.CommSetting.GetGlobalSetting().DefaultHoldAmtSerials);
                ////////////    }
                ////////////    else
                ////////////    {
                ////////////        ec.ExchangeAmount = (ec.OccurStrag as ChanceTraceStragClass).getChipAmount(CurrMoney, ec.OwnerChance, ec.OccurStrag.CommSetting.GetGlobalSetting().DefaultHoldAmtSerials);
                ////////////    }
                ////////////}
                #endregion
                if (CurrMoney < ec.ExchangeAmount * ec.OwnerChance.ChipCount)
                {
                    LogableClass.ToLog("风险", "剩余金额不足", ec.OwnerChance.ToDetailString());
                    return(false);
                }
                if (ec.ExchangeAmount * ec.OwnerChance.ChipCount * 10 > CurrMoney)//记录投入资金超出10%的记录
                {
                    LogableClass.ToLog("风险", string.Format("大投入组合[{0}]", (double)100 * ec.ExchangeAmount * ec.OccurStrag.ChipCount / CurrMoney), ec.OwnerChance.ToDetailString());
                }
                ec         = ed.AddAChance(ec);
                CurrMoney -= ec.ExchangeAmount * ec.OwnerChance.ChipCount;
                //MoneyLine.Add(CurrMoney);
                return(true);
            }
        }
示例#4
0
 public bool Update(ExchangeChance ec)
 {
     lock (ed)
     {
         double Gained = 0.0;
         bool   suc    = ed.UpdateChance(ec, out Gained);
         CurrMoney += Gained;
         MoneyLine.Add(CurrMoney);
         return(suc);
     }
 }
示例#5
0
 bool CloseAllExchance(ExpectList el)
 {
     for (int i = 0; i < AllExchance.Count; i++)
     {
         ExchangeChance ec       = AllExchance[i];
         int            MatchCnt = 0;
         ec.OwnerChance.Matched(el.LastData, out MatchCnt);
         ec.MatchChips = MatchCnt;
         ec.Server.Update(ec);
     }
     AllExchance = new List <ExchangeChance>();//全部清空
     return(true);
 }
示例#6
0
        public ExchangeChance AddAChance(ExchangeChance ec)
        {
            DataRow dr = this.NewRow();

            Eindex++;
            ec.Id            = Eindex;
            dr["Id"]         = Eindex;
            dr["ExpectNo"]   = int.Parse(ec.ExpectNo);
            dr["ChanceCode"] = ec.OwnerChance.ChanceCode;
            dr["Chips"]      = ec.OwnerChance.ChipCount;
            dr["Odds"]       = ec.OccurStrag.CommSetting.Odds;
            dr["Amount"]     = ec.ExchangeAmount;
            dr["ExecRate"]   = ec.ExchangeRate;
            dr["Cost"]       = ec.Cost;
            dr["CreateTime"] = DateTime.Now.ToString();
            Rows.Add(dr);
            return(ec);
        }