Пример #1
0
        private void ObserveAccount()
        {
            var accountObservable = Observable.FromEventPattern <AccountEventArgs>(
                eventHandler => AccountViewModel.OnAccountNotification += eventHandler,
                eventHandler => AccountViewModel.OnAccountNotification -= eventHandler)
                                    .Select(eventPattern => eventPattern.EventArgs);

            accountObservable.Subscribe(args =>
            {
                if (args.HasException)
                {
                    TradeViewModelException(args);
                }
                else if (args.AccountEventType.Equals(AccountEventType.LoggedIn) ||
                         args.AccountEventType.Equals(AccountEventType.LoggedOut))
                {
                    TradeViewModel.SetAccount(args.Value);
                    OrdersViewModel.SetAccount(args.Value);
                }
                else if (args.AccountEventType.Equals(AccountEventType.UpdateOrders))
                {
                    TradeViewModel.Touch();
                    OrdersViewModel.UpdateOrders(args.Value);
                }
                else if (args.AccountEventType.Equals(AccountEventType.SelectedAsset))
                {
                    TradeViewModel.SetSymbol(args.SelectedAsset);
                }
            });
        }
Пример #2
0
        protected override void OnDisposing()
        {
            base.OnDisposing();

            if (AccountViewModel != null)
            {
                AccountViewModel.Dispose();
            }

            foreach (var symbol in Symbols)
            {
                symbol.Dispose();
            }

            if (SymbolsViewModel != null)
            {
                SymbolsViewModel.Dispose();
            }

            if (TradeViewModel != null)
            {
                TradeViewModel.Dispose();
            }

            if (OrdersViewModel != null)
            {
                OrdersViewModel.Dispose();
            }
        }
Пример #3
0
        public TradingViewModel(ViewModelContext viewModelContext,
                                AccountViewModel accountViewModel, SymbolsViewModel symbolsViewModel,
                                TradeViewModel tradeViewModel, OrdersViewModel ordersViewModel,
                                IWpfExchangeService exchangeService, IAccountsService accountsService)
            : base(viewModelContext)
        {
            AccountViewModel = accountViewModel;
            SymbolsViewModel = symbolsViewModel;
            TradeViewModel   = tradeViewModel;
            OrdersViewModel  = ordersViewModel;

            Symbols = new ObservableCollection <SymbolViewModel>();

            this.exchangeService = exchangeService;
            this.accountsService = accountsService;

            ObserveSymbols();
            ObserveAccount();
            ObserveTrade();
            ObserveOrders();

            CloseCommand = new ViewModelCommand(Close);
        }
Пример #4
0
        private void ObserveSymbols()
        {
            var symbolsObservable = Observable.FromEventPattern <SymbolsEventArgs>(
                eventHandler => SymbolsViewModel.OnSymbolsNotification += eventHandler,
                eventHandler => SymbolsViewModel.OnSymbolsNotification -= eventHandler)
                                    .Select(eventPattern => eventPattern.EventArgs);

            symbolsObservable.Subscribe(async(args) =>
            {
                if (args.HasException)
                {
                    TradeViewModelException(args);
                }
                else if (args.Value != null)
                {
                    var symbol = Symbols.FirstOrDefault(s => s.Symbol.Name.Equals(args.Value.Name));
                    if (symbol != null)
                    {
                        SelectedSymbol = symbol;
                    }
                    else
                    {
                        symbol            = new SymbolViewModel(exchangeService);
                        symbol.Dispatcher = ViewModelContext.UiDispatcher;
                        ObserveSymbol(symbol);
                        Symbols.Add(symbol);
                        SelectedSymbol = symbol;
                        await symbol.SetSymbol(args.Value);
                    }
                }
                else if (args.Symbols != null)
                {
                    TradeViewModel.SetSymbols(args.Symbols);
                }
            });
        }