private void ProcessRemoveSecurity(Security security)
        {
            _securityIds.Remove(security.Id);

            SecurityPicker.Securities.Remove(security);
            RaiseRefuseMarketData(security);
        }
Пример #2
0
        private void AddIndicator(ChartIndicatorElement element)
        {
            var series = (CandleSeries)_bufferedChart.GetSource(element);

            if (series == null)
            {
                return;
            }

            if (_sourceElements.ContainsKey(series.Security))
            {
                return;
            }

            List <RefPair <DateTimeOffset, IDictionary <IChartElement, object> > > allValues;

            lock (_syncRoot)
            {
                allValues = series
                            .GetCandles <TimeFrameCandle>()
                            .Take(_candlesCount)
                            .Select(candle => new RefPair <DateTimeOffset, IDictionary <IChartElement, object> >(candle.OpenTime, new Dictionary <IChartElement, object>
                {
                    { element, CreateIndicatorValue(element, candle) }
                }))
                            .ToList();

                _skipElements.Remove(element);
            }

            _bufferedChart.Reset(new[] { element });
            _bufferedChart.Draw(allValues);
        }
Пример #3
0
        public void DropFromProcess(IPsiSourceFile sourceFile)
        {
            myShellLocks.Dispatcher.AssertAccess();
            bool isApplicable = myCaches.Any(t => t.IsApplicable(sourceFile));

            if (isApplicable)
            {
                FilesToProcess.Remove(sourceFile);
                AfterRemoveFromProcess.Fire(sourceFile);
            }
        }
        private void AddToProcess(IPsiSourceFile sourceFile)
        {
            myShellLocks.Dispatcher.AssertAccess();
            bool isApplicable = myCaches.Any(t => t.IsApplicable(sourceFile));

            if (isApplicable)
            {
                FilesToDrop.Remove(sourceFile);
                FilesToProcess.Add(sourceFile);
                AfterAddToProcess.Fire(sourceFile);
            }
        }
Пример #5
0
        /// <inheritdoc />
        public void SendOutMessage(Message message)
        {
            LastMessage lastMsg = null;

            void TryRemoveSubscription(long id, bool isError)
            {
                lock (_subscriptions.SyncRoot)
                {
                    if (_subscriptions.Remove(id) && _subscriptions.Count == 0)
                    {
                        lastMsg = new LastMessage
                        {
                            LocalTime = StopDate,
                            IsError   = isError,
                            Adapter   = this,
                        };
                    }
                }
            }

            switch (message.Type)
            {
            case MessageTypes.MarketData:
            {
                var response = (MarketDataMessage)message;

                if (!response.IsOk())
                {
                    TryRemoveSubscription(response.OriginalTransactionId, true);
                }

                break;
            }

            case MessageTypes.MarketDataFinished:
            {
                TryRemoveSubscription(((MarketDataFinishedMessage)message).OriginalTransactionId, false);
                break;
            }
            }

            message.Adapter = this;

            RaiseNewOutMessage(message);

            if (lastMsg != null)
            {
                RaiseNewOutMessage(lastMsg);
            }
        }
Пример #6
0
        private void ReportsClick(object sender, RoutedEventArgs e)
        {
            var security = SelectedSecurity;

            var isSubscribe = _reportSecurities.TryAdd(security);

            if (!isSubscribe)
            {
                _reportSecurities.Remove(security);
            }

            foreach (var report in Enumerator.GetValues <FundamentalReports>())
            {
                Trader.SubscribeFundamentalReport(security, report, isSubscribe);
            }
        }
Пример #7
0
        private void OnDockingManagerDocumentClosed(object sender, DocumentClosedEventArgs e)
        {
            var control = e.Document.Content as DockingControl;

            if (control == null)
            {
                return;
            }

            _documents.RemoveWhere(p => Equals(p.Value, e.Document));

            _isLayoutChanged = true;

            _changedControls.Remove(control);
            _dockingControlSettings.Remove(control);

            Flush();
        }
