Beispiel #1
0
        // ExecutionReport message handler
        private void OnExecutionReport(ExecutionReport executionReport)
        {
            Console.WriteLine("OnExecutionReport()");
            Console.WriteLine("\tRequestId = {0}", executionReport.getRequestID());

            Console.WriteLine("\tgetOrderID() = " + executionReport.getOrderID());
            Console.WriteLine("\tgetFXCMPosID() = " + executionReport.getFXCMPosID());
            Console.WriteLine("\tgetAccount() = " + executionReport.getAccount());
            Console.WriteLine("\tgetTransactTime() = " + executionReport.getTransactTime());
            Console.WriteLine("\tgetExecType() = " + executionReport.getExecType());
            Console.WriteLine("\tgetFXCMOrdStatus() = " + executionReport.getFXCMOrdStatus());
            Console.WriteLine("\tgetOrdStatus() = " + executionReport.getOrdStatus());
            Console.WriteLine("\tgetPrice() = " + executionReport.getPrice());
            Console.WriteLine("\tgetStopPx() = " + executionReport.getStopPx());
            Console.WriteLine("\tgetOrderQty() = " + executionReport.getOrderQty());
            Console.WriteLine("\tgetCumQty() = " + executionReport.getCumQty());
            Console.WriteLine("\tgetLastQty() = " + executionReport.getLastQty());
            Console.WriteLine("\tgetLeavesQty() = " + executionReport.getLeavesQty());
            Console.WriteLine("\tgetFXCMErrorDetails() = " + executionReport.getFXCMErrorDetails());
            Console.WriteLine();

            var orderId = executionReport.getOrderID();

            if (orderId != "NONE")
            {
                _orders[orderId] = executionReport;
                _orderRequests[executionReport.getRequestID()] = executionReport;
            }

            if (executionReport.getRequestID() == _currentRequest)
            {
                var status = executionReport.getFXCMOrdStatus().getCode();
                if (executionReport.isLastRptRequested() &&
                    status != IFixValueDefs.__Fields.FXCMORDSTATUS_PENDING_CANCEL &&
                    status != IFixValueDefs.__Fields.FXCMORDSTATUS_EXECUTING &&
                    status != IFixValueDefs.__Fields.FXCMORDSTATUS_INPROCESS)
                {
                    _requestOrderEvent.Set();
                }
            }
        }
        /// <summary>
        /// ExecutionReport message handler
        /// </summary>
        private void OnExecutionReport(ExecutionReport message)
        {
            var orderId = message.getOrderID();
            var orderStatus = message.getFXCMOrdStatus();

            if (orderId != "NONE" && message.getAccount() == _accountId)
            {
                if (_openOrders.ContainsKey(orderId) && OrderIsClosed(orderStatus.getCode()))
                {
                    _openOrders.Remove(orderId);
                }
                else
                {
                    _openOrders[orderId] = message;
                }

                Order order;
                if (_mapFxcmOrderIdsToOrders.TryGetValue(orderId, out order))
                {
                    // existing order
                    if (!OrderIsBeingProcessed(orderStatus.getCode()))
                    {
                        order.PriceCurrency = message.getCurrency();

                        var orderEvent = new OrderEvent(order, DateTime.UtcNow, 0)
                        {
                            Status = ConvertOrderStatus(orderStatus),
                            FillPrice = Convert.ToDecimal(message.getPrice()),
                            FillQuantity = Convert.ToInt32(message.getSide() == SideFactory.BUY ? message.getLastQty() : -message.getLastQty())
                        };

                        // we're catching the first fill so we apply the fees only once
                        if ((int)message.getCumQty() == (int)message.getLastQty() && message.getLastQty() > 0)
                        {
                            var security = _securityProvider.GetSecurity(order.Symbol);
                            orderEvent.OrderFee = security.FeeModel.GetOrderFee(security, order);
                        }

                        _orderEventQueue.Enqueue(orderEvent);
                    }
                }
                else if (_mapRequestsToOrders.TryGetValue(message.getRequestID(), out order))
                {
                    _mapFxcmOrderIdsToOrders[orderId] = order;
                    order.BrokerId.Add(orderId);
                    order.PriceCurrency = message.getCurrency();

                    // new order
                    var orderEvent = new OrderEvent(order, DateTime.UtcNow, 0)
                    {
                        Status = ConvertOrderStatus(orderStatus)
                    };

                    _orderEventQueue.Enqueue(orderEvent);
                }
            }

            if (message.getRequestID() == _currentRequest)
            {
                if (message.isLastRptRequested())
                {
                    if (orderId == "NONE" && orderStatus.getCode() == IFixValueDefs.__Fields.FXCMORDSTATUS_REJECTED)
                    {
                        if (message.getSide() != SideFactory.UNDISCLOSED)
                        {
                            var messageText = message.getFXCMErrorDetails().Replace("\n", "");
                            Log.Trace("FxcmBrokerage.OnExecutionReport(): " + messageText);
                            OnMessage(new BrokerageMessageEvent(BrokerageMessageType.Warning, "OrderSubmitReject", messageText));
                        }

                        _isOrderSubmitRejected = true;
                    }

                    _mapRequestsToAutoResetEvents[_currentRequest].Set();
                    _mapRequestsToAutoResetEvents.Remove(_currentRequest);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// ExecutionReport message handler
        /// </summary>
        private void OnExecutionReport(ExecutionReport message)
        {
            var orderId     = message.getOrderID();
            var orderStatus = message.getFXCMOrdStatus();

            if (orderId != "NONE" && message.getAccount() == _accountId)
            {
                if (_openOrders.ContainsKey(orderId) && OrderIsClosed(orderStatus.getCode()))
                {
                    _openOrders.Remove(orderId);
                }
                else
                {
                    _openOrders[orderId] = message;
                }

                Order order;
                if (_mapFxcmOrderIdsToOrders.TryGetValue(orderId, out order))
                {
                    // existing order
                    if (!OrderIsBeingProcessed(orderStatus.getCode()))
                    {
                        var status = ConvertOrderStatus(orderStatus);

                        int id;
                        // if we get a Submitted status and we had placed an order update, this new event is flagged as an update
                        var isUpdate = status == OrderStatus.Submitted && _orderUpdates.TryRemove(order.Id, out id);
                        var security = _securityProvider.GetSecurity(order.Symbol);
                        order.PriceCurrency = security.SymbolProperties.QuoteCurrency;

                        var orderEvent = new OrderEvent(order,
                                                        DateTime.UtcNow,
                                                        OrderFee.Zero)
                        {
                            Status       = isUpdate ? OrderStatus.UpdateSubmitted : status,
                            FillPrice    = Convert.ToDecimal(message.getPrice()),
                            FillQuantity = Convert.ToInt32(message.getSide() == SideFactory.BUY ? message.getLastQty() : -message.getLastQty()),
                        };

                        // we're catching the first fill so we apply the fees only once
                        if ((int)message.getCumQty() == (int)message.getLastQty() && message.getLastQty() > 0)
                        {
                            orderEvent.OrderFee = security.FeeModel.GetOrderFee(
                                new OrderFeeParameters(security, order));
                        }

                        _orderEventQueue.Enqueue(orderEvent);
                    }
                }
                else if (_mapRequestsToOrders.TryGetValue(message.getRequestID(), out order))
                {
                    _mapFxcmOrderIdsToOrders[orderId] = order;
                    order.BrokerId.Add(orderId);
                    order.PriceCurrency = _securityProvider.GetSecurity(order.Symbol).SymbolProperties.QuoteCurrency;

                    // new order
                    var orderEvent = new OrderEvent(order,
                                                    DateTime.UtcNow,
                                                    OrderFee.Zero)
                    {
                        Status = ConvertOrderStatus(orderStatus)
                    };

                    _orderEventQueue.Enqueue(orderEvent);
                }
            }

            if (message.getRequestID() == _currentRequest)
            {
                if (message.isLastRptRequested())
                {
                    if (orderId == "NONE" && orderStatus.getCode() == IFixValueDefs.__Fields.FXCMORDSTATUS_REJECTED)
                    {
                        if (message.getSide() != SideFactory.UNDISCLOSED)
                        {
                            var messageText = message.getFXCMErrorDetails().Replace("\n", "");
                            Log.Trace("FxcmBrokerage.OnExecutionReport(): " + messageText);
                            OnMessage(new BrokerageMessageEvent(BrokerageMessageType.Warning, "OrderSubmitReject", messageText));
                        }

                        _isOrderSubmitRejected = true;
                    }

                    AutoResetEvent autoResetEvent;
                    if (_mapRequestsToAutoResetEvents.TryGetValue(_currentRequest, out autoResetEvent))
                    {
                        autoResetEvent.Set();
                        _mapRequestsToAutoResetEvents.Remove(_currentRequest);
                    }
                }
            }
        }
Beispiel #4
0
        // ExecutionReport message handler
        private void OnExecutionReport(ExecutionReport executionReport)
        {
            Console.WriteLine("OnExecutionReport()");
            Console.WriteLine("\tRequestId = {0}", executionReport.getRequestID());

            Console.WriteLine("\tgetOrderID() = " + executionReport.getOrderID());
            Console.WriteLine("\tgetFXCMPosID() = " + executionReport.getFXCMPosID());
            Console.WriteLine("\tgetAccount() = " + executionReport.getAccount());
            Console.WriteLine("\tgetTransactTime() = " + executionReport.getTransactTime());
            Console.WriteLine("\tgetExecType() = " + executionReport.getExecType());
            Console.WriteLine("\tgetFXCMOrdStatus() = " + executionReport.getFXCMOrdStatus());
            Console.WriteLine("\tgetOrdStatus() = " + executionReport.getOrdStatus());
            Console.WriteLine("\tgetPrice() = " + executionReport.getPrice());
            Console.WriteLine("\tgetStopPx() = " + executionReport.getStopPx());
            Console.WriteLine("\tgetOrderQty() = " + executionReport.getOrderQty());
            Console.WriteLine("\tgetCumQty() = " + executionReport.getCumQty());
            Console.WriteLine("\tgetLastQty() = " + executionReport.getLastQty());
            Console.WriteLine("\tgetLeavesQty() = " + executionReport.getLeavesQty());
            Console.WriteLine("\tgetFXCMErrorDetails() = " + executionReport.getFXCMErrorDetails());
            Console.WriteLine();

            var orderId = executionReport.getOrderID();
            if (orderId != "NONE")
            {
                _orders[orderId] = executionReport;
                _orderRequests[executionReport.getRequestID()] = executionReport;
            }

            if (executionReport.getRequestID() == _currentRequest)
            {
                var status = executionReport.getFXCMOrdStatus().getCode();
                if (executionReport.isLastRptRequested() &&
                    status != IFixValueDefs.__Fields.FXCMORDSTATUS_PENDING_CANCEL &&
                    status != IFixValueDefs.__Fields.FXCMORDSTATUS_EXECUTING &&
                    status != IFixValueDefs.__Fields.FXCMORDSTATUS_INPROCESS)
                {
                    _requestOrderEvent.Set();
                }
            }
        }