private static bool ProcessRequest(FxcmBroker fxcm, O2GRequest request) { var responseListener = new ResponseListener(fxcm.Session); fxcm.Session.subscribeResponse(responseListener); try { responseListener.SetRequestID(request.RequestID); fxcm.Session.sendRequest(request); if (responseListener.WaitEvents()) { if (!string.IsNullOrEmpty(responseListener.Error)) { Log.Error($"Unable to process request - {responseListener.Error}"); return(false); } return(true); } else { Log.Error($"Unable to process request"); return(false); } } finally { fxcm.Session.unsubscribeResponse(responseListener); } }
private static bool ProcessOrderRequest(FxcmBroker fxcm, O2GRequest request, out string orderId) { var ret = string.Empty; var waitOrder = new ManualResetEvent(false); var responseListener = new ResponseListener( fxcm.Session, data => { O2GResponseReaderFactory factory = fxcm.Session.getResponseReaderFactory(); if (factory != null) { O2GTablesUpdatesReader reader = factory.createTablesUpdatesReader(data); for (int ii = 0; ii < reader.Count; ii++) { if (reader.getUpdateTable(ii) == O2GTableType.Orders) { O2GOrderRow orderRow = reader.getOrderRow(ii); if (reader.getUpdateType(ii) == O2GTableUpdateType.Insert) { ret = orderRow.OrderID; waitOrder.Set(); break; } } } } }); fxcm.Session.subscribeResponse(responseListener); try { responseListener.SetRequestID(request.RequestID); fxcm.Session.sendRequest(request); if (responseListener.WaitEvents()) { if (!string.IsNullOrEmpty(responseListener.Error)) { Log.Error($"Unable to process request - {responseListener.Error}"); orderId = ret; return(false); } // Get order ID waitOrder.WaitOne(); orderId = ret; return(true); } else { Log.Error($"Unable to process request"); orderId = ret; return(false); } } finally { fxcm.Session.unsubscribeResponse(responseListener); } }