/// <summary> /// Initializes a new instance of the <see cref="SecurityNativeIdMessageAdapter"/>. /// </summary> /// <param name="innerAdapter">The adapter, to which messages will be directed.</param> /// <param name="storage">Security native identifier storage.</param> public SecurityNativeIdMessageAdapter(IMessageAdapter innerAdapter, INativeIdStorage storage) : base(innerAdapter) { if (storage == null) { throw new ArgumentNullException(nameof(storage)); } Storage = storage; }
/// <summary> /// Initializes a new instance of the <see cref="SecurityNativeIdMessageAdapter"/>. /// </summary> /// <param name="innerAdapter">The adapter, to which messages will be directed.</param> /// <param name="storage">Security native identifier storage.</param> public SecurityNativeIdMessageAdapter(IMessageAdapter innerAdapter, INativeIdStorage storage) : base(innerAdapter) { if (storage == null) { throw new ArgumentNullException(nameof(storage)); } Storage = storage; _storageName = innerAdapter.NativeIdStorageName; if (_storageName.IsEmpty()) { throw new ArgumentException(nameof(innerAdapter)); } }
private void InitConnector(IEntityRegistry entityRegistry, SnapshotRegistry snapshotRegistry, INativeIdStorage nativeIdStorage) { // subscribe on connection successfully event Connector.Connected += () => { this.GuiAsync(() => ChangeConnectStatus(true)); if (Connector.Adapter.IsMarketDataTypeSupported(DataType.News) && !Connector.Adapter.IsSecurityNewsOnly) { Connector.SubscribeNews(); } }; // subscribe on connection error event Connector.ConnectionError += error => this.GuiAsync(() => { ChangeConnectStatus(false); MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2959); }); Connector.Disconnected += () => this.GuiAsync(() => ChangeConnectStatus(false)); // subscribe on error event //Connector.Error += error => // this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2955)); // subscribe on error of market data subscription event Connector.MarketDataSubscriptionFailed += (security, msg, error) => this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2956Params.Put(msg.DataType, security))); Connector.NewSecurity += _securitiesWindow.SecurityPicker.Securities.Add; Connector.NewTrade += _tradesWindow.TradeGrid.Trades.Add; Connector.NewOrderLogItem += _orderLogWindow.OrderLogGrid.LogItems.Add; Connector.NewOrder += _ordersWindow.OrderGrid.Orders.Add; Connector.NewMyTrade += _myTradesWindow.TradeGrid.Trades.Add; Connector.NewPortfolio += _portfoliosWindow.PortfolioGrid.Positions.Add; Connector.NewPosition += _portfoliosWindow.PortfolioGrid.Positions.Add; // subscribe on error of order registration event Connector.OrderRegisterFailed += _ordersWindow.OrderGrid.AddRegistrationFail; // subscribe on error of order cancelling event Connector.OrderCancelFailed += OrderFailed; // set market data provider _securitiesWindow.SecurityPicker.MarketDataProvider = Connector; // set news provider _newsWindow.NewsPanel.NewsProvider = Connector; Connector.LookupTimeFramesResult += (message, timeFrames, error) => { if (error == null) { this.GuiAsync(() => _securitiesWindow.UpdateTimeFrames(timeFrames)); } }; Connector.Adapter.NativeIdStorage = nativeIdStorage; try { nativeIdStorage.Init(); } catch (Exception ex) { MessageBox.Show(this, ex.ToString()); } if (Connector.StorageAdapter == null) { return; } try { entityRegistry.Init(); } catch (Exception ex) { MessageBox.Show(this, ex.ToString()); } Connector.Adapter.StorageProcessor.DaysLoad = TimeSpan.FromDays(3); Connector.Adapter.StorageProcessor.Mode = StorageModes.Snapshot; Connector.LookupAll(); snapshotRegistry.Init(); ConfigManager.RegisterService <IExchangeInfoProvider>(new StorageExchangeInfoProvider(entityRegistry)); ConfigManager.RegisterService <IMessageAdapterProvider>(new FullInMemoryMessageAdapterProvider(Connector.Adapter.InnerAdapters)); try { if (File.Exists(_settingsFile)) { var ctx = new ContinueOnExceptionContext(); ctx.Error += ex => ex.LogError(); using (ctx.ToScope()) Connector.Load(new XmlSerializer <SettingsStorage>().Deserialize(_settingsFile)); } } catch { } }
/// <summary> /// Initializes a new instance of the <see cref="SecurityNativeIdMessageAdapter"/>. /// </summary> /// <param name="innerAdapter">The adapter, to which messages will be directed.</param> /// <param name="storage">Security native identifier storage.</param> public SecurityNativeIdMessageAdapter(IMessageAdapter innerAdapter, INativeIdStorage storage) : base(innerAdapter) { Storage = storage ?? throw new ArgumentNullException(nameof(storage)); Storage.Added += OnStorageNewIdentifierAdded; }