コード例 #1
0
        /// <summary>
        /// The method is called when a new order added.
        /// </summary>
        /// <param name="order">Order.</param>
        protected override void OnOrderAdded(Order order)
        {
            if (order.Type != OrderTypes.Conditional)
            {
                return;
            }

            Type conditionType;

            lock (_conditionTypes.SyncRoot)
            {
                var condition = order.Condition;

                if (condition == null)
                {
                    return;
                }

                conditionType = condition.GetType();

                if (_conditionTypes.Contains(conditionType))
                {
                    return;
                }

                _conditionTypes.Add(conditionType);
            }

            GuiDispatcher.GlobalDispatcher.AddAction(() => AddColumns(conditionType));
        }
コード例 #2
0
        /// <inheritdoc />
        protected override void OnSendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Reset:
                _subscriptions.Clear();
                break;

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

                if (mdMsg.IsSubscribe)
                {
                    _subscriptions.Add(mdMsg.TransactionId);
                }

                break;
            }

            case ExtendedMessageTypes.EmulationState:
                SendOutMessage(message);
                return;
            }

            base.OnSendInMessage(message);
        }
コード例 #3
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);
        }
コード例 #4
0
            public void AddTransactionId(long transactionId)
            {
                if (transactionId == 0)
                {
                    throw new ArgumentNullException(nameof(transactionId));
                }

                this.AddInfoLog("Added trans id {0} mapping.", transactionId);
                _transactionIds.Add(transactionId);
            }
コード例 #5
0
        private void AddElement(IChartElement element, CandleSeries candleSeries)
        {
            if (!_isLoaded || candleSeries == null)
            {
                return;
            }

            _changedElements.Add(element);
            _skipElements.Add(element);
            _drawTimer.Reset();
        }
コード例 #6
0
        private void AddToProcess(IPsiSourceFile sourceFile)
        {
            myShellLocks.Dispatcher.AssertAccess();
            bool isApplicable = myCaches.Any(t => t.IsApplicable(sourceFile));

            if (isApplicable)
            {
                FilesToProcess.Add(sourceFile);
                AfterAddToProcess.Fire(sourceFile);
            }
        }
コード例 #7
0
        /// <inheritdoc />
        protected override void OnSendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Reset:
            {
                _subscriptions.Clear();
                break;
            }

            case MessageTypes.SecurityLookup:
            {
                if (_securityProvider != null)
                {
                    var lookupMsg = (SecurityLookupMessage)message;

                    var securities = lookupMsg.SecurityId == default
                                                        ? _securityProvider.LookupAll()
                                                        : _securityProvider.Lookup(lookupMsg);

                    foreach (var security in securities)
                    {
                        SendOutMessage(security.Board.ToMessage());
                        SendOutMessage(security.ToMessage(originalTransactionId: lookupMsg.TransactionId));
                    }

                    SendOutMessage(new SecurityLookupResultMessage {
                            OriginalTransactionId = lookupMsg.TransactionId
                        });
                    return;
                }

                break;
            }

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

                if (mdMsg.IsSubscribe)
                {
                    _subscriptions.Add(mdMsg.TransactionId);
                }

                break;
            }

            case ExtendedMessageTypes.EmulationState:
                SendOutMessage(message);
                return;
            }

            base.OnSendInMessage(message);
        }
コード例 #8
0
 private void ProcessOrderMessage(string portfolioName, OrderMessage message)
 {
     if (OwnInnerAdapter)
     {
         if (portfolioName == Extensions.SimulatorPortfolioName)
         {
             _emuOrderIds.Add(message.TransactionId);
             SendToEmulator(message);
         }
         else
         {
             base.OnSendInMessage(message);
         }
     }
     else
     {
         _emuOrderIds.Add(message.TransactionId);
         SendToEmulator(message);
     }
 }
コード例 #9
0
        public void Drop(IPsiSourceFile sourceFile)
        {
            DropFromProcess(sourceFile);

            bool isApplicable = myCaches.Any(t => t.IsApplicable(sourceFile));

            if (isApplicable)
            {
                FilesToDrop.Add(sourceFile);
            }
        }
