Beispiel #1
0
            protected override void OnInnerAdapterNewMessage(IMessageAdapter innerAdapter, Message message)
            {
                switch (message.Type)
                {
                    case MessageTypes.Connect:
                    case MessageTypes.Disconnect:
                        base.OnInnerAdapterNewMessage(innerAdapter, message);
                        break;

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

                        if (execMsg.ExecutionType != ExecutionTypes.Order && execMsg.ExecutionType != ExecutionTypes.Trade)
                        {
                            if (innerAdapter != InnerAdapters.LastOrDefault())
                                return;
                        }

                        base.OnInnerAdapterNewMessage(innerAdapter, message);
                        break;
                    }

                    default:
                    {
                        // на выход данные идут только из одного адаптера
                        if (innerAdapter != InnerAdapters.LastOrDefault())
                            return;

                        base.OnInnerAdapterNewMessage(innerAdapter, message);
                        break;
                    }
                }
            }
Beispiel #2
0
        /// <summary>
        /// Load settings.
        /// </summary>
        /// <param name="storage">Settings storage.</param>
        public override void Load(SettingsStorage storage)
        {
            lock (InnerAdapters.SyncRoot)
            {
                InnerAdapters.Clear();

                foreach (var s in storage.GetValue <IEnumerable <SettingsStorage> >(nameof(InnerAdapters)))
                {
                    var adapter = s.GetValue <Type>("AdapterType").CreateInstance <IMessageAdapter>(TransactionIdGenerator);
                    adapter.Load(s.GetValue <SettingsStorage>("AdapterSettings"));
                    InnerAdapters[adapter] = s.GetValue <int>("Priority");
                }
            }

            base.Load(storage);
        }
Beispiel #3
0
        /// <summary>
        /// Save settings.
        /// </summary>
        /// <param name="storage">Settings storage.</param>
        public override void Save(SettingsStorage storage)
        {
            lock (InnerAdapters.SyncRoot)
            {
                storage.SetValue(nameof(InnerAdapters), InnerAdapters.Select(a =>
                {
                    var s = new SettingsStorage();

                    s.SetValue("AdapterType", a.GetType().GetTypeName(false));
                    s.SetValue("AdapterSettings", a.Save());
                    s.SetValue("Priority", InnerAdapters[a]);

                    return(s);
                }).ToArray());
            }

            base.Save(storage);
        }
Beispiel #4
0
            protected override void OnInnerAdapterNewOutMessage(IMessageAdapter innerAdapter, Message message)
            {
                switch (message.Type)
                {
                case MessageTypes.Connect:
                case MessageTypes.Disconnect:
                    break;

                case MessageTypes.Security:
                case MessageTypes.Board:
                case MessageTypes.Level1Change:
                case MessageTypes.QuoteChange:
                case MessageTypes.Time:
                {
                    if (message.Adapter == _parent.MarketDataAdapter)
                    {
                        SendMessageToEmulationAdapters(message);
                    }

                    break;
                }

                case MessageTypes.Execution:
                {
                    if (message.Adapter != _parent.MarketDataAdapter)
                    {
                        var execMsg = (ExecutionMessage)message;

                        if (execMsg.ExecutionType != ExecutionTypes.Transaction)
                        {
                            if (innerAdapter != InnerAdapters.LastOrDefault())
                            {
                                return;
                            }
                        }
                    }
                    else
                    {
                        SendMessageToEmulationAdapters(message);
                    }

                    break;
                }

                default:
                {
                    if (message is CandleMessage)
                    {
                        if (message.Adapter != _parent.MarketDataAdapter)
                        {
                            break;
                        }

                        SendMessageToEmulationAdapters(message);
                        return;
                    }

                    break;
                }
                }

                base.OnInnerAdapterNewOutMessage(innerAdapter, message);
            }
Beispiel #5
0
 private void SendMessageToEmulationAdapters(Message message)
 {
     InnerAdapters
     .OfType <EmulationMessageAdapter>()
     .ForEach(a => a.SendInMessage(message));
 }