Ejemplo n.º 1
0
        public async Task <GetExternalOrderStatusMessage> GetMessage(GetExternalOrderStatusRequest MyRequest)
        {
            try
            {
                _Environment   = MyRequest._EnvironmentSelected;
                _HeaderMessage = MyRequest._HeaderMessage;

                GetService(MyRequest);
                _OrderStatusMessage = await _MarketplaceAPIService.GetExternalOrderStatusAsync(MyRequest._HeaderMessage, MyRequest._MyOrderStatusRequest);

                _RequestXML = _RequestInterceptor.LastRequestXML;
                _MessageXML = _RequestInterceptor.LastResponseXML;
            }
            catch (System.Exception ex)
            {
                if (_OrderStatusMessage.ErrorMessage != null)
                {
                    _InnerErrorMessage = _OrderStatusMessage.ErrorMessage;
                }
                _OperationSuccess = false;
                _ErrorMessage     = ex.Message;
                _ErrorType        = ex.HelpLink;
                _RequestXML       = _RequestInterceptor.LastRequestXML;
                _MessageXML       = _RequestInterceptor.LastResponseXML;
            }
            return(this);
        }
Ejemplo n.º 2
0
        internal bool HandleOrderStatusMsg(OrderStatusMessage msg)
        {
            bool       res   = false;
            TradeOrder order = GetChildOrderByID(msg.OrderId);

            if (order != null)
            {
                switch (msg.Status)
                {
                case Constant.OrderCancelled:
                    if (order.Status != TradeOrderStatus.Cancelled)
                    {
                        order.Status = TradeOrderStatus.Cancelled;
                        res          = true;
                    }
                    ;
                    break;

                case Constant.OrderApiCancelled:
                    if (order.Status != TradeOrderStatus.Cancelled)
                    {
                        order.Status = TradeOrderStatus.Cancelled;
                        res          = true;
                    }
                    ;
                    break;

                case Constant.OrderSubmitted:
                case Constant.OrderPreSubmitted:
                    if (order.Status == TradeOrderStatus.PendingSubmit)
                    {
                        order.Status = TradeOrderStatus.Submitted;
                        res          = true;
                    }
                    else
                    {
                        Log.Error("Received order submitted msg, however current order status is  " + msg.Status);
                    };
                    break;

                case Constant.OrderFilled:
                    if (order.Status != TradeOrderStatus.Cancelled && order.Status != TradeOrderStatus.PendingCxl)
                    {
                        order.Status = TradeOrderStatus.Filled;
                        res          = true;
                    }
                    else
                    {
                        Log.Error("Received order OrderFilled msg, however current order status is  " + msg.Status);
                    };
                    break;
                }
            }
            else
            {
                Log.Error(string.Format("Error UpdateChildOrder. Cannot find order. ChildOrderID: {0}, ParentOrderID: {1}", msg.OrderId, this.ID));
            }

            return(res);
        }
        public void OrderLockedOnceSubmitted(OrderStatus status)
        {
            // Arrange
            const int OrderId = 9876;

            var findCommandCanExecuteChangedFired   = false;
            var submitCommandCanExecuteChangedFired = false;
            var deleteCommandCanExecuteChangedFired = false;

            var vm      = GetVm();
            var builder = new OrderBuilder();
            var order   = builder.Default.SetSymbol(DefaultSymbol).Order;

            vm.FindCommand.CanExecuteChanged   += (s, e) => findCommandCanExecuteChangedFired = true;;
            vm.SubmitCommand.CanExecuteChanged += (s, e) => submitCommandCanExecuteChangedFired = true;
            vm.DeleteCommand.CanExecuteChanged += (s, e) => deleteCommandCanExecuteChangedFired = true;
            vm.Orders.Add(order);
            order.Id = OrderId;

            // Act
            var message = new OrderStatusMessage(OrderId, status.ToString(), 0, 0, 0, 0, 0, 0, 0, null, 0);

            Messenger.Default.Send(new OrderStatusChangedMessage(order.Symbol.Code, message));

            // Assert
            Assert.True(findCommandCanExecuteChangedFired);
            Assert.True(order.IsLocked);
            Assert.False(vm.SubmitCommand.CanExecute(order));
            Assert.True(submitCommandCanExecuteChangedFired);
            Assert.True(deleteCommandCanExecuteChangedFired);
        }
