public bool UpdateChance <T>(ExchangeChance <T> ec, out double Gained) where T : TimeSerialData { string sqlmodule = "{0}='{1}'"; Gained = 0; string sql = string.Format(sqlmodule, "Id", ec.Id); DataRow[] drs = this.Select(sql, ""); if (drs.Length < 1) { //throw new Exception("需要更新的下注Id不存在"); return(false); } DataRow dr = drs[0]; ec.OwnerChance.Odds = double.Parse(dr["Odds"].ToString()); double CurrOdds = ec.OwnerChance.getRealOdds(); //double.Parse(dr["Odds"].ToString()); double dGained = CurrOdds * ec.ExchangeAmount; double dCost = (double)ec.Cost; Gained = 0; if (ec.MatchChips > 0) { Gained = dGained; } dr["Gained"] = Gained; dr["Profit"] = dGained - dCost; dr["UpdateTime"] = DateTime.Now.ToString(); return(true); }
protected bool CloseAllExchance(ExpectList <T> el) { //Dictionary<string, ChanceClass<T>> tmp = new Dictionary<string, ChanceClass<T>>(); //CurrExistChanceList.Keys.ToList().ForEach(a => tmp.Add(a, CurrExistChanceList[a])); //Dictionary<string, ExchangeChance<T>> dic = AllExchance.ToDictionary(a => a.OwnerChance.GUID, a => a); //CurrExistChanceList = new Dictionary<string, ChanceClass<T>>(); //tmp.ToList().ForEach(a => //{ // if (!dic.ContainsKey(a.Key)) // { // CurrExistChanceList.Add(a.Key, a.Value); // } //}); for (int i = 0; i < AllExchance.Count; i++) { ExchangeChance <T> ec = AllExchance[i]; int MatchCnt = 0; ec.OwnerChance.Matched(el.LastData, out MatchCnt); ec.MatchChips = MatchCnt; ec.OwnerChance.MatchChips = MatchCnt; ec.Server.Update(ec); //if (MatchCnt == 0) //{ // if (tmp.ContainsKey(ec.OwnerChance.GUID) && !CurrExistChanceList.ContainsKey(ec.OwnerChance.GUID)) // CurrExistChanceList.Add(ec.OwnerChance.GUID, ec.OwnerChance); //} } AllExchance = new List <ExchangeChance <T> >();//全部清空 return(true); }
/// <summary> /// 记录交易,可以可视化查看交易结果及查看资金曲线,同时复利策略的计划必须绑定资产单元 /// </summary> /// <param name="list"></param> /// <param name="newList"></param> /// <returns></returns> protected bool ExChange(List <ChanceClass <T> > list, string lastExpectNo) { ////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 <T> cc = list[i]; BaseStragClass <T> sc = UseStrags[cc.StragId]; if (sc.AssetUnitId == null) { continue; //所属计划未指定资产单元,不记录交易信息 } if (!UseAssetUnits.ContainsKey(sc.AssetUnitId)) { continue; //所属分类无记录的资产单元,不记录信息 } if (cc.UnitCost == 0) //无交易金额,不处理 { continue; } AssetUnitClass uu = UseAssetUnits[sc.AssetUnitId]; ExchangeChance <T> ec = new ExchangeChance <T>(uu.getCurrExchangeServer(), sc, cc.ExpectCode, lastExpectNo, cc); ec.ExchangeAmount = cc.UnitCost; ec.ExchangeRate = cc.UnitCost / uu.getCurrExchangeServer().summary; if (uu.getCurrExchangeServer().Push(ref ec)) { AllExchance.Add(ec); } } return(true); }
//////void ExchangeTheChance(object sender, ElapsedEventArgs e) //////{ ////// ////ExchangeLock = true; ////// //////ToAdd 交易内容 ////// ////ExchangeLock = false; //////} public bool Push <T>(ref ExchangeChance <T> ec) where T : TimeSerialData { 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); } }
public bool Update <T>(ExchangeChance <T> ec) where T : TimeSerialData { lock (ed) { double Gained = 0.0; bool suc = ed.UpdateChance(ec, out Gained); CurrMoney += Gained; //MoneyLine.Add(CurrMoney); if (ExpectMoneyLine.ContainsKey(ec.ExExpectNo)) { ExpectMoneyLine[ec.ExExpectNo] = CurrMoney; } else { ExpectMoneyLine.Add(ec.ExExpectNo, CurrMoney); } return(suc); } }
public ExchangeChance <T> AddAChance <T>(ExchangeChance <T> ec) where T : TimeSerialData { DataRow dr = this.NewRow(); Eindex++; ec.Id = Eindex; dr["Id"] = Eindex; dr["ExpectNo"] = long.Parse(ec.ExpectNo); dr["ExExpectNo"] = ec.ExExpectNo; 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); }