Пример #8
0
            private void OnPortfolios(IEnumerable <Portfolio> portfolios)
            {
                //foreach (var portfolio in portfolios)
                //{
                //	_parent.AddInfoLog("Изменение портфеля {0}.", portfolio.Name);
                //}

                lock (_notSavedPortfolios.SyncRoot)
                {
                    if (_notSavedPortfolios.Count == 0)
                    {
                        return;
                    }

                    foreach (var p in portfolios)
                    {
                        var portfolio = p;

                        if (!_notSavedPortfolios.Contains(portfolio))
                        {
                            continue;
                        }

                        //если площадка у портфеля пустая, то необходимо дождаться ее заполнения
                        //пустой площадка может быть когда в начале придет информация о заявке
                        //с портфелем или о позиции, и только потом придет сам портфель

                        // mika: портфели могут быть универсальными и не принадлежать площадке

                        //var board = portfolio.Board;
                        //if (board == null)
                        //	continue;

                        _parent.AddInfoLog(LocalizedStrings.Str3619Params, portfolio.Name);

                        //if (board != null)
                        //	_entityRegistry.SaveExchangeBoard(board);

                        _entityRegistry.Portfolios.Save(portfolio);

                        _notSavedPortfolios.Remove(portfolio);
                    }
                }
            }
Пример #9
0
            private void OnNews(News news)
            {
                lock (_notSavedNews.SyncRoot)
                {
                    if (_notSavedNews.Count == 0)
                    {
                        return;
                    }

                    if (!_notSavedNews.Contains(news))
                    {
                        return;
                    }

                    _parent.AddInfoLog(LocalizedStrings.Str3620Params, news.Headline);

                    _entityRegistry.News.Add(news);
                    _notSavedNews.Remove(news);
                }
            }
Пример #10
0
            private void OnSecurities(IEnumerable <Security> securities)
            {
                lock (_notSavedSecurities.SyncRoot)
                {
                    if (_notSavedSecurities.Count == 0)
                    {
                        return;
                    }

                    foreach (var s in securities)
                    {
                        var security = s;

                        if (!_notSavedSecurities.Contains(security))
                        {
                            continue;
                        }

                        // NOTE Когда из Квика пришел инструмент, созданный по сделке
                        if (security.Code.IsEmpty())
                        {
                            continue;
                        }

                        _parent.AddInfoLog(LocalizedStrings.Str3618Params, security.Id);

                        var securityToSave = security.Clone();
                        securityToSave.ExtensionInfo = new Dictionary <object, object>();
                        _entityRegistry.Securities.Save(securityToSave);

                        _notSavedSecurities.Remove(security);
                    }
                }

                new NewSecuritiesCommand().Process(this);
            }
Пример #11
0
        /// <summary>
        /// Process <see cref="MarketDataMessage"/>.
        /// </summary>
        /// <param name="message">Market-data message (uses as a subscribe/unsubscribe in outgoing case, confirmation event in incoming case).</param>
        /// <param name="newOutMessage">New message event.</param>
        /// <returns>Market-data message (uses as a subscribe/unsubscribe in outgoing case, confirmation event in incoming case).</returns>
        public MarketDataMessage ProcessMarketData(MarketDataMessage message, Action <Message> newOutMessage)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (newOutMessage is null)
            {
                throw new ArgumentNullException(nameof(newOutMessage));
            }

            if (message.From == null && Settings.DaysLoad == TimeSpan.Zero)
            {
                return(message);
            }

            if (message.IsSubscribe)
            {
                if (message.SecurityId.IsAllSecurity())
                {
                    return(message);
                }

                var transactionId = message.TransactionId;

                var lastTime = LoadMessages(message, message.From, message.To, transactionId, newOutMessage);

                if (message.To != null && lastTime != null && message.To <= lastTime)
                {
                    _fullyProcessedSubscriptions.Add(transactionId);
                    newOutMessage(new SubscriptionFinishedMessage {
                        OriginalTransactionId = transactionId
                    });

                    return(null);
                }

                if (lastTime != null)
                {
                    if (!(message.DataType == MarketDataTypes.MarketDepth && message.From == null && message.To == null))
                    {
                        var clone = message.TypedClone();
                        clone.From = lastTime;
                        message    = clone;
                        message.ValidateBounds();
                    }
                }
            }
            else
            {
                if (_fullyProcessedSubscriptions.Remove(message.OriginalTransactionId))
                {
                    newOutMessage(new SubscriptionResponseMessage
                    {
                        OriginalTransactionId = message.TransactionId,
                    });

                    return(null);
                }
            }

            return(message);
        }
