Exemple #1
0
        public async void Login(object param)
        {
            if (string.IsNullOrWhiteSpace(Account.AccountInfo.User.ApiKey) ||
                string.IsNullOrWhiteSpace(Account.AccountInfo.User.ApiSecret))
            {
                OnException("AccountViewModel.Login", new Exception("Both api key and secret key are required to login to an account."));
                return;
            }

            IsLoggingIn = true;

            try
            {
                Account = await ExchangeService.GetAccountInfoAsync(Account.AccountInfo.User.ApiKey, Account.AccountInfo.User.ApiSecret, accountCancellationTokenSource.Token);

                OnAccountLoggedIn(Account);

                ExchangeService.SubscribeAccountInfo(Account.AccountInfo.User, e => AccountInfoUpdate(e.AccountInfo), SubscribeAccountInfoException, accountCancellationTokenSource.Token);

                IsLoggedIn = true;
            }
            catch (Exception ex)
            {
                OnException("AccountViewModel.Login", ex);
                IsLoggedIn = false;
            }

            IsLoggingIn = false;
        }
Exemple #2
0
        public async Task Login(Account account)
        {
            if (account == null)
            {
                throw new ArgumentNullException(nameof(account));
            }

            try
            {
                if (string.IsNullOrWhiteSpace(account.AccountInfo.User.ApiKey) ||
                    string.IsNullOrWhiteSpace(account.AccountInfo.User.ApiSecret))
                {
                    return;
                }

                IsLoggingIn = true;

                Account = await ExchangeService.GetAccountInfoAsync(account.AccountInfo.User.Exchange, account.AccountInfo.User, accountCancellationTokenSource.Token).ConfigureAwait(true);

                OnAccountLoggedIn();

                await ExchangeService.SubscribeAccountInfo(Account.AccountInfo.User.Exchange, Account.AccountInfo.User, e => AccountInfoUpdate(e.AccountInfo), SubscribeAccountInfoException, accountCancellationTokenSource.Token).ConfigureAwait(true);

                symbolsCache = symbolsCacheFactory.GetSymbolsCache(Account.AccountInfo.User.Exchange);

                dispatcherTimer          = new DispatcherTimer();
                dispatcherTimer.Tick    += new EventHandler(DispatcherTimerTick);
                dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
                dispatcherTimer.Start();

                DispatcherTimerTick(this, EventArgs.Empty);
            }
            catch (Exception ex)
            {
                OnException(ex.Message, ex);
            }
            finally
            {
                IsLoggingIn = false;
            }
        }
        private async Task Login()
        {
            if (string.IsNullOrWhiteSpace(Account.AccountInfo.User.ApiKey) ||
                string.IsNullOrWhiteSpace(Account.AccountInfo.User.ApiSecret))
            {
                OnException("AccountViewModel.Login", new Exception("Both api key and secret key are required to login to an account."));
                return;
            }

            IsLoggingIn = true;

            try
            {
                Account = await ExchangeService.GetAccountInfoAsync(Account.AccountInfo.User.ApiKey, Account.AccountInfo.User.ApiSecret, accountCancellationTokenSource.Token);

                OnAccountLoggedIn(Account);

                ExchangeService.SubscribeAccountInfo(Account.AccountInfo.User, e => AccountInfoUpdate(e.AccountInfo), SubscribeAccountInfoException, accountCancellationTokenSource.Token);

                dispatcherTimer          = new DispatcherTimer();
                dispatcherTimer.Tick    += new EventHandler(DispatcherTimerTick);
                dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
                dispatcherTimer.Start();

                DispatcherTimerTick(this, EventArgs.Empty);

                IsLoggedIn = true;
            }
            catch (Exception ex)
            {
                OnException("AccountViewModel.Login", ex);
                IsLoggedIn = false;
            }

            IsLoggingIn = false;
        }