コード例 #10
0
        /// <summary>
        /// To create news.
        /// </summary>
        /// <returns>News.</returns>
        public override News CreateNews()
        {
            lock (_notSavedSecurities.SyncRoot)
            {
                //var news = _entityRegistry.News.ReadById(id);

                //if (news == null)
                //{
                var news = base.CreateNews();
                _notSavedNews.Add(news);
                //}

                return(news);
            }
        }
コード例 #11
0
        private void ProcessOrderMessage(string portfolioName, OrderMessage message)
        {
            if (OwnInnerAdapter)
            {
                if (_isEmulationOnly || portfolioName.CompareIgnoreCase(Extensions.SimulatorPortfolioName))
                {
                    if (!_isEmulationOnly)
                    {
                        _emuOrderIds.Add(message.TransactionId);
                    }

                    SendToEmulator(message);
                }
                else
                {
                    base.OnSendInMessage(message);
                }
            }
            else
            {
                _emuOrderIds.Add(message.TransactionId);
                SendToEmulator(message);
            }
        }
コード例 #12
0
        /// <summary>
        /// To create the portfolio by the account number.
        /// </summary>
        /// <param name="name">Account number.</param>
        /// <returns>Created portfolio.</returns>
        public override Portfolio CreatePortfolio(string name)
        {
            //_parent.AddInfoLog(LocalizedStrings.Str3621Params, name);

            lock (_notSavedPortfolios.SyncRoot)
            {
                var portfolio = _entityRegistry.Portfolios.ReadById(name);

                if (portfolio == null)
                {
                    //_parent.AddInfoLog(LocalizedStrings.Str3622Params, name);

                    portfolio = base.CreatePortfolio(name);
                    _notSavedPortfolios.Add(portfolio);
                }

                return(portfolio);
            }
        }
コード例 #13
0
        /// <summary>
        /// To create the instrument by the identifier.
        /// </summary>
        /// <param name="id">Security ID.</param>
        /// <returns>Created instrument.</returns>
        public override Security CreateSecurity(string id)
        {
            //_parent.AddInfoLog(LocalizedStrings.Str3623Params, id);

            lock (_notSavedSecurities.SyncRoot)
            {
                var security = _entityRegistry.Securities.ReadById(id);

                if (security == null)
                {
                    //_parent.AddInfoLog(LocalizedStrings.Str3624Params, id);

                    security = base.CreateSecurity(id);
                    _notSavedSecurities.Add(security);
                }

                return(security);
            }
        }
コード例 #14
0
        /// <summary>
        /// Process <see cref="MessageAdapterWrapper.InnerAdapter"/> output message.
        /// </summary>
        /// <param name="message">The message.</param>
        protected override void OnInnerAdapterNewOutMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Level1Change:
            {
                var level1Msg = (Level1ChangeMessage)message.Clone();

                if (CanStore(level1Msg.SecurityId, typeof(Level1ChangeMessage), null))
                {
                    _level1Buffer.Add(level1Msg.SecurityId, level1Msg);
                }

                break;
            }

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

                if (CanStore(quotesMsg.SecurityId, typeof(QuoteChangeMessage), null))
                {
                    _orderBooksBuffer.Add(quotesMsg.SecurityId, quotesMsg);
                }

                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 error responses do not contains sec id
                    if (secId.IsDefault())
                    {
                        base.OnInnerAdapterNewOutMessage(message);
                        return;
                    }

                    buffer = _transactionsBuffer;
                    break;

                case ExecutionTypes.OrderLog:
                    buffer = _orderLogBuffer;
                    break;

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

                if (CanStore(secId, typeof(ExecutionMessage), execType))
                {
                    buffer.Add(secId, (ExecutionMessage)message.Clone());
                }

                break;
            }

            case MessageTypes.CandlePnF:
            case MessageTypes.CandleRange:
            case MessageTypes.CandleRenko:
            case MessageTypes.CandleTick:
            case MessageTypes.CandleTimeFrame:
            case MessageTypes.CandleVolume:
            {
                var candleMsg = (CandleMessage)message.Clone();

                if (CanStore(candleMsg.SecurityId, candleMsg.GetType(), candleMsg.Arg))
                {
                    _candleBuffer.Add(Tuple.Create(candleMsg.SecurityId, candleMsg.GetType(), candleMsg.Arg), candleMsg);
                }

                break;
            }

            case MessageTypes.News:
            {
                if (CanStore(default(SecurityId), typeof(NewsMessage), null))
                {
                    _newsBuffer.Add((NewsMessage)message.Clone());
                }

                break;
            }
                //case MessageTypes.Position:
                //	break;
                //case MessageTypes.Portfolio:
                //	break;
                //case MessageTypes.PositionChange:
                //	break;
                //case MessageTypes.PortfolioChange:
                //	break;
            }

            base.OnInnerAdapterNewOutMessage(message);
        }
