Exemplo n.º 1
0
        //private readonly Dictionary<string, ShortOrderInfo> ordersByCode = new Dictionary<string, ShortOrderInfo>();
        //private readonly Dictionary<string, SortedList<decimal, int>> ordersBySecurityAndPrice = new Dictionary<string, SortedList<decimal, int>>();

        //private sealed class ShortOrderInfo
        //{
        //    public string Security { get; set; }

        //    public BuySell Operation { get; set; }
        //    public long Quantity { get; set; }
        //    public decimal Price { get; set; }
        //}

        private void InfoClient_OnInfoOrder(InfoOrder order)
        {
            var security = order.security + "|" + order.board;

            if (string.IsNullOrEmpty(security))
            {
                //Logger.DebugFormat("Получено обновление заявки с пустым полем security. OrderId: {0}", order.code);
                return;
            }

            if (!buildersMap.TryGetValue(security, out var builder))
            {
                var instrument = connector.ResolveSymbolAsync(security).Result;
                if (instrument == null)
                {
                    return;
                }

                builder = new OrderBookBuilder(instrument);
                buildersMap[security] = builder;
            }

            if (!builder.ProcessOrder(order))
            {
                return;
            }

            if (subscribedBooks.Contains(security))
            {
                OnMessageReceived(builder.BuildBook());
                //TODO fire
            }
        }
Exemplo n.º 2
0
        public void SubscribeOrderBook(Instrument instrument)
        {
            var code = connector.ResolveInstrumentAsync(instrument).Result;

            if (code == null)
            {
                return;
            }
            using (allInstrumentLock.WriteLock())
            {
                if (allInstruments.Contains(code))
                {
                    subscribedBooks.Add(code);

                    if (buildersMap.TryGetValue(code, out var builder))
                    {
                        OnMessageReceived(builder.BuildBook());
                    }
                    else
                    {
                        builder           = new OrderBookBuilder(instrument);
                        buildersMap[code] = builder;
                    }
                }
            }
        }