Exemplo n.º 1
0
        public async Task GetMultipleBalancesUDTValue_BTC_BNB()
        {
            // Arrange
            var exchangeApi     = ExchangeServiceHelper.GetExchangeService(ExchangeServiceType.Standard);
            var exchangeService = new WpfExchangeService(exchangeApi);
            var symbolsCache    = SymbolsCacheHelper.GetSymbolsCache(exchangeService);
            var symbols         = await symbolsCache.GetSymbols(new[] { "BNBBTC" });

            var balances = new List <Interface.Model.AccountBalance>();

            balances.Add(new Interface.Model.AccountBalance {
                Asset = "BTC", Free = 0.00396715m
            });
            balances.Add(new Interface.Model.AccountBalance {
                Asset = "BNB", Free = 0.94444141m
            });

            var accountInfo = new Interface.Model.AccountInfo
            {
                Balances = balances
            };

            var account = new Account(accountInfo);

            // Act
            symbolsCache.ValueAccount(account);

            // Assert
            Assert.AreEqual(account.USDTValue, 50.51m);
            Assert.AreEqual(account.BTCValue, 0.00534226m);
        }
Exemplo n.º 2
0
        public async Task GetSingleBalanceUDTValue_BTC()
        {
            // Arrange
            var exchangeApi     = ExchangeServiceHelper.GetExchangeService(ExchangeServiceType.Standard);
            var exchangeService = new WpfExchangeService(exchangeApi);
            var symbolsCache    = SymbolsCacheHelper.GetSymbolsCache(exchangeService);
            var symbols         = await symbolsCache.GetSymbols();

            var balances = new List <Interface.AccountBalance>();

            balances.Add(new Interface.AccountBalance {
                Asset = "BTC", Free = 0.00794722m
            });

            var accountInfo = new Interface.AccountInfo
            {
                Balances = balances
            };

            var account = new Account(accountInfo);

            // Act
            symbolsCache.ValueAccount(account);

            // Assert
            Assert.AreEqual(account.USDTValue, 64.84m);
            Assert.AreEqual(account.BTCValue, 0.00794722m);
        }
Exemplo n.º 3
0
        public async Task GetSingleBalanceUDTValue_BNB()
        {
            // Arrange
            var exchangeApi     = ExchangeServiceHelper.GetExchangeService(ExchangeServiceType.Standard);
            var exchangeService = new WpfExchangeService(exchangeApi);
            var symbolsCache    = SymbolsCacheHelper.GetSymbolsCache(exchangeService);
            var symbols         = await symbolsCache.GetSymbols(new[] { "BNBBTC" });

            var balances = new List <Interface.Model.AccountBalance>();

            balances.Add(new Interface.Model.AccountBalance {
                Asset = "BNB", Free = 1.88373641m
            });

            var accountInfo = new Interface.Model.AccountInfo
            {
                Balances = balances
            };

            var account = new Account(accountInfo);

            // Act
            symbolsCache.ValueAccount(account);

            // Assert
            Assert.AreEqual(account.USDTValue, 25.93m);
            Assert.AreEqual(account.BTCValue, 0.00274272m);
        }
Exemplo n.º 4
0
        public async Task GetSingleBalanceUDTValue_BTC()
        {
            // Arrange
            var exchangeApi     = ExchangeServiceHelper.GetExchangeService(ExchangeServiceType.Standard);
            var exchangeService = new WpfExchangeService(exchangeApi);
            var symbolsCache    = SymbolsCacheHelper.GetSymbolsCache(exchangeService);
            await symbolsCache.GetSymbols(new[] { "BNBBTC" });

            var balances = new List <Core.Model.AccountBalance>
            {
                new Core.Model.AccountBalance {
                    Asset = "BTC", Free = 0.00794722m
                }
            };

            var accountInfo = new Core.Model.AccountInfo();

            accountInfo.Balances.AddRange(balances);

            var account = new Account(accountInfo);

            // Act
            symbolsCache.ValueAccount(account);

            // Assert
            Assert.AreEqual(account.USDTValue, 75.14m);
            Assert.AreEqual(account.BTCValue, 0.00794722m);
        }