コード例 #15
0
        /// <summary>
        /// Process <see cref="MessageAdapterWrapper.InnerAdapter"/> output message.
        /// </summary>
        /// <param name="message">The message.</param>
        protected override void OnInnerAdapterNewOutMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Level1Change:
            {
                var level1Msg = (Level1ChangeMessage)message.Clone();
                _level1Buffer.Add(level1Msg.SecurityId, level1Msg);
                break;
            }

            case MessageTypes.QuoteChange:
            {
                var quotesMsg = (QuoteChangeMessage)message.Clone();
                _orderBooksBuffer.Add(quotesMsg.SecurityId, quotesMsg);
                break;
            }

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

                DataBuffer <SecurityId, ExecutionMessage> buffer;

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

                case ExecutionTypes.Transaction:
                    buffer = _transactionsBuffer;
                    break;

                case ExecutionTypes.OrderLog:
                    buffer = _orderLogBuffer;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(LocalizedStrings.Str1695Params.Put(execMsg.ExecutionType));
                }

                buffer.Add(execMsg.SecurityId, execMsg);
                break;
            }

            case MessageTypes.CandlePnF:
            case MessageTypes.CandleRange:
            case MessageTypes.CandleRenko:
            case MessageTypes.CandleTick:
            case MessageTypes.CandleTimeFrame:
            case MessageTypes.CandleVolume:
            {
                var candleMsg = (CandleMessage)message.Clone();
                _candleBuffer.Add(Tuple.Create(candleMsg.SecurityId, candleMsg.GetType(), candleMsg.Arg), candleMsg);
                break;
            }

            case MessageTypes.News:
            {
                _newsBuffer.Add((NewsMessage)message.Clone());
                break;
            }
                //case MessageTypes.Position:
                //	break;
                //case MessageTypes.Portfolio:
                //	break;
                //case MessageTypes.PositionChange:
                //	break;
                //case MessageTypes.PortfolioChange:
                //	break;
            }

            base.OnInnerAdapterNewOutMessage(message);
        }
コード例 #16
0
        /// <inheritdoc />
        protected override bool OnSendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.OrderRegister:
            {
                var regMsg = (OrderRegisterMessage)message;
                ProcessOrderMessage(regMsg.PortfolioName, regMsg);
                return(true);
            }

            case MessageTypes.OrderReplace:
            case MessageTypes.OrderCancel:
            {
                ProcessOrderMessage(((OrderMessage)message).OriginalTransactionId, message);
                return(true);
            }

            case MessageTypes.OrderPairReplace:
            {
                var ordMsg = (OrderPairReplaceMessage)message;
                ProcessOrderMessage(ordMsg.Message1.OriginalTransactionId, message);
                return(true);
            }

            case MessageTypes.OrderGroupCancel:
            {
                SendToEmulator(message);
                return(true);
            }

            case MessageTypes.Reset:
            case MessageTypes.Connect:
            case MessageTypes.Disconnect:
            {
                SendToEmulator(message);

                if (message.Type == MessageTypes.Reset)
                {
                    _subscriptionIds.Clear();
                    _emuOrderIds.Clear();
                }

                if (OwnInnerAdapter)
                {
                    return(base.OnSendInMessage(message));
                }
                else
                {
                    return(true);
                }
            }

            case MessageTypes.PortfolioLookup:
            case MessageTypes.Portfolio:
            case MessageTypes.OrderStatus:
            {
                if (OwnInnerAdapter)
                {
                    base.OnSendInMessage(message);
                }

                SendToEmulator(message);
                return(true);
            }

            case MessageTypes.SecurityLookup:
            case MessageTypes.TimeFrameLookup:
            case MessageTypes.BoardLookup:
            case MessageTypes.MarketData:
            {
                _subscriptionIds.Add(((ISubscriptionMessage)message).TransactionId);

                // sends to emu for init subscription ids
                SendToEmulator(message);

                return(base.OnSendInMessage(message));
            }

            case MessageTypes.Level1Change:
            case ExtendedMessageTypes.CommissionRule:
            {
                SendToEmulator(message);
                return(true);
            }

            default:
            {
                if (OwnInnerAdapter)
                {
                    return(base.OnSendInMessage(message));
                }

                return(true);
            }
            }
        }