Ejemplo n.º 4
0
        private void HandleOrderStatusMsg(OrderStatusMessage msg)
        {
            if (msg.Status != Constant.OrderSubmitted)
            {
                Log.Info(string.Format("Receive Order Status Msg. OrderID: {0}, Status: {1}", msg.OrderId, msg.Status));
            }

            bool updated = false;

            try
            {
                var parent = ParentOrderManager.Instance.FindAssociatedParentOrderByChildID(msg.OrderId);
                if (parent != null)
                {
                    updated = parent.HandleOrderStatusMsg(msg);
                }
                else
                {
                    Log.Error(string.Format("Cannot find associated Parent Order."));
                }

                if (IsInitialized && updated)
                {
                    StateManager.Save();
                }
            }catch (Exception ex)
            {
                Log.Error("HandleOrderStatusMsg error: " + ex.Message);
                Log.Error(ex.StackTrace);
            }
        }
        public void TradeRecordedToDatabaseWhenFilled()
        {
            // Arrange
            const double FillPrice = 10.03;
            const ushort Quantity  = 123;

            var builder = new OrdersViewModelBuilder().AddSingleOrder(DefaultSymbol, true);
            var vm      = builder.Build();

            vm.Orders[0].Quantity = Quantity;

            // Act
            var message = new OrderStatusMessage(0, OrderStatus.Filled.ToString(), 0, 0, FillPrice, 0, 0, 0, 0, null, 0);

            Messenger.Default.Send(new OrderStatusChangedMessage(DefaultSymbol, message));

            // Assert
            builder.TradeRepository.Received().AddTrade(Arg.Is <Trade>(x =>
                                                                       x.Direction == Direction.Buy &&
                                                                       x.Quantity == Quantity &&
                                                                       x.EntryPrice == FillPrice &&
                                                                       x.ExitPrice == null &&
                                                                       x.ExitTimeStamp == null &&
                                                                       x.ProfitLoss == null));
        }
