private bool IsOverflooded(TradeTransactionRequest request, MarketOrder order) { try { var isFlooded = RequestStorage.Instance.CheckOverflood(); if (isFlooded) { var errorResponse = new BrokerService.Contract.Entity.BrokerResponse { AccountId = request.Account, Mt4OrderId = request.ClosingPositionId ?? 0, RejectReason = OrderRejectReason.UnableMassCancel, Status = OrderStatus.Rejected, RejectReasonString = "overflood", RequestId = request.Id, ValueDate = DateTime.Now }; ServerInterface.NotifyClientOnOrderRejected(order, errorResponse.RejectReasonString); return(true); } } catch (Exception ex) { Logger.Error("Error in CheckOverflood()", ex); return(true); } return(false); }
public void RequestProcessed(BrokerService.Contract.Entity.BrokerResponse response) { var request = RequestStorage.Instance.FindRequest(response.RequestId); if (request == null) { Logger.Info("MT4 executor - исходный запрос не найден: " + response); return; } Logger.Info("Ответ MT4 executor: " + response); if (response.Status != OrderStatus.Executed) { return; } // закрытие ордера if (request.request.IsClosingRequest) { if (!response.Price.HasValue) { Logger.Error("Ответ MT4 executor - закрытие позиции - нет цены"); return; } ServerInterface.CloseOrder(request.requestedOrder.ID, response.Price.Value, PositionExitReason.Closed); return; } // открытие ордера if (!response.Price.HasValue) { response.RejectReason = OrderRejectReason.UnknownOrder; } if (response.RejectReason.HasValue && response.RejectReason.Value != OrderRejectReason.None) { ServerInterface.NotifyClientOnOrderRejected(request.requestedOrder, response.RejectReasonString); Logger.DebugFormat("{0}: order {1} is rejected for reason {2}", DealerCode, request.requestedOrder.ToStringShort(), response.RejectReason); return; } var order = request.requestedOrder; order.PriceEnter = (float)response.Price.Value; order.AccountID = request.request.Account; order.TimeEnter = DateTime.Now; order.State = PositionState.Opened; order.MasterOrder = response.Mt4OrderId; int openedOrderId; ServerInterface.SaveOrderAndNotifyClient(order, out openedOrderId); }
public void RequestProcessed(BrokerService.Contract.Entity.BrokerResponse response) { var request = RequestStorage.Instance.FindRequest(response.RequestId); if (request == null) { Logger.Info("MT4 executor - исходный запрос не найден: " + response); return; } Logger.Info("Ответ MT4 executor: " + response); if (response.Status != OrderStatus.Executed) { return; } // закрытие ордера if (request.request.IsClosingRequest) { if (!response.Price.HasValue) { Logger.Error("Ответ MT4 executor - закрытие позиции - нет цены"); return; } ServerInterface.CloseOrder(request.requestedOrder.ID, response.Price.Value, PositionExitReason.Closed); return; } // открытие ордера if (!response.Price.HasValue) { response.RejectReason = OrderRejectReason.UnknownOrder; } if (response.RejectReason.HasValue && response.RejectReason.Value != OrderRejectReason.None) { ServerInterface.NotifyClientOnOrderRejected(request.requestedOrder, response.RejectReasonString); Logger.DebugFormat("{0}: order {1} is rejected for reason {2}", DealerCode, request.requestedOrder.ToStringShort(), response.RejectReason); return; } // сравнить запрошенную и итоговые цены if (request.request.RequestedPrice > 0) { // ReSharper disable once PossibleInvalidOperationException var delta = Math.Abs(response.Price.Value - request.request.RequestedPrice); var deltaRel = delta * 100 / Math.Min(response.Price.Value, request.request.RequestedPrice); if (deltaRel > 5) { var errorStr = string.Format("{0}: order {1} is rejected: requested price ({2}) is far beyond the resulted price ({3})", DealerCode, request.requestedOrder.ToStringShort(), request.request.RequestedPrice.ToStringUniformPriceFormat(true), response.Price.Value.ToStringUniformPriceFormat(true)); Logger.Error(errorStr); response.RejectReason = OrderRejectReason.UnknownOrder; response.RejectReasonString = errorStr; ServerInterface.NotifyClientOnOrderRejected(request.requestedOrder, response.RejectReasonString); return; } } var order = request.requestedOrder; order.PriceEnter = (float)response.Price.Value; order.AccountID = request.request.Account; order.TimeEnter = DateTime.Now; order.State = PositionState.Opened; order.MasterOrder = response.Mt4OrderId; int openedOrderId; ServerInterface.SaveOrderAndNotifyClient(order, out openedOrderId); }
private bool IsOverflooded(TradeTransactionRequest request, MarketOrder order) { try { var isFlooded = RequestStorage.Instance.CheckOverflood(); if (isFlooded) { var errorResponse = new BrokerService.Contract.Entity.BrokerResponse { AccountId = request.Account, Mt4OrderId = request.ClosingPositionId ?? 0, RejectReason = OrderRejectReason.UnableMassCancel, Status = OrderStatus.Rejected, RejectReasonString = "overflood", RequestId = request.Id, ValueDate = DateTime.Now }; ServerInterface.NotifyClientOnOrderRejected(order, errorResponse.RejectReasonString); return true; } } catch (Exception ex) { Logger.Error("Error in CheckOverflood()", ex); return true; } return false; }