Exemplo n.º 5
0
        public async Task AccountPreferences()
        {
            // Arrange
            var exchangeApi      = ExchangeServiceHelper.GetExchangeService(ExchangeServiceType.SymbolsViewModel);
            var exchangeService  = new WpfExchangeService(exchangeApi);
            var symbolsCache     = SymbolsCacheHelper.GetSymbolsCache(exchangeService);
            var symbolsViewModel = new SymbolsViewModel(exchangeService, symbolsCache, new DebugLogger());

            var userData = File.ReadAllText("UserAccounts.txt");
            var accounts = JsonConvert.DeserializeObject <UserAccounts>(userData);

            var account = accounts.Accounts.First();

            await Task.Delay(1000);

            // Act
            symbolsViewModel.SetAccount(account);

            // Assert
            var favourites = from s in symbolsViewModel.Symbols
                             join f in account.Preferences.FavouriteSymbols on s.Name equals f
                             select s;

            foreach (var favourite in favourites)
            {
                Assert.IsNotNull(symbolsViewModel.Symbols.First(s => s.Name.Equals(favourite.Name) && s.IsFavourite.Equals(true)));
            }

            Assert.AreEqual(symbolsViewModel.SelectedSymbol.Name, account.Preferences.SelectedSymbol);
        }
Exemplo n.º 6
0
        public void Login_AccountInfo_Update()
        {
            // Arrange
            var    fail             = false;
            var    hasUpdated       = false;
            string errorMessage     = string.Empty;
            var    exchangeApi      = ExchangeServiceHelper.GetExchangeService(ExchangeServiceType.SubscribeAccountInfo);
            var    exchangeService  = new WpfExchangeService(exchangeApi);
            var    symbolsCache     = SymbolsCacheHelper.GetSymbolsCache(exchangeService);
            var    accountViewModel = new AccountViewModel(exchangeService, symbolsCache, new DebugLogger());

            var account = new Account(new Interface.AccountInfo {
                User = new Interface.User()
            })
            {
                ApiKey    = "apikey",
                ApiSecret = "apisecret"
            };

            accountViewModel.Account = account;

            var accountObservable = Observable.FromEventPattern <AccountEventArgs>(
                eventHandler => accountViewModel.OnAccountNotification += eventHandler,
                eventHandler => accountViewModel.OnAccountNotification -= eventHandler)
                                    .Select(eventPattern => eventPattern.EventArgs);

            accountObservable.Subscribe(args =>
            {
                if (args.AccountEventType.Equals(AccountEventType.LoggedIn))
                {
                    // expected
                }
                else if (args.AccountEventType.Equals(AccountEventType.UpdateOrders))
                {
                    hasUpdated = true;
                }
                else
                {
                    fail = true;
                }
            });

            // Act
            accountViewModel.LoginCommand.Execute(null);

            // Assert
            var btc  = accountViewModel.Account.Balances.SingleOrDefault(ab => ab.Asset.Equals("BTC"));
            var bcpt = accountViewModel.Account.Balances.SingleOrDefault(ab => ab.Asset.Equals("BCPT"));
            var test = accountViewModel.Account.Balances.SingleOrDefault(ab => ab.Asset.Equals("TEST"));

            Assert.IsTrue(hasUpdated);
            Assert.IsNull(btc);
            Assert.IsNull(bcpt);
            Assert.IsNotNull(test);
            Assert.IsTrue(accountViewModel.Account.Balances.Count().Equals(5));
            Assert.IsFalse(fail);
        }
Exemplo n.º 7
0
        public void SelectedAsset()
        {
            // Arrange
            var            fail = false;
            AccountBalance selectedAccountBalance = null;
            var            exchangeApi            = ExchangeServiceHelper.GetExchangeService();
            var            exchangeService        = new WpfExchangeService(exchangeApi);
            var            symbolsCache           = SymbolsCacheHelper.GetSymbolsCache(exchangeService);
            var            accountViewModel       = new AccountViewModel(exchangeService, symbolsCache, new DebugLogger());

            var account = new Account(new Interface.AccountInfo {
                User = new Interface.User()
            })
            {
                ApiKey    = "apikey",
                ApiSecret = "apisecret"
            };

            accountViewModel.Account = account;

            var accountObservable = Observable.FromEventPattern <AccountEventArgs>(
                eventHandler => accountViewModel.OnAccountNotification += eventHandler,
                eventHandler => accountViewModel.OnAccountNotification -= eventHandler)
                                    .Select(eventPattern => eventPattern.EventArgs);

            accountObservable.Subscribe(args =>
            {
                if (args.AccountEventType.Equals(AccountEventType.LoggedOut) ||
                    args.AccountEventType.Equals(AccountEventType.LoggedIn))
                {
                    // expected
                }
                else if (args.AccountEventType.Equals(AccountEventType.SelectedAsset))
                {
                    selectedAccountBalance = args.SelectedAsset;
                }
                else
                {
                    fail = true;
                }
            });

            // Act
            accountViewModel.SetAccount(account);
            accountViewModel.LoginCommand.Execute(null);
            var trx = accountViewModel.Account.Balances.Single(ab => ab.Asset.Equals("TRX"));

            accountViewModel.SelectedAsset = trx;

            // Assert
            Assert.AreEqual(selectedAccountBalance, trx);
            Assert.IsFalse(fail);
        }
