Ejemplo n.º 1
0
        public void Buy_ZeroQuantity_ThrowsException()
        {
            var subject = new Binance(Mock.Of <IWebSocket>(), Mock.Of <IBinanceClient>(), Mock.Of <ITime>());

            var e = Expect.ThrowAsync <ArgumentException>(async() => {
                await subject.Buy(new Sample(), 0);
            });

            Assert.AreEqual("quantity", e.ParamName);
        }
Ejemplo n.º 2
0
        public void Buy_NotInitialized_ThrowsException()
        {
            var subject = new Binance(Mock.Of <IWebSocket>(), Mock.Of <IBinanceClient>(), Mock.Of <ITime>());

            var e = Expect.ThrowAsync <InvalidOperationException>(async() => {
                await subject.Buy(new Sample(), 1);
            });

            Assert.AreEqual("Cannot Buy until Initialized", e.Message);
        }
Ejemplo n.º 3
0
        public void Buy_NullRate_ThrowsException()
        {
            var subject = new Binance(Mock.Of <IWebSocket>(), Mock.Of <IBinanceClient>(), Mock.Of <ITime>());

            var e = Expect.ThrowAsync <ArgumentNullException>(async() => {
                await subject.Buy(null, 1);
            });

            Assert.AreEqual("rate", e.ParamName);
        }
Ejemplo n.º 4
0
        public void Buy_TransactionLessThanMinQuantity_ReturnsNull()
        {
            var binanceClient = InitBinanceClientMock();
            var subject       = new Binance(Mock.Of <IWebSocket>(), binanceClient.Object, Mock.Of <ITime>());

            subject.Initialize(Assets.BTC, Assets.USDT).Wait();

            var result = subject.Buy(new Sample()
            {
                Value = 10000M
            }, 1).Result;

            Assert.IsNull(result);
            binanceClient.Verify(m => m.CreateOrder(It.IsAny <CreateOrderRequest>()), Times.Never());
        }
Ejemplo n.º 5
0
        public void Buy_TransactionMoreThanMinQuantity_SubmitsAndReturnsOrder()
        {
            var binanceClient = InitBinanceClientMock();

            binanceClient.Setup(m => m.CreateOrder(It.Is <CreateOrderRequest>(r =>
                                                                              r.Symbol == "BTCUSDT" &&
                                                                              r.Side == OrderSide.Buy &&
                                                                              r.Type == OrderType.Market &&
                                                                              r.Quantity == 0.0009M
                                                                              ))).ReturnsAsync(new ResultCreateOrderResponse()
            {
                ClientOrderId = "123"
            });
            var subject = new Binance(Mock.Of <IWebSocket>(), binanceClient.Object, Mock.Of <ITime>());

            subject.Initialize(Assets.BTC, Assets.USDT).Wait();

            var result = subject.Buy(new Sample()
            {
                Value = 10000M
            }, 10).Result;

            Assert.AreEqual("123", result.Id);
        }