Пример #12
0
 private void OnConnectorCandleSeriesStopped(CandleSeries series)
 {
     _candleSeries.Remove(series);
     Stopped?.Invoke(series);
 }
Пример #13
0
        /// <summary>
        /// Process message.
        /// </summary>
        /// <param name="message">Message.</param>
        public void SendInMessage(Message message)
        {
            if (message is null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (message.OfflineMode != MessageOfflineModes.None)
            {
                return;
            }

            switch (message.Type)
            {
            case MessageTypes.Reset:
            {
                _subscriptionsById.Clear();

                _ticksBuffer.Clear();
                _level1Buffer.Clear();
                _candleBuffer.Clear();
                _orderLogBuffer.Clear();
                _orderBooksBuffer.Clear();
                _transactionsBuffer.Clear();
                _newsBuffer.Clear();
                _positionChangesBuffer.Clear();

                //SendOutMessage(new ResetMessage());
                break;
            }

            case MessageTypes.OrderRegister:
            {
                var regMsg = (OrderRegisterMessage)message;

                //if (!CanStore<ExecutionMessage>(regMsg.SecurityId, ExecutionTypes.Transaction))
                //	break;

                // try - cause looped back messages from offline adapter
                _securityIds.TryAdd(regMsg.TransactionId, regMsg.SecurityId);

                _transactionsBuffer.Add(regMsg.SecurityId, new ExecutionMessage
                    {
                        ServerTime     = DateTimeOffset.Now,
                        ExecutionType  = ExecutionTypes.Transaction,
                        SecurityId     = regMsg.SecurityId,
                        TransactionId  = regMsg.TransactionId,
                        HasOrderInfo   = true,
                        OrderPrice     = regMsg.Price,
                        OrderVolume    = regMsg.Volume,
                        Currency       = regMsg.Currency,
                        PortfolioName  = regMsg.PortfolioName,
                        ClientCode     = regMsg.ClientCode,
                        BrokerCode     = regMsg.BrokerCode,
                        Comment        = regMsg.Comment,
                        Side           = regMsg.Side,
                        TimeInForce    = regMsg.TimeInForce,
                        ExpiryDate     = regMsg.TillDate,
                        Balance        = regMsg.Volume,
                        VisibleVolume  = regMsg.VisibleVolume,
                        LocalTime      = regMsg.LocalTime,
                        IsMarketMaker  = regMsg.IsMarketMaker,
                        IsMargin       = regMsg.IsMargin,
                        Slippage       = regMsg.Slippage,
                        IsManual       = regMsg.IsManual,
                        OrderType      = regMsg.OrderType,
                        UserOrderId    = regMsg.UserOrderId,
                        OrderState     = OrderStates.Pending,
                        Condition      = regMsg.Condition?.Clone(),
                        MinVolume      = regMsg.MinOrderVolume,
                        PositionEffect = regMsg.PositionEffect,
                        PostOnly       = regMsg.PostOnly,
                    });

                break;
            }

            case MessageTypes.OrderCancel:
            {
                var cancelMsg = (OrderCancelMessage)message;

                //if (!CanStore<ExecutionMessage>(cancelMsg.SecurityId, ExecutionTypes.Transaction))
                //	break;

                // try - cause looped back messages from offline adapter
                _securityIds.TryAdd(cancelMsg.TransactionId, cancelMsg.SecurityId);

                _transactionsBuffer.Add(cancelMsg.SecurityId, new ExecutionMessage
                    {
                        ServerTime            = DateTimeOffset.Now,
                        ExecutionType         = ExecutionTypes.Transaction,
                        SecurityId            = cancelMsg.SecurityId,
                        HasOrderInfo          = true,
                        TransactionId         = cancelMsg.TransactionId,
                        IsCancellation        = true,
                        OrderId               = cancelMsg.OrderId,
                        OrderStringId         = cancelMsg.OrderStringId,
                        OriginalTransactionId = cancelMsg.OriginalTransactionId,
                        OrderVolume           = cancelMsg.Volume,
                        //Side = cancelMsg.Side,
                    });

                break;
            }

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

                if (Enabled)
                {
                    if (mdMsg.IsSubscribe)
                    {
                        _subscriptionsById.Add(mdMsg.TransactionId);
                    }
                    else
                    {
                        _subscriptionsById.Remove(mdMsg.OriginalTransactionId);
                    }
                }

                break;
            }
            }
        }