Exemplo n.º 8
0
        public void Login()
        {
            // Arrange
            var    fail             = false;
            var    loggedInAccount  = string.Empty;
            string errorMessage     = string.Empty;
            var    exchangeApi      = ExchangeServiceHelper.GetExchangeService();
            var    exchangeService  = new WpfExchangeService(exchangeApi);
            var    symbolsCache     = SymbolsCacheHelper.GetSymbolsCache(exchangeService);
            var    accountViewModel = new AccountViewModel(exchangeService, symbolsCache, new DebugLogger());

            var account = new Account(new Interface.AccountInfo {
                User = new Interface.User()
            })
            {
                ApiKey    = "apikey",
                ApiSecret = "apisecret"
            };

            accountViewModel.Account = account;

            var accountObservable = Observable.FromEventPattern <AccountEventArgs>(
                eventHandler => accountViewModel.OnAccountNotification += eventHandler,
                eventHandler => accountViewModel.OnAccountNotification -= eventHandler)
                                    .Select(eventPattern => eventPattern.EventArgs);

            accountObservable.Subscribe(args =>
            {
                if (args.AccountEventType.Equals(AccountEventType.LoggedIn))
                {
                    loggedInAccount = JsonConvert.SerializeObject(args.Value);
                }
                else
                {
                    fail = true;
                }
            });

            // Act
            accountViewModel.LoginCommand.Execute(null);

            // Assert
            var accountViewModelAccount = JsonConvert.SerializeObject(accountViewModel.Account);
            var accountInfo             = JsonConvert.SerializeObject(accountViewModel.Account.AccountInfo);
            var testAccountInfo         = JsonConvert.SerializeObject(TestHelper.AccountInfo);

            Assert.AreEqual(accountViewModelAccount, loggedInAccount);
            Assert.AreEqual(accountInfo, testAccountInfo);
            Assert.IsFalse(fail);
        }
Exemplo n.º 9
0
        public void SetAccount()
        {
            // Arrange
            var     fail             = false;
            Account notifyAccount    = null;
            var     exchangeApi      = ExchangeServiceHelper.GetExchangeService();
            var     exchangeService  = new WpfExchangeService(exchangeApi);
            var     symbolsCache     = SymbolsCacheHelper.GetSymbolsCache(exchangeService);
            var     accountViewModel = new AccountViewModel(exchangeService, symbolsCache, new DebugLogger());

            var account = new Account(new Interface.AccountInfo {
                User = new Interface.User()
            })
            {
                ApiKey    = "apikey",
                ApiSecret = "apisecret"
            };

            var accountObservable = Observable.FromEventPattern <AccountEventArgs>(
                eventHandler => accountViewModel.OnAccountNotification += eventHandler,
                eventHandler => accountViewModel.OnAccountNotification -= eventHandler)
                                    .Select(eventPattern => eventPattern.EventArgs);

            accountObservable.Subscribe(args =>
            {
                if (args.AccountEventType.Equals(AccountEventType.LoggedIn))
                {
                    notifyAccount = args.Value;
                }
                else
                {
                    fail = true;
                }
            });

            // Act
            accountViewModel.SetAccount(account);

            // Assert
            Assert.AreEqual(account.ApiKey, accountViewModel.Account.ApiKey);
            Assert.AreEqual(account.AccountInfo.User.ApiSecret, accountViewModel.Account.AccountInfo.User.ApiSecret);
            Assert.IsNotNull(notifyAccount);
            Assert.AreEqual(account.ApiKey, notifyAccount.ApiKey);
            Assert.AreEqual(account.AccountInfo.User.ApiSecret, notifyAccount.AccountInfo.User.ApiSecret);
            Assert.IsFalse(fail);
        }