コード例 #17
0
 void ICandleSource <Candle> .Start(CandleSeries series, DateTimeOffset?from, DateTimeOffset?to)
 {
     _candleSeries.Add(series);
     _connector.SubscribeCandles(series, from, to);
 }
コード例 #18
0
 private void OnNewsChanged(News news)
 {
     _newsBuffer.Add(news);
 }
コード例 #19
0
        // опциональные колонки, которые записываются напрямую в поля сущностей (например, Security.TheorPrice), а не через ExtensionInfo
        private void TryAddAsExtended(DdeTableColumn column)
        {
            if (column == null)
            {
                throw new ArgumentNullException("column");
            }

            if (column.IsMandatory)
            {
                return;
            }

            var isStandard = false;
            var tableType  = TableType == null ? DdeTableTypes.None : TableType();

            switch (tableType)
            {
            case DdeTableTypes.Security:
                isStandard =
                    column == DdeSecurityColumns.MarginBuy ||
                    column == DdeSecurityColumns.MarginSell ||
                    column == DdeSecurityColumns.MinPrice ||
                    column == DdeSecurityColumns.MaxPrice ||
                    column == DdeSecurityColumns.ExpiryDate ||
                    column == DdeSecurityColumns.SettlementDate ||
                    column == DdeSecurityColumns.LastTradeTime ||
                    column == DdeSecurityColumns.LastChangeTime ||
                    column == DdeSecurityColumns.LastTradePrice ||
                    column == DdeSecurityColumns.LastTradeVolume ||
                    column == DdeSecurityColumns.LastTradeVolume2 ||
                    column == DdeSecurityColumns.StepPrice ||
                    column == DdeSecurityColumns.ShortName ||
                    column == DdeSecurityColumns.BestBidPrice ||
                    column == DdeSecurityColumns.BestBidVolume ||
                    column == DdeSecurityColumns.BestAskPrice ||
                    column == DdeSecurityColumns.BestAskVolume ||
                    column == DdeSecurityColumns.OpenPrice ||
                    column == DdeSecurityColumns.HighPrice ||
                    column == DdeSecurityColumns.LowPrice ||
                    column == DdeSecurityColumns.ClosePrice ||
                    column == DdeSecurityColumns.OpenPositions ||
                    column == DdeSecurityColumns.NominalCurrency ||
                    column == DdeSecurityColumns.BidsCount ||
                    column == DdeSecurityColumns.BidsVolume ||
                    column == DdeSecurityColumns.AsksCount ||
                    column == DdeSecurityColumns.AsksVolume ||
                    column == DdeSecurityColumns.ISIN ||
                    column == DdeSecurityColumns.TheorPrice ||
                    column == DdeSecurityColumns.ImpliedVolatility ||
                    column == DdeSecurityColumns.Strike;
                break;

            case DdeTableTypes.Trade:
                isStandard = column == DdeTradeColumns.TimeMcs;
                break;

            case DdeTableTypes.Order:
                isStandard =
                    column == DdeOrderColumns.TimeMcs ||
                    column == DdeOrderColumns.CancelTimeMcs;
                break;

            case DdeTableTypes.MyTrade:
                isStandard = column == DdeMyTradeColumns.TimeMcs;
                break;
            }

            if (!isStandard)
            {
                _extendedColumns.Add(column);
            }

            _nonMandatoryColumns.Add(column);
        }