Ejemplo n.º 6
0
        private void ibClient_HandleOrderStatus(OrderStatusMessage message)
        {
            if (OnOrderStatusEvent != null)
            {
                OnOrderStatusMessage msg = new OnOrderStatusMessage(message);

                OnOrderStatusEvent(msg);
            }
        }
        private bool ProcessOrderStatusMessage(OrderStatusMessage message)
        {
            if (message.HasOrderId())
            {
                return(base.OnSendInMessage(message));
            }

            return(ProcessInSubscriptionMessage(message));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Process <see cref="OrderStatusMessage"/>.
        /// </summary>
        /// <param name="message">A message requesting current registered orders and trades.</param>
        /// <returns>A message requesting current registered orders and trades.</returns>
        private OrderStatusMessage ProcessOrderStatus(OrderStatusMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (!message.IsSubscribe)
            {
                return(message);
            }

            var transId = message.TransactionId;

            _orderStatusIds.Add(transId);

            if (!message.HasOrderId() && message.OriginalTransactionId == 0 && Settings.DaysLoad > TimeSpan.Zero)
            {
                var from = message.From ?? DateTime.UtcNow.Date - Settings.DaysLoad;
                var to   = message.To;

                if (Settings.IsMode(StorageModes.Snapshot))
                {
                    var storage = (ISnapshotStorage <string, ExecutionMessage>)GetSnapshotStorage(DataType.Transactions);

                    foreach (var snapshot in storage.GetAll(from, to))
                    {
                        snapshot.OriginalTransactionId = transId;
                        snapshot.SetSubscriptionIds(subscriptionId: transId);
                        RaiseNewOutMessage(snapshot);

                        from = snapshot.ServerTime;
                    }

                    if (from >= to)
                    {
                        return(null);
                    }

                    message.From = from;
                }
                else if (Settings.IsMode(StorageModes.Incremental))
                {
                    if (!message.SecurityId.IsDefault())
                    {
                        // TODO restore last actual state from incremental messages

                        //GetStorage<ExecutionMessage>(msg.SecurityId, ExecutionTypes.Transaction)
                        //	.Load(from, to)
                        //	.ForEach(RaiseStorageMessage);
                    }
                }
            }

            return(message);
        }
        private void ProcessOrderStatusMessage(OrderStatusMessage message)
        {
            if (message.HasOrderId())
            {
                base.OnSendInMessage(message);
                return;
            }

            ProcessInSubscriptionMessage(message, DataType.Transactions);
        }
        private bool ProcessOrderStatus(OrderStatusMessage message)
        {
            if (message.Adapter != null && message.Adapter != this)
            {
                return(base.OnSendInMessage(message));
            }

            message = _storageProcessor.ProcessOrderStatus(message, RaiseStorageMessage);

            return(message == null || base.OnSendInMessage(message));
        }
Ejemplo n.º 11
0
 private void handleOrderStatus(OrderStatusMessage statusMessage)
 {
     for (int i = 0; i < liveOrdersGrid.Rows.Count; i++)
     {
         if (liveOrdersGrid[0, i].Value.Equals(statusMessage.PermId))
         {
             liveOrdersGrid[7, i].Value = statusMessage.Status;
             return;
         }
     }
 }
Ejemplo n.º 12
0
        /// <inheritdoc />
        public void UnSubscribeOrders()
        {
            var lookupMsg = new OrderStatusMessage
            {
                TransactionId = TransactionIdGenerator.GetNextId(),
                IsSubscribe   = false,
            };

            this.AddInfoLog(nameof(UnSubscribeOrders));
            SendInMessage(lookupMsg);
        }
        public void Process(OrderStatusMessage orderStatusMessage,
            Order order)
        {
            // Apply the changes to the Order from the OrderStatusMessage
            updateTheOrder(order);

            // Find the first IOrderHandler that "knows" how
            // to process this Order
            IOrderHandler handler =
                Array.Find(_handlers, h => h.CanProcess(order));

            handler.ProcessOrder(order);
        }
Ejemplo n.º 14
0
 private void ibClient_HandleOrderStatus(OrderStatusMessage statusMessage)
 {
     lock (_openOrderLockObj)
     {
         for (int i = 0; i < _openOrders.Count; i++)
         {
             if (_openOrders[i].Order.PermId == statusMessage.PermId)
             {
                 _openOrders[i].OrderStatus = statusMessage;
                 UpdateOrderMessageToDatabase(_openOrders[i]);
                 return;
             }
         }
     }
 }
Ejemplo n.º 15
0
        private void handleOrderStatus(OrderStatusMessage statusMessage)
        {
            //MessageBox.Show("handleOrderStatus: " + statusMessage);

            /*
             * for (int i = 0; i < liveOrdersGrid.Rows.Count; i++)
             * {
             *      if (liveOrdersGrid[0, i].Value.Equals(statusMessage.PermId))
             *      {
             *              liveOrdersGrid[8, i].Value = statusMessage.Status;
             *              return;
             *      }
             * }
             */
        }
        public void Process(OrderStatusMessage orderStatusMessage)
        {
            // Get the connection string from configuration
            string connectionString =
                ConfigurationManager.ConnectionStrings["Main"]
                    .ConnectionString;

            Order order = null;

            using (SqlConnection connection =
                new SqlConnection(connectionString))
            {
                // go get some data from the database
                order = fetchData(orderStatusMessage, connection);
            }

            // Apply the changes to the Order from the OrderStatusMessage
            updateTheOrder(order);

            // International orders have a unique set of business rules
            if (order.IsInternational)
            {
                processInternationalOrder(order);
            }

                // We need to treat larger orders in a special manner
            else if (order.LineItems.Count > 10)
            {
                processLargeDomesticOrder(order);
            }

                // Smaller domestic orders
            else
            {
                processRegularDomesticOrder(order);
            }

            // Ship the order if it's ready
            if (order.IsReadyToShip())
            {
                ShippingGateway gateway = new ShippingGateway();

                // Transform the Order object into a Shipment
                ShipmentMessage message =
                    createShipmentMessageForOrder(order);
                gateway.SendShipment(message);
            }
        }
Ejemplo n.º 17
0
            public void UnSubscribe(Subscription subscription)
            {
                if (subscription == null)
                {
                    throw new ArgumentNullException(nameof(subscription));
                }

                ISubscriptionMessage unsubscribe;

                if (subscription.DataType.IsMarketData)
                {
                    unsubscribe = new MarketDataMessage();
                }
                else if (subscription.DataType == DataType.Transactions)
                {
                    unsubscribe = new OrderStatusMessage();
                }
                else if (subscription.DataType == DataType.PositionChanges)
                {
                    unsubscribe = new PortfolioLookupMessage();
                }
                else if (subscription.DataType.IsPortfolio)
                {
                    unsubscribe = new PortfolioMessage();
                }
                else
                {
                    throw new ArgumentOutOfRangeException(nameof(subscription), subscription.DataType, LocalizedStrings.Str1219);
                }

                //// "immediate" unsubscribe
                //if (unsubscribe == null)
                //{
                //	lock (_syncObject)
                //	{
                //		_subscriptions.Remove(subscription.TransactionId);
                //	}

                //	return;
                //}

                unsubscribe.TransactionId         = _connector.TransactionIdGenerator.GetNextId();
                unsubscribe.OriginalTransactionId = subscription.TransactionId;
                unsubscribe.IsSubscribe           = false;

                SendRequest(unsubscribe, subscription);
            }
Ejemplo n.º 18
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <see cref="Message"/>
        /// <param name="message">Source message.</param>
        public OrderStatusData(Message message)
        {
            OrderStatusMessage orderStatusMessage = message.OrderStatusMsg.Clone();

            TraderId       = message.TraderId;
            ClientId       = DWConverter.FromProtoUuid(message.ClientId);
            Symbol         = SymbolsContainer.GetSymbol(message.MarketId);
            Direction      = orderStatusMessage.Side;
            Status         = orderStatusMessage.Status;
            PositionMargin = DWConverter.FromProtoDecimal(orderStatusMessage.PositionMargin);
            OrderMargin    = DWConverter.FromProtoDecimal(orderStatusMessage.OrderMargin);
            TraderBalance  = DWConverter.FromProtoDecimal(orderStatusMessage.TraderBalance);
            TraderBalance2 = DWConverter.FromProtoDecimal(orderStatusMessage.TraderBalance2);
            MarkPrice      = DWConverter.FromProtoDecimal(orderStatusMessage.MarkPrice);
            PaidPrice      = DWConverter.FromProtoDecimal(orderStatusMessage.PaidPrice);
            Price          = DWConverter.FromProtoDecimal(orderStatusMessage.Price);
            Quantity       = DWConverter.FromProtoDecimal(orderStatusMessage.Quantity);
            //this.TakeProfitPrice = message.FromProtoDecimal(orderStatusMessage.TakeProfitPrice);
            Upnl           = DWConverter.FromProtoDecimal(orderStatusMessage.Upnl);
            BuyOrderMargin = DWConverter.FromProtoDecimal(orderStatusMessage.BuyOrderMargin);
            Duration       = orderStatusMessage.Duration;
            Leverage       = orderStatusMessage.Leverage;
            OldContractId  = orderStatusMessage.OldContractId;
            OrderClientId  = DWConverter.FromProtoUuid(orderStatusMessage.OrderClientId);
            if (orderStatusMessage.OrderTimestamp == 0)
            {
                OrderTimestamp = DWConverter.FromLongDateTime(message.Timestamp);
            }
            else
            {
                OrderTimestamp = DWConverter.FromLongDateTime(orderStatusMessage.OrderTimestamp);
            }
            OrderType       = orderStatusMessage.OrderType;
            PaidPrice       = DWConverter.FromProtoDecimal(orderStatusMessage.PaidPrice);
            SellOrderMargin = DWConverter.FromProtoDecimal(orderStatusMessage.SellOrderMargin);
            Side            = orderStatusMessage.Side;
            //this.TakeProfitType = orderStatusMessage.TakeProfitType;
            Pnl = DWConverter.FromProtoDecimal(orderStatusMessage.Pnl);
            BuyOrderQuantity  = DWConverter.FromProtoDecimal(orderStatusMessage.BuyOrderQuantity);
            SellOrderQuantity = DWConverter.FromProtoDecimal(orderStatusMessage.SellOrderQuantity);
            AccumQuantity     = DWConverter.FromProtoDecimal(orderStatusMessage.AccumQuantity);
            OpenTime          = DWConverter.FromLongDateTime(orderStatusMessage.OpenTime);
            OrigClientId      = DWConverter.FromProtoUuid(orderStatusMessage.OrigClientId);
            OrigQuantity      = DWConverter.FromProtoDecimal(orderStatusMessage.OrigQuantity);
        }
        public void AddNewOrderStatusMessage(OrderStatusMessage orderStatusMessage)
        {
            using (var dbContext = new MyDBContext())
            {
                if (orderStatusMessage.Status.Contains("Cancel"))

                {
                    var openorder =
                        dbContext.OpenOrder.Where(
                            x => x.PermanentId == orderStatusMessage.PermanentId).ToList();
                    if (openorder?.Count > 0)
                    {
                        DeleteRange(openorder, dbContext);
                        SaveChanges(dbContext);
                    }
                }

                Add(orderStatusMessage, dbContext);
                SaveChanges(dbContext);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Subscription"/>.
        /// </summary>
        /// <param name="dataType">Data type info.</param>
        /// <param name="security">Security.</param>
        public Subscription(DataType dataType, Security security)
        {
            DataType = dataType ?? throw new ArgumentNullException(nameof(dataType));
            Security = security;

            if (dataType.IsMarketData)
            {
                MarketDataMessage = new MarketDataMessage
                {
                    DataType    = dataType.ToMarketDataType().Value,
                    Arg         = dataType.Arg,
                    IsSubscribe = true
                };

                if (Security != null)
                {
                    MarketDataMessage.FillSecurityInfo(Security);
                }
            }
            else if (dataType == DataType.Transactions)
            {
                OrderStatusMessage = new OrderStatusMessage {
                    IsSubscribe = true
                }
            }
            ;
            else if (dataType == DataType.PositionChanges)
            {
                PortfolioLookupMessage = new PortfolioLookupMessage {
                    IsSubscribe = true
                }
            }
            ;
            else
            {
                throw new ArgumentOutOfRangeException(nameof(dataType), dataType, LocalizedStrings.Str1219);
            }
        }
        private void ProcessOrderStatus(OrderStatusMessage message)
        {
            if (message == null)
            {
                var portfolioRefresh = false;

                var orders = _httpClient.RequestOpenOrders();

                var ids = _orderInfo.Keys.ToHashSet();

                foreach (var order in orders)
                {
                    ids.Remove(order.Id);

                    var info = _orderInfo.TryGetValue(order.Id);

                    if (info == null)
                    {
                        info = RefTuple.Create(TransactionIdGenerator.GetNextId(), (decimal)order.Amount);

                        _orderInfo.Add(order.Id, info);

                        ProcessOrder(order, (decimal)order.Amount, info.First, 0);

                        portfolioRefresh = true;
                    }
                    else
                    {
                        // balance existing orders tracked by trades
                    }
                }

                var trades = GetTrades();

                foreach (var trade in trades)
                {
                    ProcessTrade(trade);
                }

                foreach (var id in ids)
                {
                    // can be removed from ProcessTrade
                    if (!_orderInfo.TryGetAndRemove(id, out var info))
                    {
                        return;
                    }

                    SendOutMessage(new ExecutionMessage
                    {
                        ExecutionType         = ExecutionTypes.Transaction,
                        HasOrderInfo          = true,
                        OrderId               = id,
                        OriginalTransactionId = info.First,
                        ServerTime            = CurrentTime.ConvertToUtc(),
                        OrderState            = OrderStates.Done,
                    });

                    portfolioRefresh = true;
                }

                if (portfolioRefresh)
                {
                    ProcessPortfolioLookup(null);
                }
            }
            else
            {
                if (!message.IsSubscribe)
                {
                    return;
                }

                var orders = _httpClient.RequestOpenOrders().ToArray();

                foreach (var order in orders)
                {
                    var info = RefTuple.Create(TransactionIdGenerator.GetNextId(), (decimal)order.Amount);

                    _orderInfo.Add(order.Id, info);

                    ProcessOrder(order, (decimal)order.Amount, info.First, message.TransactionId);
                }

                var trades = GetTrades();

                foreach (var trade in trades)
                {
                    ProcessTrade(trade);
                }

                SendSubscriptionResult(message);
            }
        }
Ejemplo n.º 22
0
 private void ProcessInOrderStatusMessage(OrderStatusMessage message)
 {
     ProcessInSubscriptionMessage(message, message.TransactionId, _orderStatusSubscribers, null, null, null);
 }
Ejemplo n.º 23
0
 public OnOrderStatusMessage(OrderStatusMessage msg) :
     base(msg.OrderId, msg.Status, msg.Filled, msg.Remaining, msg.AvgFillPrice, msg.PermId, msg.ParentId, msg.LastFillPrice, msg.ClientId, msg.WhyHeld, msg.MktCapPrice)
 {
 }
 private Order fetchData(OrderStatusMessage message, SqlConnection connection)
 {
     return new Order();
 }
Ejemplo n.º 25
0
 public SubscriptionInfo(OrderStatusMessage original)
 {
     Original = original ?? throw new System.ArgumentNullException(nameof(original));
 }
Ejemplo n.º 26
0
 public void LookupOrders(OrderStatusMessage criteria)
 {
     SubscribeOrders(criteria);
 }
Ejemplo n.º 27
0
 static void client_OrderStatus(OrderStatusMessage e)
 {
     Console.WriteLine("Order Placed.");
 }
Ejemplo n.º 28
0
        /// <inheritdoc />
        protected override bool OnSendInMessage(Message message)
        {
            void AddInfo(OrderRegisterMessage regMsg)
            {
                if (regMsg is null)
                {
                    throw new ArgumentNullException(nameof(regMsg));
                }

                if (regMsg.OrderType == OrderTypes.Market || regMsg.Price == 0)
                {
                    return;
                }

                if (regMsg.TimeInForce == TimeInForce.MatchOrCancel || regMsg.TimeInForce == TimeInForce.CancelBalance)
                {
                    return;
                }

                lock (_sync)
                {
                    foreach (var info in _byId.Values)
                    {
                        if (info.BookSubscription.SecurityId == regMsg.SecurityId)
                        {
                            info.AddOrder(regMsg);
                        }
                    }
                }
            }

            switch (message.Type)
            {
            case MessageTypes.Reset:
            {
                lock (_sync)
                {
                    _byId.Clear();
                    _byBookId.Clear();
                    _byOrderStatusId.Clear();
                    _online.Clear();
                    _unsubscribeRequests.Clear();
                }

                break;
            }

            case MessageTypes.OrderRegister:
            case MessageTypes.OrderReplace:
            {
                AddInfo((OrderRegisterMessage)message);
                break;
            }

            case MessageTypes.OrderPairReplace:
            {
                var pairMsg = (OrderPairReplaceMessage)message;

                AddInfo(pairMsg.Message1);
                AddInfo(pairMsg.Message2);

                break;
            }

            case MessageTypes.MarketData:
            {
                var mdMsg = (MarketDataMessage)message;

                if (mdMsg.IsSubscribe)
                {
                    if (mdMsg.SecurityId == default)
                    {
                        break;
                    }

                    if (mdMsg.DataType2 != DataType.FilteredMarketDepth)
                    {
                        break;
                    }

                    var transId = mdMsg.TransactionId;

                    mdMsg = mdMsg.TypedClone();
                    mdMsg.TransactionId = TransactionIdGenerator.GetNextId();
                    mdMsg.DataType2     = DataType.MarketDepth;

                    var orderStatus = new OrderStatusMessage
                    {
                        TransactionId = TransactionIdGenerator.GetNextId(),
                        IsSubscribe   = true,
                        States        = new[] { OrderStates.Active },
                        SecurityId    = mdMsg.SecurityId,
                    };

                    var info = new FilteredMarketDepthInfo(transId, new Subscription(mdMsg, mdMsg), new Subscription(orderStatus, orderStatus));

                    lock (_sync)
                    {
                        _byId.Add(transId, info);
                        _byBookId.Add(mdMsg.TransactionId, info);
                        _byOrderStatusId.Add(orderStatus.TransactionId, info);
                    }

                    base.OnSendInMessage(mdMsg);
                    base.OnSendInMessage(orderStatus);

                    return(true);
                }
                else
                {
                    MarketDataMessage  bookUnsubscribe   = null;
                    OrderStatusMessage ordersUnsubscribe = null;

                    lock (_sync)
                    {
                        if (!_byId.TryGetValue(mdMsg.OriginalTransactionId, out var info))
                        {
                            break;
                        }

                        info.UnSubscribeId = mdMsg.TransactionId;

                        if (info.BookSubscription.State.IsActive())
                        {
                            bookUnsubscribe = new MarketDataMessage
                            {
                                TransactionId         = TransactionIdGenerator.GetNextId(),
                                OriginalTransactionId = info.BookSubscription.TransactionId,
                                IsSubscribe           = false,
                            };

                            _unsubscribeRequests.Add(bookUnsubscribe.TransactionId, Tuple.Create(info, true));
                        }

                        if (info.OrdersSubscription.State.IsActive())
                        {
                            ordersUnsubscribe = new OrderStatusMessage
                            {
                                TransactionId         = TransactionIdGenerator.GetNextId(),
                                OriginalTransactionId = info.OrdersSubscription.TransactionId,
                                IsSubscribe           = false,
                            };

                            _unsubscribeRequests.Add(ordersUnsubscribe.TransactionId, Tuple.Create(info, false));
                        }
                    }

                    if (bookUnsubscribe == null && ordersUnsubscribe == null)
                    {
                        RaiseNewOutMessage(new SubscriptionResponseMessage
                            {
                                OriginalTransactionId = mdMsg.TransactionId,
                                Error = new InvalidOperationException(LocalizedStrings.SubscriptionNonExist.Put(mdMsg.OriginalTransactionId)),
                            });
                    }
                    else
                    {
                        if (bookUnsubscribe != null)
                        {
                            base.OnSendInMessage(bookUnsubscribe);
                        }

                        if (ordersUnsubscribe != null)
                        {
                            base.OnSendInMessage(ordersUnsubscribe);
                        }
                    }

                    return(true);
                }
            }
            }

            return(base.OnSendInMessage(message));
        }
Ejemplo n.º 29
0
 private void ProcessOrderStatusMessage(OrderStatusMessage message)
 {
     ProcessInSubscriptionMessage(message, DataType.Transactions, default, (id, error) => null);
Ejemplo n.º 30
0
 /// <inheritdoc />
 public void SubscribeOrders(OrderStatusMessage criteria)
 {
     Subscribe(new Subscription(criteria, (SecurityMessage)null));
 }
Ejemplo n.º 31
0
 public async Task <IActionResult> Put(int id, [FromBody] OrderStatusMessage value)
 {
     throw new NotImplementedException();
 }