예제 #1
0
        protected CoinTraderTestBase()
        {
            Market = "BTC-ETC";
            var pushManagerMock = new Mock <IPushManager>();

            CoinTrader = new CoinTrader(CryptoApiMock.Object, OrleansClientMock.Object, HubNotifierMock.Object, pushManagerMock.Object)
            {
                Strategy = Strategy.Object
            };
            var tickerSubject = new Subject <Ticker>();
            var orderSubject  = new Subject <CryptoOrder>();

            CryptoApiMock.SetupGet(c => c.TickerUpdated).Returns(tickerSubject);
            CryptoApiMock.SetupGet(c => c.OrderUpdated).Returns(orderSubject);
            TraderGrainMock.Setup(t => t.IsInitialized()).ReturnsAsync(true);
            HubNotifierMock.Setup(h => h.UpdateTrader(It.IsAny <TraderState>())).Returns(Task.CompletedTask);
            HubNotifierMock.Setup(h => h.UpdateTicker(It.IsAny <Ticker>())).Returns(Task.CompletedTask);
            TraderGrainMock.Setup(t => t.UpdateTrades(It.IsAny <List <Trade> >())).Returns(Task.CompletedTask);
            pushManagerMock.Setup(p => p.TriggerPush(It.IsAny <PushMessage>())).Returns(Task.CompletedTask);
            TraderGrainMock.Setup(c => c.GetTraderData()).ReturnsAsync(new TraderState {
                Trades = new List <Trade>()
            });
            OrleansClientMock.Setup(c => c.GetGrain <ITraderGrain>(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(TraderGrainMock.Object);
        }
예제 #2
0
        public async Task TraderGrain_Should_InitializeTrader()
        {
            TraderGrainMock.Setup(t => t.GetTraderData()).ReturnsAsync(new TraderState
            {
                Trades = new List <Trade> {
                    Trade.Empty, Trade.Empty, Trade.Empty, Trade.Empty
                }
            });
            await InitializeTrader(new TradeAction { TradeAdvice = TradeAdvice.Buy, OrderPricePerUnit = 1 });

            CoinTrader.Trades.Count.Should().Be(4);
            CoinTrader.Strategy.Settings.Should().NotBeNull();
        }
예제 #3
0
        protected void Reset()
        {
            Market = "BTC-ETC";
            var pushManagerMock = new Mock <IPushManager>();

            Strategy.SetupGet(strategy => strategy.Settings).Returns(new TraderSettings {
                TradingBudget = 1000
            });
            CoinTrader = new CoinTrader(CryptoApiMock.Object)
            {
                Strategy     = Strategy.Object,
                IsInTestMode = true
            };
            var tickerSubject = new Subject <Ticker>();
            var orderSubject  = new Subject <CryptoOrder>();

            CryptoApiMock.SetupGet(c => c.TickerUpdated).Returns(tickerSubject);
            CryptoApiMock.SetupGet(c => c.OrderUpdated).Returns(orderSubject);
            TraderGrainMock.Setup(t => t.IsInitialized()).ReturnsAsync(true);
            HubNotifierMock.Setup(h => h.UpdateTrader(It.IsAny <TraderState>())).Returns(Task.CompletedTask);
            HubNotifierMock.Setup(h => h.UpdateTicker(It.IsAny <Ticker>())).Returns(Task.CompletedTask);
            TraderGrainMock.Setup(t => t.UpdateTrades(It.IsAny <List <Trade> >())).Returns(Task.CompletedTask);
            pushManagerMock.Setup(p => p.TriggerPush(It.IsAny <PushMessage>())).Returns(Task.CompletedTask);
            var traderState = new TraderState
            {
                Trades   = new List <Trade>(),
                Budget   = new Budget(),
                Settings = new TraderSettings {
                    TradingBudget = 1000
                }
            };

            CoinTrader.TraderState = traderState;
            TraderGrainMock.Setup(c => c.GetTraderData()).ReturnsAsync(traderState);
            OrleansClientMock.Setup(c => c.GetGrain <ITraderGrain>(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(TraderGrainMock.Object);
        }