コード例 #20
0
		/// <inheritdoc />
		protected override void OnInnerAdapterNewOutMessage(Message message)
		{
			switch (message.Type)
			{
				case MessageTypes.Level1Change:
				{
					var level1Msg = (Level1ChangeMessage)message;

					if (CanStore<Level1ChangeMessage>(level1Msg.SecurityId))
						_level1Buffer.Add(level1Msg.SecurityId, (Level1ChangeMessage)level1Msg.Clone());

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

					if (CanStore<QuoteChangeMessage>(quotesMsg.SecurityId))
						_orderBooksBuffer.Add(quotesMsg.SecurityId, (QuoteChangeMessage)quotesMsg.Clone());

					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))
							{
								base.OnInnerAdapterNewOutMessage(message);
								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 || CanStore<ExecutionMessage>(secId, execType))
						buffer.Add(secId, (ExecutionMessage)message.Clone());

					break;
				}
				case MessageTypes.CandlePnF:
				case MessageTypes.CandleRange:
				case MessageTypes.CandleRenko:
				case MessageTypes.CandleTick:
				case MessageTypes.CandleTimeFrame:
				case MessageTypes.CandleVolume:
				{
					var candleMsg = (CandleMessage)message;

					if (CanStore(candleMsg.SecurityId, candleMsg.GetType(), candleMsg.Arg))
						_candleBuffer.Add(Tuple.Create(candleMsg.SecurityId, candleMsg.GetType(), candleMsg.Arg), (CandleMessage)candleMsg.Clone());

					break;
				}
				case MessageTypes.News:
				{
					if (CanStore<NewsMessage>(default))
						_newsBuffer.Add((NewsMessage)message.Clone());

					break;
				}
コード例 #21
0
ファイル: LayoutManager.cs プロジェクト: cha7ura/StockSharp
 private void OnDockingControlChanged(DockingControl control)
 {
     _changedControls.Add(control);
     Flush();
 }
コード例 #22
0
 private void OnChartPanelSubscribeCandleElement(ChartCandleElement element, CandleSeries candleSeries)
 {
     _elements.Add(element);
     _drawTimer.Reset();
 }
コード例 #23
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;
            }
            }
        }
コード例 #24
0
ファイル: ConcurrentSet.cs プロジェクト: lbmaian/LbmLib
 public bool Add(T item) => set.Add(item);
コード例 #25
0
        public StrategySecuritiesPanel()
        {
            InitializeComponent();

            SecurityPicker.GridChanged += RaiseChangedCommand;
            AlertBtn.SchemaChanged     += RaiseChangedCommand;

            GotFocus += (s, e) => RaiseSelectedCommand();

            _newSecuritiesTooltip = (ToolTip)AddSecurity.ToolTip;
            _defaultStorageBrush  = ((TextBlock)_newSecuritiesTooltip.Content).Foreground;
            _defaultToolTipText   = ((TextBlock)_newSecuritiesTooltip.Content).Text;

            var cmdSvc = ConfigManager.GetService <IStudioCommandService>();

            cmdSvc.Register <ResetedCommand>(this, false, cmd =>
            {
                var selectedSecurities = Securities;

                selectedSecurities.ForEach(RaiseRefuseMarketData);
                selectedSecurities.ForEach(RaiseRequestMarketData);
            });
            cmdSvc.Register <NewSecuritiesCommand>(this, false, cmd =>
            {
                if (_isTooltipVisible)
                {
                    return;
                }

                _isTooltipVisible = true;

                GuiDispatcher.GlobalDispatcher.AddAction(() =>
                {
                    ((TextBlock)_newSecuritiesTooltip.Content).Text       = LocalizedStrings.Str3276;
                    ((TextBlock)_newSecuritiesTooltip.Content).Foreground = Brushes.Red;
                    _newSecuritiesTooltip.Placement       = PlacementMode.Bottom;
                    _newSecuritiesTooltip.PlacementTarget = AddSecurity;
                    _newSecuritiesTooltip.IsOpen          = true;
                });
            });
            cmdSvc.Register <BindStrategyCommand>(this, false, cmd =>
            {
                if (!cmd.CheckControl(this))
                {
                    return;
                }

                if (_securityIds.Count == 0)
                {
                    _securityIds.Add(cmd.Source.Security.Id);

                    AddDefaultSecurities("RI");
                    AddDefaultSecurities("Si");
                    AddDefaultSecurities("GZ");
                }

                var selectedSecurities = Securities;

                SecurityPicker.Securities.AddRange(selectedSecurities);
                selectedSecurities.ForEach(RaiseRequestMarketData);

                GuiDispatcher.GlobalDispatcher.AddAction(() =>
                {
                    SecurityPicker.AddContextMenuItem(new Separator());
                    SecurityPicker.AddContextMenuItem(new MenuItem {
                        Header = LocalizedStrings.Str3277, Command = OpenMarketDepthCommand, CommandTarget = this
                    });
                });
            });

            WhenLoaded(() => new RequestBindSource(this).SyncProcess(this));
        }
