Exemple #1
0
			void ISecurityStorage.Delete(Security security)
			{
				if (!_securities.Remove(security))
					return;

				Save();
				Removed?.Invoke(new[] { security });
			}
Exemple #2
0
        private bool RemoveOrder(Order o)
        {
            var res = _chartOrders.Remove(o);

            Orders.Remove(o);

            return(res);
        }
        private void ProcessMarketData(MarketDataMessage mdMsg)
        {
            switch (mdMsg.DataType)
            {
            case MarketDataTypes.Level1:
            {
                if (mdMsg.IsSubscribe)
                {
                    _subscribedLevel1.Add(mdMsg.SecurityId);
                }
                else
                {
                    _subscribedLevel1.Remove(mdMsg.SecurityId);
                }

                break;
            }

            case MarketDataTypes.MarketDepth:
            {
                if (mdMsg.IsSubscribe)
                {
                    _subscribedDepths.Add(mdMsg.SecurityId, mdMsg.MaxDepth ?? MarketDataMessage.DefaultMaxDepth);
                }
                else
                {
                    _subscribedDepths.Remove(mdMsg.SecurityId);
                }

                break;
            }

            case MarketDataTypes.Trades:
            {
                if (mdMsg.IsSubscribe)
                {
                    _subscribedTicks.Add(mdMsg.SecurityId);
                }
                else
                {
                    _subscribedTicks.Remove(mdMsg.SecurityId);
                }

                break;
            }

            default:
            {
                SendOutMarketDataNotSupported(mdMsg.TransactionId);
                return;
            }
            }

            var reply = (MarketDataMessage)mdMsg.Clone();

            reply.OriginalTransactionId = mdMsg.OriginalTransactionId;
            SendOutMessage(reply);
        }
Exemple #4
0
        /// <summary>
        /// Остановить подписку получения свечек, ранее созданную через <see cref="SubscribeCandles"/>.
        /// </summary>
        /// <param name="series">Серия свечек.</param>
        public void UnSubscribeCandles(CandleSeries series)
        {
            if (series == null)
            {
                throw new ArgumentNullException(nameof(series));
            }

            _realTimeSeries.Remove(series);
        }
        /// <inheritdoc />
        protected override bool OnSendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.PortfolioLookup:
            {
                var lookupMsg = (PortfolioLookupMessage)message;

                if (lookupMsg.IsSubscribe)
                {
                    if (lookupMsg.To == null)
                    {
                        this.AddDebugLog("Subscription {0} added.", lookupMsg.TransactionId);
                        _subscriptions.Add(lookupMsg.TransactionId);

                        lock (_sync)
                            _positionManager.ProcessMessage(message);
                    }

                    if (IsEmulate)
                    {
                        RaiseNewOutMessage(lookupMsg.CreateResult());
                        return(true);
                    }
                }
                else
                {
                    if (_subscriptions.Remove(lookupMsg.OriginalTransactionId))
                    {
                        this.AddDebugLog("Subscription {0} removed.", lookupMsg.OriginalTransactionId);

                        lock (_sync)
                            _positionManager.ProcessMessage(message);
                    }

                    if (IsEmulate)
                    {
                        //RaiseNewOutMessage(lookupMsg.CreateResponse());
                        return(true);
                    }
                }

                break;
            }

            default:
            {
                lock (_sync)
                    _positionManager.ProcessMessage(message);

                break;
            }
            }

            return(base.OnSendInMessage(message));
        }
        /// <summary>
        /// To delete the active object.
        /// </summary>
        /// <param name="obj">The active object.</param>
        public void Remove(T obj)
        {
            Interlocked.Decrement(ref _objectCount);

            //if (IsTraceObjects)
            //	_parent.AddDebugLog("Удален({1}) {0} типа {2}.", obj, ObjectCount, obj.GetType().Name);

            if (!IsObjectTracking)
            {
                return;
            }

            var found = _objects.Remove(obj);

            if (ThrowOnRemoveDeleted && !found)
            {
                throw new ArgumentException(LocalizedStrings.ObjectWasAlreadyDeleted.Put(obj));
            }
        }
