public void EnqueueUpdateMoneyData(int botId) { var res = _dictBotIdConnId.FirstOrDefault(a => a.Key == botId); if (res.Key == 0) { return; //not found } int connId = res.Value; CUserMoney userMon = new CUserMoney(); CUtil.CopyObjProperties(_client.AccountsMoney[botId], userMon.AccountMoney); CAccountTrade accTr = new CAccountTrade(); CUtil.CopyObjProperties(_client.AccountsTrade[botId], accTr); //injection ! //TODO normal in the future accTr.money_sess_limit = _client.GetSessionLimit(botId); userMon.ListAccountTrade.Add(accTr); _bqTraderData.Add(new CTradingData { ConnId = connId, Data = (object)userMon, Event = enmTradingEvent.UpdateMoneyData } ); }
/// <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); } } }