public async Task OrderTypes_SelectedSymbol() { // Arrange var cxlToken = new CancellationToken(); var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var tradeViewModel = new TradeViewModel(exchangeService); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(cxlToken); var trx = symbols.Single(s => s.Name.Equals("TRXBTC")); tradeViewModel.SetSymbols(symbols.ToList()); tradeViewModel.SelectedSymbol = trx; // Act var orderTypes = tradeViewModel.OrderTypes; // Assert Assert.AreEqual(tradeViewModel.SelectedSymbol, trx); var missing = InterfaceExtensions.OrderExtensions.OrderTypes().Except(tradeViewModel.OrderTypes).ToList(); foreach (var orderType in missing) { if (orderType != InterfaceExtensions.OrderExtensions.GetOrderTypeName(Interface.OrderType.StopLoss) && orderType != InterfaceExtensions.OrderExtensions.GetOrderTypeName(Interface.OrderType.TakeProfit)) { Assert.Fail(); } } }
public async Task SetAccount() { // Arrange var cxlToken = new CancellationToken(); var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var tradeViewModel = new TradeViewModel(exchangeService); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(cxlToken); var trx = symbols.Single(s => s.Name.Equals("TRXBTC")); tradeViewModel.SetSymbols(symbols.ToList()); var account = new Account(new Interface.AccountInfo { User = new Interface.User() }) { ApiKey = "apikey", ApiSecret = "apisecret" }; account = await exchangeService.GetAccountInfoAsync(account.AccountInfo.User.ApiKey, account.AccountInfo.User.ApiSecret, cxlToken); // Act tradeViewModel.SetAccount(account); // Assert Assert.AreEqual(tradeViewModel.Account, account); Assert.AreEqual(tradeViewModel.SelectedOrderType, null); Assert.IsNull(tradeViewModel.SelectedSymbol); }
public async Task Quantity_and_Price_and_StopPrice_NoTrim() { // Arrange var cxlToken = new CancellationToken(); var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var tradeViewModel = new TradeViewModel(exchangeService); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(cxlToken); tradeViewModel.SetSymbols(symbols.ToList()); var trx = tradeViewModel.Symbols.Single(s => s.Name.Equals("TRXBTC")); tradeViewModel.SelectedSymbol = trx; var quantity = 294m; var price = 1.12345678m; // Act tradeViewModel.Quantity = quantity; tradeViewModel.Price = price; tradeViewModel.StopPrice = price; // Assert Assert.AreEqual(tradeViewModel.Quantity, quantity.Trim(trx.QuantityPrecision)); Assert.AreEqual(tradeViewModel.Price, price.Trim(trx.PricePrecision)); Assert.AreEqual(tradeViewModel.StopPrice, price.Trim(trx.PricePrecision)); }
public async Task BuyQuantity_SufficientFunds() { // Arrange var cxlToken = new CancellationToken(); var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var tradeViewModel = new TradeViewModel(exchangeService, new DebugLogger()); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(Exchange.Test, cxlToken); var trx = symbols.Single(s => s.Name.Equals("TRXBTC")); var account = new Account(new Interface.Model.AccountInfo { User = new Interface.Model.User() }) { ApiKey = "apikey", ApiSecret = "apisecret" }; account = await exchangeService.GetAccountInfoAsync(Exchange.Test, account.AccountInfo.User, cxlToken); var selectedAsset = account.Balances.Single(ab => ab.Asset.Equals("TRX")); tradeViewModel.SetSymbols(symbols.ToList()); tradeViewModel.SetAccount(account); tradeViewModel.SetSymbol(selectedAsset); tradeViewModel.QuoteAccountBalance.Free = 0.00012693M; // Act tradeViewModel.BuyQuantityCommand.Execute(75); // Assert Assert.IsTrue(tradeViewModel.Quantity.Equals(10)); }
public async Task SellQuantity() { // Arrange var cxlToken = new CancellationToken(); var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var tradeViewModel = new TradeViewModel(exchangeService); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(cxlToken); var trx = symbols.Single(s => s.Name.Equals("TRXBTC")); var account = new Account(new Interface.AccountInfo { User = new Interface.User() }) { ApiKey = "apikey", ApiSecret = "apisecret" }; account = await exchangeService.GetAccountInfoAsync(account.AccountInfo.User.ApiKey, account.AccountInfo.User.ApiSecret, cxlToken); var selectedAsset = account.Balances.Single(ab => ab.Asset.Equals("TRX")); tradeViewModel.SetSymbols(symbols.ToList()); tradeViewModel.SetAccount(account); tradeViewModel.SetSymbol(selectedAsset); // Act tradeViewModel.SellQuantityCommand.Execute(75); // Assert Assert.IsTrue(tradeViewModel.Quantity.Equals((selectedAsset.Free * 0.75m).Trim(trx.QuantityPrecision))); }
public async Task SubscribeStatistics() { // Arrange var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var cxlToken = new CancellationToken(); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(Exchange.Test, cxlToken).ConfigureAwait(false);
public async Task Buy_Fails_PlaceOrder() { // Arrange var cxlToken = new CancellationToken(); var exchangeApi = ExchangeServiceHelper.GetExchangeService(ExchangeServiceType.PlaceOrderException); var exchangeService = new WpfExchangeService(exchangeApi); var tradeViewModel = new TradeViewModel(exchangeService); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(cxlToken); var trx = symbols.Single(s => s.Name.Equals("TRXBTC")); var account = new Account(new Interface.AccountInfo { User = new Interface.User() }) { ApiKey = "apikey", ApiSecret = "apisecret" }; account = await exchangeService.GetAccountInfoAsync(account.AccountInfo.User.ApiKey, account.AccountInfo.User.ApiSecret, cxlToken); var selectedAsset = account.Balances.Single(ab => ab.Asset.Equals("TRX")); tradeViewModel.SetSymbols(symbols.ToList()); tradeViewModel.SetAccount(account); tradeViewModel.SetSymbol(selectedAsset); tradeViewModel.QuoteAccountBalance.Free = 0.00012693M; tradeViewModel.SelectedOrderType = "Limit"; tradeViewModel.Quantity = 200m; tradeViewModel.Price = 0.00000900M; tradeViewModel.QuoteAccountBalance.Free = 200m * 0.00000900M; var tradeObservable = Observable.FromEventPattern <TradeEventArgs>( eventHandler => tradeViewModel.OnTradeNotification += eventHandler, eventHandler => tradeViewModel.OnTradeNotification -= eventHandler) .Select(eventPattern => eventPattern.EventArgs); Exception ex = null; tradeObservable.Subscribe(args => { if (args.HasException) { ex = args.Exception; } }); // Act tradeViewModel.BuyCommand.Execute(null); // Assert Assert.IsNotNull(ex); Assert.IsTrue(ex.Message.Contains("failed to place order")); }
public async Task Sell_Pass() { // Arrange var cxlToken = new CancellationToken(); var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var tradeViewModel = new TradeViewModel(exchangeService, new DebugLogger()); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(Exchange.Test, cxlToken); var trx = symbols.Single(s => s.Name.Equals("TRXBTC")); var account = new Account(new Core.Model.AccountInfo { User = new Core.Model.User() }) { ApiKey = "apikey", ApiSecret = "apisecret" }; account = await exchangeService.GetAccountInfoAsync(Exchange.Test, account.AccountInfo.User, cxlToken); var selectedAsset = account.Balances.Single(ab => ab.Asset.Equals("TRX")); tradeViewModel.SetSymbols(symbols.ToList()); tradeViewModel.SetAccount(account); tradeViewModel.SetSymbol(selectedAsset); tradeViewModel.QuoteAccountBalance.Free = 0.00012693M; tradeViewModel.SelectedOrderType = "Limit"; tradeViewModel.Quantity = tradeViewModel.BaseAccountBalance.Free; tradeViewModel.Price = 0.00000850M; var tradeObservable = Observable.FromEventPattern <TradeEventArgs>( eventHandler => tradeViewModel.OnTradeNotification += eventHandler, eventHandler => tradeViewModel.OnTradeNotification -= eventHandler) .Select(eventPattern => eventPattern.EventArgs); Exception ex = null; tradeObservable.Subscribe(args => { if (args.HasException) { ex = args.Exception; } }); // Act tradeViewModel.SellCommand.Execute(null); // Assert Assert.IsNull(ex); }
public async Task GetSymbols24HourStatisticsAsync() { // Arrange var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var cxlToken = new CancellationToken(); // Act var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(Exchange.Test, cxlToken).ConfigureAwait(false); // Assert var testResults = symbols.Where(s => s.SymbolStatistics.LastPrice.Equals(0.0M)).ToList(); Assert.IsFalse(testResults.Any()); }
public async Task OrderTypes_NoSelectedSymbol() { // Arrange var cxlToken = new CancellationToken(); var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var tradeViewModel = new TradePanelViewModel(exchangeService, new DebugLogger()); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(Exchange.Test, cxlToken); tradeViewModel.SetSymbols(symbols.ToList()); // Act // Assert Assert.IsNull(tradeViewModel.SelectedSymbol); var intersection = tradeViewModel.OrderTypes.Intersect(InterfaceExtensions.OrderExtensions.OrderTypes()).ToList(); Assert.IsTrue(InterfaceExtensions.OrderExtensions.OrderTypes().Count().Equals(intersection.Count)); }
public async Task SetAccount_Different_Account_Null_SelectedAsset() { // Arrange var cxlToken = new CancellationToken(); var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var tradeViewModel = new TradeViewModel(exchangeService, new DebugLogger()); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(Exchange.Test, cxlToken); tradeViewModel.SetSymbols(symbols.ToList()); var account = new Account(new Interface.Model.AccountInfo { User = new Interface.Model.User() }) { ApiKey = "apikey", ApiSecret = "apisecret" }; account = await exchangeService.GetAccountInfoAsync(Exchange.Test, account.AccountInfo.User, cxlToken); tradeViewModel.SetAccount(account); var differentAccount = new Account(new Interface.Model.AccountInfo { User = new Interface.Model.User() }) { ApiKey = "test123", ApiSecret = "test123" }; // Act tradeViewModel.SetAccount(differentAccount); // Assert Assert.AreEqual(tradeViewModel.Account, differentAccount); Assert.AreEqual(tradeViewModel.SelectedOrderType, null); Assert.IsNull(tradeViewModel.SelectedSymbol); }
public async Task SelectedOrderType_IsStopLoss_Not_IsLoading() { // Arrange var cxlToken = new CancellationToken(); var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var tradeViewModel = new TradeViewModel(exchangeService); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(cxlToken); tradeViewModel.SetSymbols(symbols.ToList()); var trx = tradeViewModel.Symbols.Single(s => s.Name.Equals("TRXBTC")); tradeViewModel.SelectedSymbol = trx; // Act tradeViewModel.SelectedOrderType = "Stop Loss"; // Assert Assert.IsFalse(tradeViewModel.IsPriceEditable); Assert.IsTrue(tradeViewModel.IsMarketPrice); }
public async Task SelectedSymbol_HasAccount() { // Arrange var cxlToken = new CancellationToken(); var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var tradeViewModel = new TradeViewModel(exchangeService); var account = new Account(new Interface.AccountInfo { User = new Interface.User() }) { ApiKey = "apikey", ApiSecret = "apisecret" }; account = await exchangeService.GetAccountInfoAsync(account.AccountInfo.User.ApiKey, account.AccountInfo.User.ApiSecret, cxlToken); var baseBalance = account.Balances.Single(a => a.Asset.Equals("TRX")); var quoteAsset = account.Balances.Single(a => a.Asset.Equals("BTC")); tradeViewModel.SetAccount(account); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(cxlToken); tradeViewModel.SetSymbols(symbols.ToList()); var trx = tradeViewModel.Symbols.Single(s => s.Name.Equals("TRXBTC")); // Act tradeViewModel.SelectedSymbol = trx; // Assert Assert.AreEqual(tradeViewModel.SelectedSymbol, trx); Assert.AreEqual(tradeViewModel.Quantity, 0); Assert.AreEqual(tradeViewModel.Price, trx.SymbolStatistics.LastPrice); Assert.AreEqual(tradeViewModel.StopPrice, trx.SymbolStatistics.LastPrice); Assert.AreEqual(tradeViewModel.BaseAccountBalance, baseBalance); Assert.AreEqual(tradeViewModel.QuoteAccountBalance, quoteAsset); }
public async Task SubscribeStatistics() { // Arrange var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var cxlToken = new CancellationToken(); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(cxlToken).ConfigureAwait(false); Action <Exception> exception = e => { }; // Act exchangeService.SubscribeStatistics(symbols, exception, cxlToken); // Assert var eth = symbols.Single(s => s.Name.Equals("ETHBTC")); var updatedEthStats = TestHelper.EthStats_UpdatedLastPrice_Upwards; Assert.AreEqual(eth.SymbolStatistics.PriceChangePercent, updatedEthStats.PriceChangePercent); Assert.AreEqual(eth.LastPriceChangeDirection, 1); Assert.AreEqual(eth.SymbolStatistics.LastPrice, updatedEthStats.LastPrice); }
public async Task SelectedSymbol_Null() { // Arrange var cxlToken = new CancellationToken(); var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var tradeViewModel = new TradeViewModel(exchangeService, new DebugLogger()); var account = new Account(new Interface.Model.AccountInfo { User = new Interface.Model.User() }) { ApiKey = "apikey", ApiSecret = "apisecret" }; account = await exchangeService.GetAccountInfoAsync(Exchange.Test, account.AccountInfo.User, cxlToken); tradeViewModel.SetAccount(account); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(Exchange.Test, cxlToken); tradeViewModel.SetSymbols(symbols.ToList()); var trx = tradeViewModel.Symbols.Single(s => s.Name.Equals("TRXBTC")); tradeViewModel.SelectedSymbol = trx; // Act tradeViewModel.SelectedSymbol = null; // Assert Assert.IsNull(tradeViewModel.SelectedSymbol); Assert.AreEqual(tradeViewModel.Quantity, 0); Assert.AreEqual(tradeViewModel.Price, 0); Assert.AreEqual(tradeViewModel.StopPrice, 0); Assert.IsNull(tradeViewModel.BaseAccountBalance); Assert.IsNull(tradeViewModel.QuoteAccountBalance); }
public async Task SelectedOrderType_SelectedSymbol() { // Arrange var cxlToken = new CancellationToken(); var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var tradeViewModel = new TradeViewModel(exchangeService); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(cxlToken); tradeViewModel.SetSymbols(symbols.ToList()); var trx = tradeViewModel.Symbols.Single(s => s.Name.Equals("TRXBTC")); tradeViewModel.SelectedSymbol = trx; // Act tradeViewModel.SelectedOrderType = "Limit"; // Assert Assert.AreEqual(tradeViewModel.SelectedOrderType, "Limit"); Assert.AreEqual(tradeViewModel.Price, trx.SymbolStatistics.LastPrice); Assert.AreEqual(tradeViewModel.StopPrice, trx.SymbolStatistics.LastPrice); }
public async Task GetRangeOfOrderTypes() { var cxlToken = new CancellationToken(); var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(Exchange.Test, cxlToken); var orderTypes = new List <Core.Model.OrderType>(); foreach (var symbol in symbols) { foreach (var orderType in symbol.OrderTypes) { if (!orderTypes.Contains(orderType)) { orderTypes.Add(orderType); } } } Assert.AreEqual(orderTypes.Count, 5); }
public async Task SelectedSymbol_NoAccount() { // Arrange var cxlToken = new CancellationToken(); var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var tradeViewModel = new TradeViewModel(exchangeService); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(cxlToken); tradeViewModel.SetSymbols(symbols.ToList()); var trx = tradeViewModel.Symbols.Single(s => s.Name.Equals("TRXBTC")); // Act tradeViewModel.SelectedSymbol = trx; // Assert Assert.AreEqual(tradeViewModel.SelectedSymbol, trx); Assert.AreEqual(tradeViewModel.Quantity, 0); Assert.AreEqual(tradeViewModel.Price, trx.SymbolStatistics.LastPrice); Assert.AreEqual(tradeViewModel.StopPrice, trx.SymbolStatistics.LastPrice); Assert.IsNull(tradeViewModel.BaseAccountBalance); Assert.IsNull(tradeViewModel.QuoteAccountBalance); }
public async Task SetSymbol() { // Arrange var cxlToken = new CancellationToken(); var exchangeApi = ExchangeServiceHelper.GetExchangeService(); var exchangeService = new WpfExchangeService(exchangeApi); var tradeViewModel = new TradeViewModel(exchangeService, new DebugLogger()); var symbols = await exchangeService.GetSymbols24HourStatisticsAsync(Exchange.Test, cxlToken); var trx = symbols.Single(s => s.Name.Equals("TRXBTC")); tradeViewModel.SetSymbols(symbols.ToList()); var account = new Account(new Core.Model.AccountInfo { User = new Core.Model.User() }) { ApiKey = "apikey", ApiSecret = "apisecret" }; account = await exchangeService.GetAccountInfoAsync(Exchange.Test, account.AccountInfo.User, cxlToken); var asset = account.Balances.Single(a => a.Asset.Equals("TRX")); tradeViewModel.SetAccount(account); // Act tradeViewModel.SetSymbol(asset); // Assert Assert.AreEqual(tradeViewModel.Account, account); Assert.AreEqual(tradeViewModel.SelectedOrderType, null); Assert.AreEqual(tradeViewModel.SelectedSymbol.Name, trx.Name); }