public bool IsContainDealId(int botId, long dealID) { lock (DictUserDealsLog) { if (!DictUserDealsLog.ContainsKey(botId)) { return(false); } foreach (var kvp in DictUserDealsLog[botId]) { foreach (var deal in kvp.Value) { if (deal.DealId == dealID) { return(true); } } } } return(false); }
/// <summary> /// Update deal's history log /// </summary> /// <param name="instrument"></param> /// <param name="rd"></param> private void UpdateDealsData(string instrument, CRawUserDeal rd) { CUserDeal userDeal = null; long timeMili = 0; CUserDeal dealWithSameId = null; int botId = (int)(rd.Ext_id_buy > 0 ? rd.Ext_id_buy : rd.Ext_id_sell); lock (DictUserDealsLog) { if (!DictUserDealsLog.ContainsKey(botId)) { DictUserDealsLog[botId] = new Dictionary <string, List <CUserDeal> >(); } if (!DictUserDealsLog[botId].ContainsKey(instrument)) { DictUserDealsLog[botId][instrument] = new List <CUserDeal>(); } dealWithSameId = DictUserDealsLog[botId][instrument].FirstOrDefault(a => a.ReplId == rd.ReplId); //deal doesn't have the same id if (dealWithSameId == null) { EnmDealDir dd = rd.Ext_id_buy > 0 ? EnmDealDir.Buy : EnmDealDir.Sell; userDeal = new CUserDeal { ReplId = rd.ReplId, Amount = rd.Amount, Moment = rd.Moment, Price = rd.Price, BuySell = dd, Fee = rd.Fee_buy + rd.Fee_sell, DealId = rd.Id_Deal //2018-06-13 }; DictUserDealsLog[botId][instrument].Add((CUserDeal)userDeal); // Plaza2Connector.TriggerRecalculateBot(botId, EnmBotEventCode.OnUserDeal, timeMili = CUtilTime.GetUnixTimestampMillis(userDeal.Moment); LatestDealsData.Update(botId, instrument, new CLatestTradeData { Dt_timestamp_ms = timeMili, ReplId = rd.ReplId, Dt = rd.Moment } ); CDBUserDeal dbUSerDeal = new CDBUserDeal(); CUtil.CopyObjProperties(userDeal, dbUSerDeal); dbUSerDeal.Instrument = instrument; dbUSerDeal.account_trade_Id = (int)botId; dbUSerDeal.stock_exch_id = UserDealsPosBoxClient.StockExchId; //StockExchangeId; dbUSerDeal.ReplId = rd.ReplId; dbUSerDeal.DealId = rd.Id_Deal; //2018-05-31 dbUSerDeal.Fee = rd.Fee_buy + rd.Fee_sell; //2018-05-31 UserDealsPosBoxClient.UpdateDBUserDealsLog(dbUSerDeal); } } }