コード例 #26
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;
            }
            }
        }
コード例 #27
0
        /// <summary>
        /// Process message.
        /// </summary>
        /// <param name="message">Message.</param>
        public void SendOutMessage(Message message)
        {
            if (message is null)
            {
                throw new ArgumentNullException(nameof(message));
            }

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

            switch (message.Type)
            {
            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;
            }
            }
        }
コード例 #28
0
ファイル: LuaFixServer.cs プロジェクト: Igorvl/StockSharp
 public void AddTransactionId(long transactionId)
 {
     this.AddInfoLog("Added trans id {0} mapping.", transactionId);
     _transactionIds.Add(transactionId);
 }
コード例 #29
0
        /// <inheritdoc />
        public override bool SendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Reset:
            {
                Reset();
                break;
            }

            case MessageTypes.OrderRegister:
            {
                var regMsg = (OrderRegisterMessage)message;
                _secIds.TryAdd(regMsg.TransactionId, regMsg.SecurityId);
                break;
            }

            case MessageTypes.OrderReplace:
            {
                var replaceMsg = (OrderReplaceMessage)message;

                if (_secIds.TryGetValue(replaceMsg.OriginalTransactionId, out var secId))
                {
                    _secIds.TryAdd(replaceMsg.TransactionId, secId);
                }

                break;
            }

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

                if (_secIds.TryGetValue(replaceMsg.Message1.OriginalTransactionId, out var secId))
                {
                    _secIds.TryAdd(replaceMsg.Message1.TransactionId, secId);
                }

                if (_secIds.TryGetValue(replaceMsg.Message2.OriginalTransactionId, out secId))
                {
                    _secIds.TryAdd(replaceMsg.Message2.TransactionId, secId);
                }

                break;
            }

            case MessageTypes.OrderStatus:
            {
                var statusMsg = (OrderStatusMessage)message;

                if (statusMsg.IsSubscribe)
                {
                    if (IsSupportTransactionLog)
                    {
                        _transactionLogSubscriptions.Add(statusMsg.TransactionId, new SubscriptionInfo(statusMsg.TypedClone()));
                    }
                    else
                    {
                        _orderStatusIds.Add(statusMsg.TransactionId);
                    }
                }

                break;
            }
            }

            return(base.SendInMessage(message));
        }
コード例 #30
0
ファイル: LayoutManager.cs プロジェクト: progmax/StockSharp
        //private void OnDockingManagerLayoutChanged(object sender, EventArgs e)
        //{
        //	//if (DockingManager.Layout == null)
        //	//	return;

        //	//DockingManager.Layout.Updated += OnLayoutUpdated;
        //}

        //private void OnLayoutUpdated(object sender, EventArgs e)
        //{
        //	_isLayoutChanged = true;
        //	Flush();
        //}

        //private void OnDockingManagerDocumentClosing(object sender, DocumentClosingEventArgs e)
        //{
        //	var control = e.Document.Content as BaseStudioControl;

        //	if (control == null)
        //		return;

        //	e.Cancel = !control.CanClose();
        //}

        //private void OnDockingManagerDocumentClosed(object sender, DocumentClosedEventArgs e)
        //{
        //	var control = e.Document.Content as BaseStudioControl;

        //	if (control == null)
        //		return;

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

        //	_isLayoutChanged = true;

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

        //	Flush();
        //}

        private void OnBaseStudioControlChanged(BaseStudioControl control)
        {
            _changedControls.Add(control);
            Flush();
        }