Пример #14
0
        /// <summary>
        /// Process message.
        /// </summary>
        /// <param name="message">Message.</param>
        public void ProcessMessage(Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (message.OfflineMode != MessageOfflineModes.None)
            {
                return;
            }

            switch (message.Type)
            {
            // in message
            case MessageTypes.Reset:
            {
                _subscriptionsById.Clear();

                _ticksBuffer.Clear();
                _level1Buffer.Clear();
                _candleBuffer.Clear();
                _orderLogBuffer.Clear();
                _orderBooksBuffer.Clear();
                _transactionsBuffer.Clear();
                _newsBuffer.Clear();
                _positionChangesBuffer.Clear();

                //SendOutMessage(new ResetMessage());
                break;
            }

            case MessageTypes.OrderRegister:
            {
                var regMsg = (OrderRegisterMessage)message;

                //if (!CanStore<ExecutionMessage>(regMsg.SecurityId, ExecutionTypes.Transaction))
                //	break;

                // try - cause looped back messages from offline adapter
                _securityIds.TryAdd(regMsg.TransactionId, regMsg.SecurityId);

                _transactionsBuffer.Add(regMsg.SecurityId, new ExecutionMessage
                    {
                        ServerTime    = DateTimeOffset.Now,
                        ExecutionType = ExecutionTypes.Transaction,
                        SecurityId    = regMsg.SecurityId,
                        TransactionId = regMsg.TransactionId,
                        HasOrderInfo  = true,
                        OrderPrice    = regMsg.Price,
                        OrderVolume   = regMsg.Volume,
                        Currency      = regMsg.Currency,
                        PortfolioName = regMsg.PortfolioName,
                        ClientCode    = regMsg.ClientCode,
                        BrokerCode    = regMsg.BrokerCode,
                        Comment       = regMsg.Comment,
                        Side          = regMsg.Side,
                        TimeInForce   = regMsg.TimeInForce,
                        ExpiryDate    = regMsg.TillDate,
                        Balance       = regMsg.Volume,
                        VisibleVolume = regMsg.VisibleVolume,
                        LocalTime     = regMsg.LocalTime,
                        IsMarketMaker = regMsg.IsMarketMaker,
                        IsMargin      = regMsg.IsMargin,
                        Slippage      = regMsg.Slippage,
                        IsManual      = regMsg.IsManual,
                        OrderType     = regMsg.OrderType,
                        UserOrderId   = regMsg.UserOrderId,
                        OrderState    = OrderStates.Pending,
                        Condition     = regMsg.Condition?.Clone(),
                    });

                break;
            }

            case MessageTypes.OrderCancel:
            {
                var cancelMsg = (OrderCancelMessage)message;

                //if (!CanStore<ExecutionMessage>(cancelMsg.SecurityId, ExecutionTypes.Transaction))
                //	break;

                // try - cause looped back messages from offline adapter
                _securityIds.TryAdd(cancelMsg.TransactionId, cancelMsg.SecurityId);

                _transactionsBuffer.Add(cancelMsg.SecurityId, new ExecutionMessage
                    {
                        ServerTime            = DateTimeOffset.Now,
                        ExecutionType         = ExecutionTypes.Transaction,
                        SecurityId            = cancelMsg.SecurityId,
                        HasOrderInfo          = true,
                        TransactionId         = cancelMsg.TransactionId,
                        IsCancellation        = true,
                        OrderId               = cancelMsg.OrderId,
                        OrderStringId         = cancelMsg.OrderStringId,
                        OriginalTransactionId = cancelMsg.OriginalTransactionId,
                        OrderVolume           = cancelMsg.Volume,
                        //Side = cancelMsg.Side,
                    });

                break;
            }

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

                if (Enabled)
                {
                    if (mdMsg.IsSubscribe)
                    {
                        _subscriptionsById.Add(mdMsg.TransactionId);
                    }
                    else
                    {
                        _subscriptionsById.Remove(mdMsg.OriginalTransactionId);
                    }
                }

                break;
            }

            // out messages
            case MessageTypes.Level1Change:
            {
                var level1Msg = (Level1ChangeMessage)message;

                if (CanStore(level1Msg))
                {
                    _level1Buffer.Add(level1Msg.SecurityId, level1Msg.TypedClone());
                }

                break;
            }

            case MessageTypes.QuoteChange:
            {
                var quotesMsg = (QuoteChangeMessage)message;

                if (CanStore(quotesMsg))
                {
                    _orderBooksBuffer.Add(quotesMsg.SecurityId, quotesMsg.TypedClone());
                }

                break;
            }

            case MessageTypes.Execution:
            {
                var execMsg = (ExecutionMessage)message;

                DataBuffer <SecurityId, ExecutionMessage> buffer;

                var secId    = execMsg.SecurityId;
                var execType = execMsg.ExecutionType;

                switch (execType)
                {
                case ExecutionTypes.Tick:
                    buffer = _ticksBuffer;
                    break;

                case ExecutionTypes.Transaction:
                {
                    // some responses do not contains sec id
                    if (secId.IsDefault() && !_securityIds.TryGetValue(execMsg.OriginalTransactionId, out secId))
                    {
                        return;
                    }

                    buffer = _transactionsBuffer;
                    break;
                }

                case ExecutionTypes.OrderLog:
                    buffer = _orderLogBuffer;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(message), execType, LocalizedStrings.Str1695Params.Put(message));
                }

                //if (execType == ExecutionTypes.Transaction && execMsg.TransactionId == 0)
                //	break;

                if (execType == ExecutionTypes.Transaction || CanStore(execMsg))
                {
                    buffer.Add(secId, execMsg.TypedClone());
                }

                break;
            }

            case MessageTypes.News:
            {
                var newsMsg = (NewsMessage)message;

                if (CanStore(newsMsg))
                {
                    _newsBuffer.Add(newsMsg.TypedClone());
                }

                break;
            }

            case MessageTypes.PositionChange:
            {
                var posMsg = (PositionChangeMessage)message;
                var secId  = posMsg.SecurityId;

                //if (CanStore<PositionChangeMessage>(secId))
                _positionChangesBuffer.Add(secId, posMsg.TypedClone());

                break;
            }

            default:
            {
                if (message is CandleMessage candleMsg && candleMsg.State == CandleStates.Finished)
                {
                    if (CanStore(candleMsg))
                    {
                        _candleBuffer.Add(Tuple.Create(candleMsg.SecurityId, candleMsg.GetType(), candleMsg.Arg), candleMsg.TypedClone());
                    }
                }

                break;
            }
            }
        }
Пример #15
0
 public bool Remove(T item) => set.Remove(item);
Пример #16
0
        /// <summary>
        /// Удаление колонки.
        /// </summary>
        /// <param name="item">Колонка.</param>
        protected override void OnRemoved(DdeTableColumn item)
        {
            _extendedColumns.Remove(item);

            base.OnRemoved(item);
        }
Пример #17
0
 /// <summary>
 /// Update filter with remove a subscription.
 /// </summary>
 /// <param name="securityId">Security ID.</param>
 /// <param name="dataType">Data type info.</param>
 /// <returns>If subscription was just removed, return <see langword="true" />, otherwise <see langword="false" />.</returns>
 public bool UnSubscribe(SecurityId securityId, DataType dataType)
 {
     return(_subscriptions.Remove(Tuple.Create(securityId, dataType)));
 }