private void ProcessUserTradeExecute(JArray jarrTe) { ResponseTrades rt = jarrTe.ToObject <ResponseTrades>(); Log(String.Format("[USER TRADE EXECUTE] <== {0}", rt.ToString())); _client.UpdateUserDeals(rt); }
private void ProcessUserTradeUpdate(JArray jarrTu) { ResponseTrades rt = jarrTu.ToObject <ResponseTrades>(); Log(String.Format("[USER TRADE UPDATE] <== {0}", rt.ToString())); _client.UpdateUserDealsLateUpd(rt); }
private void AddDealNoBotId(ResponseTrades rt) { if (_lstDealsNoBotId.Find(el => el.Id == rt.Id) == null) { _lstDealsNoBotId.Add(rt); Log(String.Format("Remeber deal with no BotId orderId={0}", rt.OrderId)); } }
public void Update(ResponseTrades[] rt) { for (int i = rt.Length - 1; i >= 0; i--) { ResponseTrades trade = rt[i]; Log(trade.ToString()); DateTime dtCreate = CUtilTime.DateTimeFromUnixTimestampMillis( Convert.ToInt64(trade.MtsCreate)); if ((DateTime.UtcNow - dtCreate).TotalHours > _parHourOld) { continue; } if (_lst.Find(el => el.Id == trade.Id) == null) //not found { long botId = _client.GetBotIdBfxRest(trade.OrderId); if (botId > 0)// botId found { CDBBfxTrades bfxTrade = new CDBBfxTrades { Id = trade.Id, BotId = botId, MtsCreate = trade.MtsCreate, OrderId = trade.OrderId, Pair = trade.Pair.Remove(0, 1), ExecAmount = Convert.ToDecimal(trade.ExecAmount), ExecPrice = Convert.ToDecimal(trade.ExecPrice), Maker = trade.Maker, Fee = Convert.ToDecimal(trade.Fee), FeeCurrency = trade.FeeCurrency, OrderPrice = Convert.ToDecimal(trade.OrderPrice), DtCreate = dtCreate }; _lst.Add(bfxTrade); _client.DBCommunicator.QueueData(bfxTrade); if (_lst.Count > 0) { if ((DateTime.UtcNow - _lst[0].DtCreate).TotalHours > _parHourOld) { _lst.RemoveAt(0); Log(String.Format("Remove first. Count={0}", _lst.Count)); } } } } } }
/// <summary> /// Calling on "te" (TradeExecute) bifinex events. /// Ask UserOrderBoxCrypto to get botId based on OrderId. /// If BotId found -do call Update if not do save to /// _lstNotProcessedDeals for using this data later. /// /// /// Call from CBitfinexWebSockConnector.ProcessUserTradeExecute /// </summary> /// <param name="rt"></param> public void UpdateUserDeals(ResponseTrades rt) { Log("[UpdateUserDeals] " + rt.ToString()); EnmOrderDir dir = rt.ExecAmount > 0 ? EnmOrderDir.Buy : EnmOrderDir.Sell; string instrument = rt.Pair.Remove(0, 1); //remove 't' //long iAmount = CUtilConv.GetIntVolume(Convert.ToDecimal(rt.ExecAmount), GetDecimalVolume(instrument)); decimal dcmlAmount = Convert.ToDecimal(rt.ExecAmount); DateTime moment = CUtilTime.DateTimeFromUnixTimestampMillis(rt.MtsCreate); int botId = _userOrderBoxCrypto.GetBotIdOfOrder(instrument, rt.OrderId); if (botId > 0) //botId found { Log("[UpdateUserDeals] botId=" + botId); _userDealsPosBoxCrypto.Update(rt.Id, rt.OrderId, instrument, dir, dcmlAmount, botId, Convert.ToDecimal(rt.ExecPrice), moment, rt.MtsCreate, (decimal)rt.Fee); //2018-06-13 common situation - remember that no fee //to remove it if fee will be recieved and get from rest if not if ((decimal)rt.Fee == 0) { lock (_lstDealsWithNoFee) _lstDealsWithNoFee.Add(rt); } } else //botId not found { //Write error for now (debugging). In the future - remove error msg. Error("UpdateUserDeals. Bot id not found"); //Put to list of deals to process it later (on "tu") _lstNotProcessedDeals.Add(rt); //add 2018-05-24 AddDealNoBotId(rt); // _lstDealsNoBotId.Add(rt); } }
/// <summary> /// Call when: /// /// Trade update message triggered. Possible two cases: /// /// 1) When we've not recieved trade execute message - do full update /// 2) When we already recieved Trade execute message (TE) - just update fee /// /// Call from: /// /// CBitfinexWeebSockConnector.ProcessUserTradeUpdate /// /// /// </summary> /// <param name="rt"></param> public void UpdateUserDealsLateUpd(ResponseTrades rt) { Log("[UpdateUserDealsLateUpd] " + rt.ToString()); EnmOrderDir dir = rt.ExecAmount > 0 ? EnmOrderDir.Buy : EnmOrderDir.Sell; //TODO change to deal dir EnmDealDir dealDir = rt.ExecAmount > 0 ? EnmDealDir.Buy : EnmDealDir.Sell; //TODO change to deal dir string instrument = rt.Pair.Remove(0, 1); //remove 't' decimal dcmlAmount = Convert.ToDecimal(rt.ExecAmount); DateTime moment = CUtilTime.DateTimeFromUnixTimestampMillis(rt.MtsCreate); int botId = _userOrderBoxCrypto.GetBotIdOfOrder(instrument, rt.OrderId); //fee recieved no worry about "no fee" deals if (rt.Fee != 0) { lock (_lstDealsWithNoFee) { _lstDealsWithNoFee.RemoveAll(el => el.Id == rt.Id); } } //if deal is not processed by "trade execute message" yet - //do full update. bool bNotProcessedYet = (_lstNotProcessedDeals.Find(el => el.Id == rt.Id) != null); //Deal was not processed yet - do full update if (bNotProcessedYet) { if (botId > 0) //botId found { Log("[UpdateUserDealsLateUpd]. First processing deal. botId=" + botId); _userDealsPosBoxCrypto.Update(rt.Id, rt.OrderId, instrument, dir, dcmlAmount, botId, Convert.ToDecimal(rt.ExecPrice), moment, rt.MtsCreate, (decimal)rt.Fee); //deal processed no need update it - do remove _lstNotProcessedDeals.RemoveAll(el => el.Id == rt.Id); } else //botId not found - now having a REAL problem { Error("CAUTION ! UpdateUserDealsLateUpd. BotId not found !"); //2018-05-14 remember deals with no botId for future processing //2018-05-24 refact to funct AddDealNoBotId(rt); } } //if deal has already processed by "trade execute message" just update fee data else { Log("[UpdateUserDealsLateUpd] Update fee"); _userDealsPosBoxCrypto.UpdateFee(botId, instrument, rt.Id, Math.Abs(Convert.ToDecimal(rt.Fee)), dealDir ); //TODO update fee if order if not found } }
public void UpdateUserDealsLateUpd(ResponseTrades rt) { }