Exemple #7
0
        /// <summary>
        /// Покинуть комнату.
        /// </summary>
        /// <param name="room">Комната.</param>
        public void Leave(ChatRoom room)
        {
            if (room == null)
            {
                throw new ArgumentNullException("room");
            }

            Invoke(f => f.Leave(SessionId, room.Id));
            _accessedRooms.Remove(room.Id);
        }
        private void ProcessMarketData(MarketDataMessage mdMsg)
        {
            switch (mdMsg.DataType)
            {
            case MarketDataTypes.Level1:
            {
                if (mdMsg.IsSubscribe)
                {
                    _subscribedLevel1.Add(mdMsg.SecurityId);
                }
                else
                {
                    _subscribedLevel1.Remove(mdMsg.SecurityId);
                }

                break;
            }

            case MarketDataTypes.MarketDepth:
            {
                if (mdMsg.IsSubscribe)
                {
                    _subscribedDepths.Add(mdMsg.SecurityId, mdMsg.MaxDepth);
                }
                else
                {
                    _subscribedDepths.Remove(mdMsg.SecurityId);
                }

                break;
            }

            case MarketDataTypes.Trades:
            {
                if (mdMsg.IsSubscribe)
                {
                    _subscribedTicks.Add(mdMsg.SecurityId);
                }
                else
                {
                    _subscribedTicks.Remove(mdMsg.SecurityId);
                }

                break;
            }

            default:
                throw new ArgumentOutOfRangeException("mdMsg", mdMsg.DataType, LocalizedStrings.Str1618);
            }

            var reply = (MarketDataMessage)mdMsg.Clone();

            reply.OriginalTransactionId = mdMsg.OriginalTransactionId;
            SendOutMessage(reply);
        }
            public void UnRegisterPortfolio(Portfolio portfolio)
            {
                if (portfolio == null)
                {
                    throw new ArgumentNullException(nameof(portfolio));
                }

                if (portfolio is BasketPortfolio basketPortfolio)
                {
                    basketPortfolio.InnerPortfolios.ForEach(_connector.UnRegisterPortfolio);
                }
                else
                {
                    _registeredPortfolios.Remove(portfolio);
                    _connector.OnUnRegisterPortfolio(portfolio);
                }
            }
            public void Remove(TData data)
            {
                lock (_data.SyncRoot)
                {
                    if (!_data.Remove(data))
                    {
                        return;
                    }

                    _dataVersion++;

                    switch (_currState)
                    {
                    case States.Starting:
                        if (_data.Count == 0)
                        {
                            _currState = States.Stopping;
                        }

                        break;

                    case States.Started:
                        //if (_data.Count == 0)
                        //	_currState = States.Stopping;

                        _response.Close();
                        break;

                    case States.Stopping:
                        return;

                    case States.Stopped:
                        throw new InvalidOperationException();

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }
Exemple #11
0
        private void ProcessMarketData(MarketDataMessage mdMsg)
        {
            var secCode   = mdMsg.SecurityId.SecurityCode;
            var boardCode = mdMsg.SecurityId.BoardCode;

            switch (mdMsg.DataType)
            {
            case MarketDataTypes.Level1:
            {
                if (mdMsg.IsSubscribe)
                {
                    _client.SubscribeQuote(secCode, boardCode);
                }
                else
                {
                    _client.UnsubsribeQuote(secCode, boardCode);
                }

                break;
            }

            case MarketDataTypes.MarketDepth:
            {
                if (mdMsg.IsSubscribe)
                {
                    _client.SubscribeLevel2(secCode, boardCode);
                }
                else
                {
                    _client.UnsubsribeLevel2(secCode, boardCode);
                }

                break;
            }

            case MarketDataTypes.Trades:
            {
                if (mdMsg.IsSubscribe)
                {
                    _subscribedSecuritiesToTrade.Add(secCode);
                    _client.SubscribeQuote(secCode, boardCode);
                }
                else
                {
                    _subscribedSecuritiesToTrade.Remove(secCode);
                    _client.UnsubsribeQuote(secCode, boardCode);
                }

                break;
            }

            case MarketDataTypes.News:
            {
                if (mdMsg.IsSubscribe)
                {
                    _client.SubscribeNews();
                }
                else
                {
                    _client.UnsubscribeNews();
                }

                break;
            }

            default:
            {
                SendOutMarketDataNotSupported(mdMsg.TransactionId);
                return;
            }
            }

            var reply = (MarketDataMessage)mdMsg.Clone();

            reply.OriginalTransactionId = mdMsg.TransactionId;
            SendOutMessage(reply);
        }
Exemple #12
0
        private void ProcessMarketData(MarketDataMessage mdMsg)
        {
            switch (mdMsg.DataType)
            {
            case MarketDataTypes.Level1:
            {
                //if (mdMsg.IsSubscribe)
                //	_subscribedLevel1.Add(secCode);
                //else
                //	_subscribedLevel1.Remove(secCode);

                break;
            }

            case MarketDataTypes.MarketDepth:
            {
                if (mdMsg.IsSubscribe)
                {
                    _subscribedDepths.Add(mdMsg.SecurityId);

                    if (_subscribedDepths.Count == 1)
                    {
                        _pusherClient.SubscribeDepths();
                    }
                }
                else
                {
                    _subscribedDepths.Remove(mdMsg.SecurityId);

                    if (_subscribedDepths.Count == 0)
                    {
                        _pusherClient.UnSubscribeDepths();
                    }
                }

                break;
            }

            case MarketDataTypes.Trades:
            {
                if (mdMsg.IsSubscribe)
                {
                    if (mdMsg.From != null && mdMsg.From.Value.DateTime == DateTime.Today)
                    {
                        _httpClient.RequestTransactions().Select(t => new ExecutionMessage
                            {
                                ExecutionType = ExecutionTypes.Tick,
                                SecurityId    = _btcUsd,
                                TradeId       = t.Id,
                                TradePrice    = (decimal)t.Price,
                                TradeVolume   = (decimal)t.Amount,
                                ServerTime    = t.Time.ApplyTimeZone(TimeZoneInfo.Utc)
                            }).ForEach(SendOutMessage);
                    }

                    _subscribedTicks.Add(mdMsg.SecurityId);

                    if (_subscribedTicks.Count == 1)
                    {
                        _pusherClient.SubscribeTrades();
                    }
                }
                else
                {
                    _subscribedTicks.Remove(mdMsg.SecurityId);

                    if (_subscribedTicks.Count == 0)
                    {
                        _pusherClient.UnSubscribeTrades();
                    }
                }

                break;
            }

            default:
            {
                SendOutMarketDataNotSupported(mdMsg.TransactionId);
                return;
            }
            }

            var reply = (MarketDataMessage)mdMsg.Clone();

            reply.OriginalTransactionId = mdMsg.OriginalTransactionId;
            SendOutMessage(reply);
        }
Exemple #13
0
 /// <summary>
 /// Остановить подписку получения свечек, ранее созданную через <see cref="SubscribeCandles"/>.
 /// </summary>
 /// <param name="series">Серия свечек.</param>
 public void UnSubscribeCandles(CandleSeries series)
 {
     _series.RemoveByValue(series);
     _realTimeSeries.Remove(series);
 }
        /// <inheritdoc />
        protected override bool OnSendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Reset:
            {
                _subscriptions.Clear();
                _strategyIdMap.Clear();
                _strategySubscriptions.Clear();

                lock (_sync)
                    _positionManager.ProcessMessage(message);

                break;
            }

            case MessageTypes.PortfolioLookup:
            {
                var lookupMsg = (PortfolioLookupMessage)message;

                if (lookupMsg.IsSubscribe)
                {
                    if (!lookupMsg.StrategyId.IsEmpty())
                    {
                        this.AddDebugLog("Subscription (strategy='{1}') {0} added.", lookupMsg.TransactionId, lookupMsg.StrategyId);
                        _strategyIdMap.Add(lookupMsg.TransactionId, lookupMsg.StrategyId);
                        _strategySubscriptions.SafeAdd(lookupMsg.StrategyId).Add(lookupMsg.TransactionId);
                        RaiseNewOutMessage(lookupMsg.CreateResult());
                        return(true);
                    }

                    if (lookupMsg.To == null)
                    {
                        this.AddDebugLog("Subscription {0} added.", lookupMsg.TransactionId);
                        _subscriptions.Add(lookupMsg.TransactionId);

                        lock (_sync)
                            _positionManager.ProcessMessage(message);
                    }

                    if (IsEmulate)
                    {
                        RaiseNewOutMessage(lookupMsg.CreateResult());
                        return(true);
                    }
                }
                else
                {
                    if (_subscriptions.Remove(lookupMsg.OriginalTransactionId))
                    {
                        this.AddDebugLog("Subscription {0} removed.", lookupMsg.OriginalTransactionId);

                        lock (_sync)
                            _positionManager.ProcessMessage(message);
                    }
                    else if (_strategyIdMap.TryGetAndRemove(lookupMsg.OriginalTransactionId, out var strategyId))
                    {
                        _strategySubscriptions.TryGetValue(strategyId)?.Remove(lookupMsg.OriginalTransactionId);
                        this.AddDebugLog("Subscription (strategy='{1}') {0} removed.", lookupMsg.OriginalTransactionId, strategyId);
                        return(true);
                    }

                    if (IsEmulate)
                    {
                        //RaiseNewOutMessage(lookupMsg.CreateResponse());
                        return(true);
                    }
                }

                break;
            }

            default:
            {
                lock (_sync)
                    _positionManager.ProcessMessage(message);

                break;
            }
            }

            return(base.OnSendInMessage(message));
        }
        private void ProcessMarketData(MarketDataMessage mdMsg)
        {
            var secCode   = mdMsg.SecurityId.SecurityCode;
            var boardCode = mdMsg.SecurityId.BoardCode;

            switch (mdMsg.DataType)
            {
            case MarketDataTypes.Level1:
            {
                if (mdMsg.IsSubscribe)
                {
                    SessionHolder.Session.SubscribeQuote(secCode, boardCode);
                }
                else
                {
                    SessionHolder.Session.UnsubsribeQuote(secCode, boardCode);
                }

                break;
            }

            case MarketDataTypes.MarketDepth:
            {
                if (mdMsg.IsSubscribe)
                {
                    SessionHolder.Session.SubscribeLevel2(secCode, boardCode);
                }
                else
                {
                    SessionHolder.Session.UnsubsribeLevel2(secCode, boardCode);
                }
                break;
            }

            case MarketDataTypes.Trades:
            {
                if (mdMsg.IsSubscribe)
                {
                    _subscribedSecuritiesToTrade.Add(secCode);
                    SessionHolder.Session.SubscribeQuote(secCode, boardCode);
                }
                else
                {
                    _subscribedSecuritiesToTrade.Remove(secCode);
                    SessionHolder.Session.UnsubsribeQuote(secCode, boardCode);
                }
                break;
            }

            case MarketDataTypes.News:
            {
                if (mdMsg.IsSubscribe)
                {
                    SessionHolder.Session.SubscribeNews();
                }
                else
                {
                    SessionHolder.Session.UnsubscribeNews();
                }
                break;
            }

            default:
                throw new ArgumentOutOfRangeException("message", mdMsg.DataType, LocalizedStrings.Str1618);
            }

            var reply = (MarketDataMessage)mdMsg.Clone();

            reply.OriginalTransactionId = mdMsg.TransactionId;
            SendOutMessage(reply);
        }