public Service(Oanda.RestClient restClient, string[] instruments) { this.restClient = restClient; this.mt4Commands = new Subject <MT4.Command>(); var prices = this.restClient.GetPriceStream(instruments); this.Instruments = new ReadOnlyDictionary <string, Instrument>( instruments .Select(name => { var ps = prices.Where(p => p.InstrumentName == name); var cs = this.mt4Commands.Where(c => c.Instrument == name); return(new Instrument(name, ps, cs)); }) .ToDictionary(instrument => instrument.Name) ); var events = this.restClient.GetEventStream().Merge(Observable.Return <object>(null)); this.Account = events .SelectMany(_ => this.restClient.GetAccount()) .ToReadOnlyReactiveProperty() ; this.Positions = events .SelectMany(_ => this.restClient.GetPositions()) .ToReadOnlyReactiveProperty() ; }
private void Application_Startup(object sender, StartupEventArgs e) { logger.Debug("start app"); var settings = LineTrader.Properties.Settings.Default; if (settings.AccountToken == "" || settings.AccountId == 0) { logger.Debug("no setting"); ShowAccountSetting(settings); return; } var restClient = new Model.Oanda.RestClient(settings.Practice, settings.AccountToken, settings.AccountId); logger.Debug("getting account"); restClient.GetAccount().ContinueWith(s => { logger.Debug("got account"); Dispatcher.Invoke(() => { if (s.IsFaulted || s.IsCanceled) { ShowAccountSetting(settings); } else { logger.Debug("start app"); StartApplication(settings, restClient); } }); }); }
private void StartApplication(LineTrader.Properties.Settings settings, Model.Oanda.RestClient restClient) { var service = new Model.Service(restClient, settings.Instruments.Split(',')); var win = new View.MainWindow(service); logger.Debug("showing window"); win.Show(); logger.Debug("window shown"); var mt4Server = new MT4Server(service); logger.Debug("start mt4 server"); mt4Server.Start(); logger.Debug("app started"); }