private void CreateAndStartClient()
 {
     Client = new DataRequestClient.DataRequestClient(
         "SERVERCLIENT",
         "localhost",
         Settings.Default.RealTimeDataServerRequestPort,
         Settings.Default.RealTimeDataServerPublishPort,
         Settings.Default.HistoricalServerPort
         );
     Client.Connect();
     Client.HistoricalDataReceived += Client_HistoricalDataReceived;
 }
        public HistoricalRequestViewModel(Instrument instrument)
        {
            var r = new Random(); //we have to randomize the name of the client, can't reuse the identity

            uiContext = SynchronizationContext.Current;
            string datasourceName = instrument.Datasource.Name;

            //historicalBroker.DataSources.TryGetValue(datasourceName, out  historicalDataSource);

            Title = $"Historical Data Request for {instrument.Symbol} @ {datasourceName}";

            client = new DataRequestClient.DataRequestClient(
                $"DataRequestClient-{r.Next()}",
                "localhost",
                Settings.Default.RealTimeDataServerRequestPort,
                Settings.Default.RealTimeDataServerPublishPort,
                Settings.Default.HistoricalServerPort

                );

            client.HistoricalDataReceived += Client_HistoricalDataReceived;
            client.Error += Client_Error;
            client.Connect();

            Data = new ReactiveList <OHLCBar>();
            RequestDataTooltip = $"Button was disabled because no active connection to {datasourceName} was found.";
            TheInstrument      = instrument;

            new DateTime(DateTime.Now.Year, 1, 1, 0, 0, 0, 0);
            new DateTime(DateTime.Now.AddYears(-5).Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0, 0);
            StartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1, 0, 0, 0, 0);
            EndDate   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0, 0);
            //var isConnectedToDataSource = this.WhenAny(x => x.historicalDataSource.Connected, x => x.Value == true);
            //TODO problem with ThreadAccess on IB when property of connected changed
            //TODO use message pattern from mvvm light
            RequestDataCommand = ReactiveCommand.Create(RequestData);// isConnectedToDataSource);
            ExportCommand      = ReactiveCommand.Create(ExportData);
        }