Esempio n. 1
0
            private void ProcessSecurityMarketData(Security security, MarketDataTypes dataType, Security subscriber)
            {
                var message = new MarketDataMessage
                {
                    DataType    = dataType,
                    IsSubscribe = true,
                    //SecurityId = _connector.GetSecurityId(subscriber),
                    TransactionId = _connector.TransactionIdGenerator.GetNextId()
                };

                switch (dataType)
                {
                case MarketDataTypes.Trades:
                    message.Arg = ExecutionTypes.Tick;
                    break;

                case MarketDataTypes.OrderLog:
                    message.Arg = ExecutionTypes.OrderLog;
                    break;
                }

                message.FillSecurityInfo(_connector, subscriber);

                if (security == null)
                {
                    message.Error = new ArgumentException(LocalizedStrings.Str692Params.Put(message.SecurityId, _connector.Name));
                    _connector.SendOutMessage(message);
                }
                else
                {
                    _connector.SendInMessage(message);
                }
            }
            public void ProcessRequest(Security security, MarketDataMessage message, bool tryAdd)
            {
                if (security == null)
                {
                    throw new ArgumentNullException(nameof(security));
                }

                if (message == null)
                {
                    throw new ArgumentNullException(nameof(message));
                }

                if (message.TransactionId == 0)
                {
                    message.TransactionId = _connector.TransactionIdGenerator.GetNextId();
                }

                message.FillSecurityInfo(_connector, security);

                var value = Tuple.Create((MarketDataMessage)message.Clone(), security);

                if (tryAdd)
                {
                    // if the message was looped back via IsBack=true
                    _pendingSubscriptions.TryAdd(message.TransactionId, value);
                }
                else
                {
                    _pendingSubscriptions.Add(message.TransactionId, value);
                }

                _connector.SendInMessage(message);
            }
Esempio n. 3
0
            private void SendRequest(ISubscriptionMessage request, Subscription subscription)
            {
                _connector.AddInfoLog(request.IsSubscribe ? LocalizedStrings.SubscriptionSent : LocalizedStrings.UnSubscriptionSent, subscription.Security?.Id, subscription);

                _requests.Add(request.TransactionId, Tuple.Create(request, subscription));
                _connector.SendInMessage((Message)request);
            }
Esempio n. 4
0
            public void SubscribeUnSubscribe(Security security, MarketDataMessage message)
            {
                if (security == null)
                {
                    throw new ArgumentNullException(nameof(security));
                }

                _pendingSubscriptions.Add(message.TransactionId, Tuple.Create((MarketDataMessage)message.Clone(), security));
                _connector.SendInMessage(message);
            }
            public void Subscribe(Security security, MarketDataMessage message)
            {
                if (security == null)
                {
                    throw new ArgumentNullException(nameof(security));
                }

                //var indexSecurity = security as IndexSecurity;

                //if (indexSecurity != null)
                //	indexSecurity.InnerSecurities.ForEach(s => _connector.SubscribeMarketData(s, message));
                //else if (security is ContinuousSecurity)
                //	SubscribeContinuous((ContinuousSecurity)security, message);
                //else
                //{
                //TrySubscribe(security, message);
                _pendingSubscriptions.Add(message.TransactionId, Tuple.Create((MarketDataMessage)message.Clone(), security));
                _connector.SendInMessage(message);
                //}
            }
Esempio n. 6
0
            private void SendRequest(ISubscriptionMessage request, Subscription subscription, bool needLog)
            {
                lock (_syncObject)
                    _requests.Add(request.TransactionId, Tuple.Create(request, subscription));

                if (needLog)
                {
                    _connector.AddInfoLog(request.IsSubscribe ? LocalizedStrings.SubscriptionSent : LocalizedStrings.UnSubscriptionSent, subscription.SecurityId, request);
                }

                _connector.SendInMessage((Message)request);
            }
Esempio n. 7
0
            private void ProcessSecurityMarketData(Security security, MarketDataMessage message /*, Security subscriber*/)
            {
                //var message = new MarketDataMessage
                //{
                //	DataType = dataType,
                //	IsSubscribe = true,
                //	//SecurityId = _connector.GetSecurityId(subscriber),
                //	TransactionId = _connector.TransactionIdGenerator.GetNextId()
                //};

                //switch (dataType)
                //{
                //	case MarketDataTypes.Trades:
                //		message.Arg = ExecutionTypes.Tick;
                //		break;
                //	case MarketDataTypes.OrderLog:
                //		message.Arg = ExecutionTypes.OrderLog;
                //		break;
                //}

                //message.FillSecurityInfo(_connector, subscriber);

                if (security == null)
                {
                    var reply = new MarketDataMessage
                    {
                        OriginalTransactionId = message.TransactionId,
                        Error = new ArgumentException(LocalizedStrings.Str692Params.Put(message.SecurityId, _connector.Name))
                    };
                    _connector.SendOutMessage(reply);
                }
                else
                {
                    _connector.SendInMessage(message);
                }
            }
Esempio n. 8
0
            public void ProcessRequest(Security security, MarketDataMessage message, bool tryAdd)
            {
                if (message == null)
                {
                    throw new ArgumentNullException(nameof(message));
                }

                if (!tryAdd)
                {
                    var msg = (message.IsSubscribe ? LocalizedStrings.SubscriptionSent : LocalizedStrings.UnSubscriptionSent)
                              .Put(security?.Id, message.ToDataTypeString());

                    if (message.From != null && message.To != null)
                    {
                        msg += LocalizedStrings.Str691Params.Put(message.From.Value, message.To.Value);
                    }

                    _connector.AddDebugLog(msg + ".");
                }

                if (security == null)
                {
                    if (!message.IsSubscribe)
                    {
                        if (message.OriginalTransactionId != 0)
                        {
                            security = TryGetSecurity(message.OriginalTransactionId);
                        }
                    }
                }

                if (security == null)
                {
                    if (message.DataType != MarketDataTypes.News)
                    {
                        if (message.SecurityId.IsDefault())
                        {
                            throw new ArgumentNullException(nameof(security));
                        }

                        security = _connector.LookupById(message.SecurityId);

                        if (security == null)
                        {
                            throw new ArgumentException(LocalizedStrings.Str704Params.Put(message.SecurityId));
                        }
                    }
                }

                if (message.TransactionId == 0)
                {
                    message.TransactionId = _connector.TransactionIdGenerator.GetNextId();
                }

                if (security != null)
                {
                    message.FillSecurityInfo(_connector, security);
                }

                var value = Tuple.Create((MarketDataMessage)message.Clone(), security);

                if (tryAdd)
                {
                    // if the message was looped back via IsBack=true
                    _requests.TryAdd(message.TransactionId, value);
                }
                else
                {
                    _requests.Add(message.TransactionId, value);
                }

                _connector.SendInMessage(message);
            }