//Here we will process the rejected messages and see if that's ok or not protected void ProcessReject(object param) { try { lock (TimeoutOrders) { Wrapper rejectWrapper = (Wrapper)param; string key = (string)rejectWrapper.GetField(RejectFields.KEY); string text = (string)rejectWrapper.GetField(RejectFields.Text); if (TimeoutOrders.ContainsKey(key)) { TimeoutOrders.Remove(key); } //Implement rejects if (OrdersSent.ContainsKey(key)) { DoLog(string.Format("<{0}>-Received reject message for Cl. Order Id {1}:{2}", Configuration.Name, key, text), Constants.MessageType.AssertFailed); OrdersSent.Remove(key); } } } catch (Exception ex) { DoLog(string.Format("{0}-Critical error processing a reject:{1}", Configuration.Name, ex.Message), Constants.MessageType.Error); } }
protected void ProcessExecutionReport(object param) { try { lock (TimeoutOrders) { Wrapper erWrapper = (Wrapper)param; string key = (string)erWrapper.GetField(ExecutionReportFields.KEY); string orderId = (string)erWrapper.GetField(ExecutionReportFields.OrderID); string clOrderId = (string)erWrapper.GetField(ExecutionReportFields.ClOrdID); if (OrdersSent.ContainsKey(key) && LastProcessedCounter.ContainsKey(key)) { DoLog(string.Format("<{0}>- Received order id {1} - cl order id {2}", Configuration.Name, orderId, clOrderId), Constants.MessageType.Information); try { int counter = Convert.ToInt32(erWrapper.GetField(ExecutionReportFields.Account)); int lastCounter = LastProcessedCounter[clOrderId]; //We validate that it's lower. No that it has a specific number if (counter == Configuration.ExecutionReportsPerOrder && counter == (lastCounter + 1)) { DoLog(string.Format("<{0}>- Received counter #{1} for cl. order id {2} which is the last counter and all the previous counter were received ok!. The count is ok!", Configuration.Name, counter, clOrderId), Constants.MessageType.AssertOk); ClearOrderTracking(clOrderId); } else { if (counter == (lastCounter + 1)) { LastProcessedCounter[clOrderId] = counter; } else { DoLog(string.Format("<{0}>- Recevied counter #{1} and expected #{2} for cl. order id {3} . Wrong counter number!", Configuration.Name, counter, lastCounter + 1, clOrderId), Constants.MessageType.AssertFailed); ClearOrderTracking(clOrderId); } } } catch (Exception ex) { DoLog(string.Format("<{0}>- Received an order Id with a counter that doesn't seem to be an int value: {1}", Configuration.Name, erWrapper.GetField(ExecutionReportFields.Account)), Constants.MessageType.AssertFailed); OrdersSent.Remove(clOrderId); } } //This must be an order we don't manage or that we have already rejected so the counter is considered to be not working } } catch (Exception ex) { DoLog(string.Format("<{0}>-Critical error processing a execution report:{1}", Configuration.Name, ex.Message), Constants.MessageType.AssertFailed); } }
private void ClearOrderTracking(string clOrderId) { TimeoutOrders.Remove(clOrderId); LastProcessedCounter.Remove(clOrderId); OrdersSent.Remove(clOrderId); }
protected void ProcessExecutionReport(object param) { try { lock (TimeoutOrders) { Wrapper erWrapper = (Wrapper)param; string key = (string)erWrapper.GetField(ExecutionReportFields.KEY); string orderId = (string)erWrapper.GetField(ExecutionReportFields.OrderID); string clOrderId = (string)erWrapper.GetField(ExecutionReportFields.ClOrdID); if (TimeoutOrders.ContainsKey(key)) { TimeoutOrders.Remove(key); } if (OrdersSent.ContainsKey(key)) { if (orderId.Contains("_")) { DoLog(string.Format("<{0}>- Received order id {1}", Configuration.Name, orderId), Constants.MessageType.AssertOk); string strCount = orderId.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries)[1]; try { int count = Convert.ToInt32(strCount); //We validate that it's lower. No that it has a specific number if (LastProcessedCounter.HasValue && LastProcessedCounter.Value < count) { DoLog(string.Format("<{0}>- Recevied an orderId counter {1} which is bigger than the number we had in memory. The count seems ok", Configuration.Name, count, LastProcessedCounter.HasValue ? LastProcessedCounter.Value.ToString() : "-"), Constants.MessageType.AssertOk); LastProcessedCounter = count; } else { if (LastProcessedCounter.HasValue) { DoLog(string.Format("<{0}>- Recevied an orderId counter {1} which is LOWER than the number we had in memory. What happened with the counter?", Configuration.Name, count, LastProcessedCounter.HasValue ? LastProcessedCounter.Value.ToString() : "-"), Constants.MessageType.AssertFailed); OrdersSent.Remove(key); } else { LastProcessedCounter = count; } } } catch (Exception ex) { DoLog(string.Format("<{0}>- Received an order Id with a counter that doesn't seem to be an int value: {1}", Configuration.Name, strCount), Constants.MessageType.AssertFailed); OrdersSent.Remove(key); } } else { DoLog(string.Format("<{0}>- Received an order Id whose format doesn't match the exepected one: {1}", Configuration.Name, orderId), Constants.MessageType.AssertFailed); OrdersSent.Remove(key); } } //This must be an order we don't manage or that we have already rejected so the counter is considered to be not working } } catch (Exception ex) { DoLog(string.Format("<{0}>-Critical error processing a execution report:{1}", Configuration.Name, ex.Message), Constants.MessageType.AssertFailed); } }