public async Task BuyOrder_Should_BeValid() { CryptoApiMock.MockBuyingTrade(new CryptoOrder { Market = Market, PricePerUnit = 100, Price = 1000, IsClosed = false, OrderType = CryptoOrderType.LimitBuy, Quantity = 9.975M, Limit = 100 }); Strategy.SetupGet(strategy => strategy.Settings).Returns(new TraderSettings { TradingBudget = 1000 }); InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Buy, OrderPricePerUnit = 100 }); await CoinTrader.UpdatePrice(new Ticker()); CryptoApiMock.Verify(c => c.BuyCoinAsync(It.Is <CryptoOrder>(b => b.PricePerUnit == 100 && b.Price == 1000 && b.Market == Market && !b.IsClosed && b.OrderType == CryptoOrderType.LimitBuy && b.Quantity == 9.975M && b.Limit == 100)), Times.Once); }
public async Task SellOrder_Should_BeValid() { CryptoApiMock.MockSellingTrade(new CryptoOrder { Market = Market, PricePerUnit = 110, Price = 1100, OrderType = CryptoOrderType.LimitSell, Quantity = 10M, Limit = 110 }); Strategy.SetupGet(strategy => strategy.Settings).Returns(new TraderSettings { TradingBudget = 1000 }); InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Sell, OrderPricePerUnit = 110 }); CoinTrader.TraderState.Trades[0].BuyOrder.Quantity = 10; await CoinTrader.UpdatePrice(new Ticker()); CryptoApiMock.Verify(c => c.SellCoinAsync(It.Is <CryptoOrder>(s => s.PricePerUnit == 110 && s.Price == 1100 && s.Market == Market && s.OrderType == CryptoOrderType.LimitSell && s.Quantity == 10M && s.Limit == 110)), Times.Once); }
public async Task CoinTrader_Should_CallStrategyWhenPriceIsUpdated() { await InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Sell }); await CoinTrader.UpdatePrice(_newPriceTicker); Strategy.Verify(s => s.CalculateTradeAction(It.Is <Ticker>(t => t.Ask == 100), It.IsAny <Trade>()), Times.Once); }
public async Task SellingCoin_Should_UpdateTradeStatusIfOrderIsSuccessful() { await InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Sell }); await CoinTrader.UpdatePrice(_newPriceTicker); CoinTrader.Trades[0].Status.Should().Be(TradeStatus.Selling); }
public async Task CoinTrader_Should_BeAbleToReceivePriceUpdates() { await InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Sell }); await CoinTrader.UpdatePrice(_newPriceTicker); CoinTrader.Ticker.Ask.Should().Be(100); }
public async Task SellAdvice_Should_CreateSellOrder() { await InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Sell, OrderPricePerUnit = 120 }); await CoinTrader.UpdatePrice(_newPriceTicker); CryptoApiMock.Verify(c => c.SellCoinAsync(It.Is <CryptoOrder>(b => b.PricePerUnit == 120)), Times.Once); }
public async Task BuyingOrder_Should_UpdateTraderStatus() { CryptoApiMock.MockBuyingTrade(new CryptoOrder()); await InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Buy, OrderPricePerUnit = 98 }); await CoinTrader.UpdatePrice(_newPriceTicker); CoinTrader.Trades[0].Status.Should().Be(TradeStatus.Buying); }
public async Task CancellingBuyOrder_Should_RemoveTrade() { CryptoApiMock.MockCancelTrade(new CryptoOrder()); await InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Cancel }); await CoinTrader.UpdatePrice(_newPriceTicker); CoinTrader.Trades.Count.Should().Be(0); }
public async Task SellOrder_Should_CreateEmptyTrade() { await InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Sell }); await CoinTrader.UpdatePrice(_newPriceTicker); CoinTrader.Trades.Count.Should().Be(2); CoinTrader.Trades[1].Status.Should().Be(TradeStatus.Empty); }
public async Task BuyAdvice_Should_CreateBuyOrder() { CryptoApiMock.MockBuyingTrade(new CryptoOrder()); await InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Buy, OrderPricePerUnit = 98 }); await CoinTrader.UpdatePrice(_newPriceTicker); CryptoApiMock.Verify(c => c.BuyCoinAsync(It.Is <CryptoOrder>(b => b.PricePerUnit == 98)), Times.Once); }
public async Task SellOrder_ShouldNot_CreateEmptyTrade() { InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Sell }); await CoinTrader.UpdatePrice(_newPriceTicker); CoinTrader.TraderState.Trades.Count.Should().Be(1); }
public async Task CompletedTrades_ShouldNot_BeUpdated() { await InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Sell }); CoinTrader.Trades[0].Status = TradeStatus.Completed; await CoinTrader.UpdatePrice(_newPriceTicker); Strategy.Verify(s => s.CalculateTradeAction(It.IsAny <Ticker>(), It.IsAny <Trade>()), Times.Never); }
public async Task CancelAdvice_Should_CancelBuyOrder() { CryptoApiMock.MockCancelTrade(new CryptoOrder()); await InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Cancel }); CoinTrader.Trades[0].BuyOrder.Uuid = "test"; await CoinTrader.UpdatePrice(_newPriceTicker); CryptoApiMock.Verify(c => c.CancelOrder(It.Is <string>(s => s == "test")), Times.Once); }
public async Task EmptyTradesList_Should_AddNewTrade() { CryptoApiMock.MockBuyingTrade(new CryptoOrder()); await InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Buy, OrderPricePerUnit = 98 }); CoinTrader.Trades = new List <Trade>(); await CoinTrader.UpdatePrice(_newPriceTicker); CoinTrader.Trades.Count.Should().Be(1); }
public async Task UpdatePrice_Should_UpdateAllTrades() { await InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Cancel }); CryptoApiMock.MockCancelTrade(new CryptoOrder()); CoinTrader.Trades.Add(new Trade()); await CoinTrader.UpdatePrice(_newPriceTicker); Strategy.Verify(s => s.CalculateTradeAction(It.IsAny <Ticker>(), It.IsAny <Trade>()), Times.Exactly(2)); }
public async Task ClosedOrder_Should_UpdateTradeStatus() { CryptoApiMock.MockBuyingTrade(new CryptoOrder()); InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Buy, OrderPricePerUnit = 98 }); await CoinTrader.UpdatePrice(_newPriceTicker); await CoinTrader.UpdateOrder(new CryptoOrder { IsClosed = false, OrderType = CryptoOrderType.LimitBuy }); CoinTrader.TraderState.Trades[0].Status.Should().NotBe(TradeStatus.Bought); }
public async Task MultipleSells_ShouldAdd_TradeForEachOne() { await InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Sell }); CoinTrader.Trades.Add(new Trade()); await CoinTrader.UpdatePrice(_newPriceTicker); CoinTrader.Trades.Count.Should().Be(4); CoinTrader.Trades[2].Status.Should().Be(TradeStatus.Empty); CoinTrader.Trades[3].Status.Should().Be(TradeStatus.Empty); }
public async Task CanceledBuyOrder_Should_RestoreAvailableBudget() { await TriggerBuy(100, 1000, 1000); CoinTrader.TraderState.Budget.Available.Should().Be(0); Strategy.SetTradeAction(new TradeAction { TradeAdvice = TradeAdvice.Cancel }); await CoinTrader.UpdatePrice(new Ticker()); CoinTrader.TraderState.Budget.Available.Should().Be(1000); }
public async Task CompletedTrades_ShouldNot_BeUpdated() { InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Hold }); CoinTrader.TraderState.Trades[0].Status = TradeStatus.Completed; CoinTrader.TraderState.Trades.Add(new Trade { Status = TradeStatus.Empty }); await CoinTrader.UpdatePrice(_newPriceTicker); Strategy.Verify(s => s.CalculateTradeAction(It.IsAny <Ticker>(), It.IsAny <Trade>()), Times.Once); }
private async Task TriggerBuy(decimal pricePerUnit, decimal price, decimal budget) { var cryptoOrder = new CryptoOrder { PricePerUnit = pricePerUnit, Price = price }; CryptoApiMock.MockBuyingTrade(cryptoOrder); CryptoApiMock.MockCancelTrade(cryptoOrder); await InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Buy, OrderPricePerUnit = pricePerUnit }); Strategy.SetupGet(strategy => strategy.Settings).Returns(new TraderSettings { TradingBudget = budget }); await CoinTrader.UpdatePrice(new Ticker()); }
public async Task PriceUpdate_Should_UpdateTraderProfit() { CryptoApiMock.MockBuyingTrade(new CryptoOrder()); var trade = new Trade(); trade.BuyOrder.PricePerUnit = 100; trade.BuyOrder.IsClosed = true; CoinTrader.TraderState.Trades = new List <Trade> { trade }; trade.Status = TradeStatus.Bought; CoinTrader.Strategy = new HoldUntilPriceDropsStrategy(); await CoinTrader.UpdatePrice(_newPriceTicker); CoinTrader.TraderState.Trades[0].Profit.Should().Be(19.4M); }
public async Task OnlyCompletedTrades_Should_AddNewTrade() { CryptoApiMock.MockBuyingTrade(new CryptoOrder()); InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Buy, OrderPricePerUnit = 98 }); CoinTrader.TraderState.Trades = new List <Trade> { new Trade { Status = TradeStatus.Completed } }; await CoinTrader.UpdatePrice(_newPriceTicker); CoinTrader.TraderState.Trades.Count.Should().Be(2); }
public async Task SellingCoin_Should_UpdateOrderForTrade() { await InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Sell, OrderPricePerUnit = 98 }); var sellOrder = new CryptoOrder { OrderType = CryptoOrderType.LimitSell, Price = 1100, Uuid = "S" }; CryptoApiMock.MockSellingTrade(sellOrder); CoinTrader.Trades[0].SellOrder.Uuid = "S"; await CoinTrader.UpdatePrice(_newPriceTicker); CoinTrader.Trades[0].SellOrder.Uuid.Should().Be("S"); CoinTrader.Trades[0].SellOrder.Price.Should().Be(1100); }