Exemplo n.º 10
0
        public void Login_AccountKeyMissing_NotifyHasException()
        {
            // Arrange
            var    fail             = false;
            string errorMessage     = string.Empty;
            var    exchangeApi      = ExchangeServiceHelper.GetExchangeService();
            var    exchangeService  = new WpfExchangeService(exchangeApi);
            var    symbolsCache     = SymbolsCacheHelper.GetSymbolsCache(exchangeService);
            var    accountViewModel = new AccountViewModel(exchangeService, symbolsCache, new DebugLogger());

            var account = new Account(new Interface.AccountInfo {
                User = new Interface.User()
            })
            {
                ApiKey = "apikey"
            };

            accountViewModel.Account = account;

            var accountObservable = Observable.FromEventPattern <AccountEventArgs>(
                eventHandler => accountViewModel.OnAccountNotification += eventHandler,
                eventHandler => accountViewModel.OnAccountNotification -= eventHandler)
                                    .Select(eventPattern => eventPattern.EventArgs);

            accountObservable.Subscribe(args =>
            {
                if (args.HasException)
                {
                    errorMessage = args.Exception.Message;
                }
                else
                {
                    fail = true;
                }
            });

            // Act
            accountViewModel.LoginCommand.Execute(null);

            // Assert
            Assert.AreEqual(errorMessage, "Both api key and secret key are required to login to an account.");
            Assert.IsFalse(fail);
        }
Exemplo n.º 11
0
        public async Task SelectedSymbol()
        {
            // Arrange
            var    fail             = false;
            Symbol selectedSymbol   = null;
            var    exchangeApi      = ExchangeServiceHelper.GetExchangeService(ExchangeServiceType.SymbolsViewModel);
            var    exchangeService  = new WpfExchangeService(exchangeApi);
            var    symbolsCache     = SymbolsCacheHelper.GetSymbolsCache(exchangeService);
            var    symbolsViewModel = new SymbolsViewModel(exchangeService, symbolsCache, new DebugLogger());

            var symbolsObservable = Observable.FromEventPattern <SymbolsEventArgs>(
                eventHandler => symbolsViewModel.OnSymbolsNotification += eventHandler,
                eventHandler => symbolsViewModel.OnSymbolsNotification -= eventHandler)
                                    .Select(eventPattern => eventPattern.EventArgs);

            symbolsObservable.Subscribe((args) =>
            {
                if (args.Value != null)
                {
                    selectedSymbol = args.Value;
                }
                else if (args.Symbols != null)
                {
                    // expected
                }
                else
                {
                    fail = true;
                }
            });

            await Task.Delay(1000);

            // Act
            var trx = symbolsViewModel.Symbols.Single(s => s.Name.Equals("TRXBTC"));

            symbolsViewModel.SelectedSymbol = trx;

            // Assert
            Assert.AreEqual(symbolsViewModel.SelectedSymbol, selectedSymbol);
            Assert.IsFalse(fail);
        }
Exemplo n.º 12
0
        public async Task SymbolsViewModel_Initialise()
        {
            // Arrange
            var fail            = false;
            var exchangeApi     = ExchangeServiceHelper.GetExchangeService(ExchangeServiceType.SymbolsViewModel);
            var exchangeService = new WpfExchangeService(exchangeApi);
            var symbolsCache    = SymbolsCacheHelper.GetSymbolsCache(exchangeService);

            // Act
            var symbolsViewModel = new SymbolsViewModel(exchangeService, symbolsCache, new DebugLogger());

            var symbolsObservable = Observable.FromEventPattern <SymbolsEventArgs>(
                eventHandler => symbolsViewModel.OnSymbolsNotification += eventHandler,
                eventHandler => symbolsViewModel.OnSymbolsNotification -= eventHandler)
                                    .Select(eventPattern => eventPattern.EventArgs);

            symbolsObservable.Subscribe((args) =>
            {
                if (args.Symbols != null)
                {
                    // expected
                }
                else
                {
                    fail = true;
                }
            });

            await Task.Delay(1000);

            // Assert
            Assert.AreEqual(symbolsViewModel.Symbols.Count, TestHelper.Symbols.Count);
            Assert.IsNull(symbolsViewModel.AccountPreferences);
            Assert.IsNull(symbolsViewModel.SelectedSymbol);
            Assert.IsFalse(fail);
        }