public void GetPrices24H_Should_RespondWithPricesForSymbol()
        {
            // arrange
            var expected = new Binance24HPrice()
            {
                AskPrice             = 0.123,
                BidPrice             = 0.456,
                CloseTime            = new DateTime(2017, 01, 02),
                FirstId              = 10000000000,
                HighPrice            = 0.789,
                LastId               = 20000000000,
                LastPrice            = 1.123,
                LowPrice             = 1.456,
                OpenPrice            = 1.789,
                OpenTime             = new DateTime(2017, 01, 01),
                PreviousClosePrice   = 2.123,
                PriceChange          = 2.456,
                PriceChangePercent   = 2.789,
                Trades               = 123,
                Volume               = 3.123,
                WeightedAveragePrice = 3.456
            };

            var client = PrepareClient(JsonConvert.SerializeObject(expected));

            // act
            var result = client.Get24HPrices("BNBBTC");

            // assert
            Assert.AreEqual(true, result.Success);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(expected, result.Data));
        }
        public void QueryOrder_Should_RespondWithQueriedOrder()
        {
            // arrange
            var order = new BinanceOrder()
            {
                ClientOrderId    = "order2",
                ExecutedQuantity = 0.6,
                IcebergQuantity  = 0.7,
                OrderId          = 200000000000,
                OriginalQuantity = 0.8,
                Price            = 0.9,
                Side             = OrderSide.Sell,
                Status           = OrderStatus.PartiallyFilled,
                StopPrice        = 1.0,
                Symbol           = "ETHBTC",
                Time             = new DateTime(2017, 1, 10),
                TimeInForce      = TimeInForce.ImmediateOrCancel,
                Type             = OrderType.Market
            };

            var client = PrepareClient(JsonConvert.SerializeObject(order));

            // act
            var result = client.QueryOrder("BNBBTC", orderId: 1);

            // assert
            Assert.IsTrue(result.Success);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(order, result.Data));
        }
        public void GetAllBookPrices_Should_RespondWithAllBookPrices()
        {
            // arrange
            var prices = new []
            {
                new BinanceBookPrice()
                {
                    AskPrice    = 0.1,
                    AskQuantity = 0.2,
                    BidPrice    = 0.3,
                    BidQuantity = 0.4,
                    Symbol      = "BNBBTC"
                },
                new BinanceBookPrice()
                {
                    AskPrice    = 0.5,
                    AskQuantity = 0.6,
                    BidPrice    = 0.7,
                    BidQuantity = 0.8,
                    Symbol      = "ETHBTC"
                }
            };

            var client = PrepareClient(JsonConvert.SerializeObject(prices));

            // act
            var result = client.GetAllBookPrices();

            // assert
            Assert.IsTrue(result.Success);
            Assert.AreEqual(prices.Length, result.Data.Length);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(prices[0], result.Data[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(prices[1], result.Data[1]));
        }
        public void GetAllPrices_Should_RespondWithAllPrices()
        {
            // arrange
            var prices = new []
            {
                new BinancePrice()
                {
                    Price  = 1.1,
                    Symbol = "BNBBTC"
                },
                new BinancePrice()
                {
                    Price  = 2.2,
                    Symbol = "ETHBTC"
                }
            };

            var client = PrepareClient(JsonConvert.SerializeObject(prices));

            // act
            var result = client.GetAllPrices();

            // assert
            Assert.IsTrue(result.Success);
            Assert.AreEqual(result.Data.Length, prices.Length);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(prices[0], result.Data[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(prices[1], result.Data[1]));
        }
        public void SubscribingToKlineStream_Should_TriggerWhenKlineStreamMessageIsReceived()
        {
            // arrange
            var socket = new Mock <IWebsocket>();

            socket.Setup(s => s.Close());
            socket.Setup(s => s.Connect()).Returns(Task.FromResult(true));
            socket.Setup(s => s.SetEnabledSslProtocols(It.IsAny <System.Security.Authentication.SslProtocols>()));

            var factory = new Mock <IWebsocketFactory>();

            factory.Setup(s => s.CreateWebsocket(It.IsAny <string>())).Returns(socket.Object);

            BinanceStreamKlineData result = null;
            var client = new BinanceSocketClient {
                SocketFactory = factory.Object
            };

            client.SubscribeToKlineStream("test", KlineInterval.OneMinute, (test) => result = test);

            var data = new BinanceCombinedStream <BinanceStreamKlineData>()
            {
                Stream = "test",
                Data   = new BinanceStreamKlineData()
                {
                    Event     = "TestKlineStream",
                    EventTime = new DateTime(2017, 1, 1),
                    Symbol    = "test",
                    Data      = new BinanceStreamKline()
                    {
                        TakerBuyBaseAssetVolume = 0.1m,
                        Close      = 0.2m,
                        CloseTime  = new DateTime(2017, 1, 2),
                        Final      = true,
                        FirstTrade = 10000000000,
                        High       = 0.3m,
                        Interval   = KlineInterval.OneMinute,
                        LastTrade  = 2000000000000,
                        Low        = 0.4m,
                        Open       = 0.5m,
                        TakerBuyQuoteAssetVolume = 0.6m,
                        QuoteAssetVolume         = 0.7m,
                        OpenTime   = new DateTime(2017, 1, 1),
                        Symbol     = "test",
                        TradeCount = 10,
                        Volume     = 0.8m
                    }
                }
            };

            // act
            socket.Raise(r => r.OnMessage += null, JsonConvert.SerializeObject(data));

            // assert
            Assert.IsNotNull(result);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data.Data, result, "Data"));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data.Data.Data, result.Data));
        }
Beispiel #6
0
        public void SubscribingToOrderUpdateStream_Should_TriggerWhenOrderUpdateStreamMessageIsReceived()
        {
            // arrange
            var socket = new Mock <IWebsocket>();

            socket.Setup(s => s.Close());
            socket.Setup(s => s.Connect());
            socket.Setup(s => s.Url).Returns("test");
            socket.Setup(s => s.SetEnabledSslProtocols(It.IsAny <System.Security.Authentication.SslProtocols>()));

            var factory = new Mock <IWebsocketFactory>();

            factory.Setup(s => s.CreateWebsocket(It.IsAny <string>())).Returns(socket.Object);

            BinanceStreamOrderUpdate result = null;
            var client = new BinanceSocketClient {
                SocketFactory = factory.Object
            };

            client.SubscribeToOrderUpdateStream("test", (test) => result = test);

            var data = new BinanceStreamOrderUpdate()
            {
                Event     = "executionReport",
                EventTime = new DateTime(2017, 1, 1),
                AccumulatedQuantityOfFilledTrades = 1.1,
                BuyerIsMaker              = true,
                C                         = "",
                Commission                = 2.2,
                CommissionAsset           = "test",
                ExecutionType             = ExecutionType.Trade,
                F                         = 3.3,
                g                         = 4.4,
                I                         = 100000000000,
                NewClientOrderId          = "test",
                OrderId                   = 100000000000,
                P                         = 5.5,
                Price                     = 6.6,
                PriceLastFilledTrade      = 7.7,
                Quantity                  = 8.8,
                QuantityOfLastFilledTrade = 9.9,
                RejectReason              = OrderRejectReason.AccountCannotSettle,
                Side                      = OrderSide.Buy,
                Status                    = OrderStatus.Filled,
                Symbol                    = "test",
                Time                      = new DateTime(2017, 1, 1),
                TimeInForce               = TimeInForce.GoodTillCancel,
                TradeId                   = 10000000000000,
                Type                      = OrderType.Limit
            };

            // act
            socket.Raise(r => r.OnMessage += null, new MessagedEventArgs(JsonConvert.SerializeObject(data), false, false, true, new byte[2]));

            // assert
            Assert.IsNotNull(result);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data, result, "Balances"));
        }
        public void SubscribingToUserStream_Should_TriggerWhenOrderUpdateStreamMessageIsReceived()
        {
            // arrange
            var socket = new Mock <IWebsocket>();

            socket.Setup(s => s.Close());
            socket.Setup(s => s.Connect()).Returns(Task.FromResult(true));
            socket.Setup(s => s.SetEnabledSslProtocols(It.IsAny <System.Security.Authentication.SslProtocols>()));

            var factory = new Mock <IWebsocketFactory>();

            factory.Setup(s => s.CreateWebsocket(It.IsAny <string>())).Returns(socket.Object);

            BinanceStreamOrderUpdate result = null;
            var client = new BinanceSocketClient {
                SocketFactory = factory.Object
            };

            client.SubscribeToUserStream("test", null, (test) => result = test);

            var data = new BinanceStreamOrderUpdate()
            {
                Event     = "executionReport",
                EventTime = new DateTime(2017, 1, 1),
                AccumulatedQuantityOfFilledTrades = 1.1m,
                BuyerIsMaker    = true,
                Commission      = 2.2m,
                CommissionAsset = "test",
                ExecutionType   = ExecutionType.Trade,
                I       = 100000000000,
                OrderId = 100000000000,
                Price   = 6.6m,
                PriceLastFilledTrade      = 7.7m,
                Quantity                  = 8.8m,
                QuantityOfLastFilledTrade = 9.9m,
                RejectReason              = OrderRejectReason.AccountCannotSettle,
                Side                  = OrderSide.Buy,
                Status                = OrderStatus.Filled,
                Symbol                = "test",
                Time                  = new DateTime(2017, 1, 1),
                TimeInForce           = TimeInForce.GoodTillCancel,
                TradeId               = 10000000000000,
                Type                  = OrderType.Limit,
                ClientOrderId         = "123",
                IcebergQuantity       = 9.9m,
                IsWorking             = true,
                OriginalClientOrderId = "456",
                StopPrice             = 10.10m
            };

            // act
            socket.Raise(r => r.OnMessage += null, JsonConvert.SerializeObject(data));

            // assert
            Assert.IsNotNull(result);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data, result, "Balances"));
        }
        public void SubscribingToAllSymbolTicker_Should_TriggerWhenAllSymbolTickerStreamMessageIsReceived()
        {
            // arrange
            var socket = new Mock <IWebsocket>();

            socket.Setup(s => s.Close());
            socket.Setup(s => s.Connect()).Returns(Task.FromResult(true));
            socket.Setup(s => s.SetEnabledSslProtocols(It.IsAny <System.Security.Authentication.SslProtocols>()));

            var factory = new Mock <IWebsocketFactory>();

            factory.Setup(s => s.CreateWebsocket(It.IsAny <string>())).Returns(socket.Object);

            BinanceStreamTick[] result = null;
            var client = new BinanceSocketClient {
                SocketFactory = factory.Object
            };

            client.SubscribeToAllSymbolTicker((test) => result = test);

            var data = new[]
            {
                new BinanceStreamTick()
                {
                    BestAskPrice          = 0.1m,
                    BestAskQuantity       = 0.2m,
                    BestBidPrice          = 0.3m,
                    BestBidQuantity       = 0.4m,
                    CloseTradesQuantity   = 0.5m,
                    CurrentDayClosePrice  = 0.6m,
                    FirstTradeId          = 1,
                    HighPrice             = 0.7m,
                    LastTradeId           = 2,
                    LowPrice              = 0.8m,
                    OpenPrice             = 0.9m,
                    PrevDayClosePrice     = 1.0m,
                    PriceChange           = 1.1m,
                    PriceChangePercentage = 1.2m,
                    StatisticsCloseTime   = new DateTime(2017, 1, 2),
                    StatisticsOpenTime    = new DateTime(2017, 1, 1),
                    Symbol = "test",
                    TotalTradedBaseAssetVolume  = 1.3m,
                    TotalTradedQuoteAssetVolume = 1.4m,
                    TotalTrades     = 3,
                    WeightedAverage = 1.5m
                }
            };

            // act
            socket.Raise(r => r.OnMessage += null, JsonConvert.SerializeObject(data));

            // assert
            Assert.IsNotNull(result);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data[0], result[0]));
        }
Beispiel #9
0
        public void SubscribingToKlineStream_Should_TriggerWhenKlineStreamMessageIsReceived()
        {
            // arrange
            var socket = new Mock <IWebsocket>();

            socket.Setup(s => s.Close());
            socket.Setup(s => s.Connect());
            socket.Setup(s => s.Url).Returns("test");
            socket.Setup(s => s.SetEnabledSslProtocols(It.IsAny <System.Security.Authentication.SslProtocols>()));

            var factory = new Mock <IWebsocketFactory>();

            factory.Setup(s => s.CreateWebsocket(It.IsAny <string>())).Returns(socket.Object);

            BinanceStreamKline result = null;
            var client = new BinanceSocketClient {
                SocketFactory = factory.Object
            };

            client.SubscribeToKlineStream("test", KlineInterval.OneMinute, (test) => result = test);

            var data = new BinanceStreamKline()
            {
                Event     = "TestKlineStream",
                EventTime = new DateTime(2017, 1, 1),
                Symbol    = "test",
                Data      = new BinanceStreamKlineInner()
                {
                    ActiveBuyVolume      = 0.1,
                    Close                = 0.2,
                    EndTime              = new DateTime(2017, 1, 2),
                    Final                = true,
                    FirstTrade           = 10000000000,
                    High                 = 0.3,
                    Interval             = KlineInterval.OneMinute,
                    LastTrade            = 2000000000000,
                    Low                  = 0.4,
                    Open                 = 0.5,
                    QuoteActiveBuyVolume = 0.6,
                    QuoteVolume          = 0.7,
                    StartTime            = new DateTime(2017, 1, 1),
                    Symbol               = "test",
                    TradeCount           = 10,
                    Volume               = 0.8
                }
            };

            // act
            socket.Raise(r => r.OnMessage += null, new MessagedEventArgs(JsonConvert.SerializeObject(data), false, false, true, new byte[2]));

            // assert
            Assert.IsNotNull(result);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data, result, "Data"));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data.Data, result.Data));
        }
Beispiel #10
0
        public void SubscribingToAccountUpdateStream_Should_TriggerWhenAccountUpdateStreamMessageIsReceived()
        {
            // arrange
            var socket = new Mock <IWebsocket>();

            socket.Setup(s => s.Close());
            socket.Setup(s => s.Connect());
            socket.Setup(s => s.Url).Returns("test");
            socket.Setup(s => s.SetEnabledSslProtocols(It.IsAny <System.Security.Authentication.SslProtocols>()));

            var factory = new Mock <IWebsocketFactory>();

            factory.Setup(s => s.CreateWebsocket(It.IsAny <string>())).Returns(socket.Object);

            BinanceStreamAccountInfo result = null;
            var client = new BinanceSocketClient {
                SocketFactory = factory.Object
            };

            client.SubscribeToAccountUpdateStream("test", (test) => result = test);

            var data = new BinanceStreamAccountInfo()
            {
                Event            = "outboundAccountInfo",
                EventTime        = new DateTime(2017, 1, 1),
                BuyerCommission  = 1.1,
                CanDeposit       = true,
                CanTrade         = true,
                CanWithdraw      = false,
                MakerCommission  = 2.2,
                SellerCommission = 3.3,
                TakerCommission  = 4.4,
                Balances         = new List <BinanceStreamBalance>()
                {
                    new BinanceStreamBalance()
                    {
                        Asset = "test1", Free = 1.1, Locked = 2.2
                    },
                    new BinanceStreamBalance()
                    {
                        Asset = "test2", Free = 3.3, Locked = 4.4
                    },
                }
            };

            // act
            socket.Raise(r => r.OnMessage += null, new MessagedEventArgs(JsonConvert.SerializeObject(data), false, false, true, new byte[2]));

            // assert
            Assert.IsNotNull(result);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data, result, "Balances"));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data.Balances[0], result.Balances[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data.Balances[1], result.Balances[1]));
        }
        public void GetOpenOrders_Should_RespondWithOpenOrders()
        {
            // arrange
            var orders = new []
            {
                new BinanceOrder()
                {
                    ClientOrderId    = "order1",
                    ExecutedQuantity = 0.1,
                    IcebergQuantity  = 0.2,
                    OrderId          = 100000000000,
                    OriginalQuantity = 0.3,
                    Price            = 0.4,
                    Side             = OrderSide.Buy,
                    Status           = OrderStatus.Canceled,
                    StopPrice        = 0.5,
                    Symbol           = "BNBBTC",
                    Time             = new DateTime(2017, 1, 1),
                    TimeInForce      = TimeInForce.GoodTillCancel,
                    Type             = OrderType.Limit
                },
                new BinanceOrder()
                {
                    ClientOrderId    = "order2",
                    ExecutedQuantity = 0.6,
                    IcebergQuantity  = 0.7,
                    OrderId          = 200000000000,
                    OriginalQuantity = 0.8,
                    Price            = 0.9,
                    Side             = OrderSide.Sell,
                    Status           = OrderStatus.PartiallyFilled,
                    StopPrice        = 1.0,
                    Symbol           = "ETHBTC",
                    Time             = new DateTime(2017, 1, 10),
                    TimeInForce      = TimeInForce.ImmediateOrCancel,
                    Type             = OrderType.Market
                }
            };

            var client = PrepareClient(JsonConvert.SerializeObject(orders));

            // act
            var result = client.GetOpenOrders("BNBBTC");

            // assert
            Assert.IsTrue(result.Success);
            Assert.AreEqual(orders.Length, result.Data.Length);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(orders[0], result.Data[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(orders[1], result.Data[1]));
        }
Beispiel #12
0
        public void GetKlines_Should_RespondWithKlines()
        {
            // arrange
            var klines = new []
            {
                new BinanceKline()
                {
                    QuoteAssetVolume = 0.1m,
                    Close            = 0.2m,
                    CloseTime        = new DateTime(1970, 1, 1),
                    High             = 0.3m,
                    Low      = 0.4m,
                    Open     = 0.5m,
                    OpenTime = new DateTime(1970, 1, 1),
                    TakerBuyBaseAssetVolume  = 0.6m,
                    TakerBuyQuoteAssetVolume = 0.7m,
                    TradeCount = 10,
                    Volume     = 0.8m
                },
                new BinanceKline()
                {
                    QuoteAssetVolume = 0.9m,
                    Close            = 1.0m,
                    CloseTime        = new DateTime(1970, 1, 1),
                    High             = 1.1m,
                    Low      = 1.2m,
                    Open     = 1.3m,
                    OpenTime = new DateTime(1970, 1, 1),
                    TakerBuyBaseAssetVolume  = 1.4m,
                    TakerBuyQuoteAssetVolume = 1.5m,
                    TradeCount = 20,
                    Volume     = 1.6m
                }
            };

            var client = PrepareClient(JsonConvert.SerializeObject(new object[]
            {
                new object[] { 0, 0.5m, 0.3m, 0.4m, 0.2m, 0.8m, 0, 0.1m, 10, 0.6m, 0.7m },
                new object[] { 0, 1.3m, 1.1m, 1.2m, 1.0m, 1.6m, 0, 0.9m, 20, 1.4m, 1.5m }
            }));

            // act
            var result = client.GetKlines("BNBBTC", KlineInterval.OneMinute);

            // assert
            Assert.IsTrue(result.Success);
            Assert.AreEqual(result.Data.Length, klines.Length);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(klines[0], result.Data[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(klines[1], result.Data[1]));
        }
Beispiel #13
0
        public void SubscribingToPartialBookDepthStream_Should_TriggerWhenPartialBookStreamMessageIsReceived()
        {
            // arrange
            var socket = new Mock <IWebsocket>();

            socket.Setup(s => s.Close());
            socket.Setup(s => s.Connect()).Returns(Task.FromResult(true));
            socket.Setup(s => s.SetEnabledSslProtocols(It.IsAny <System.Security.Authentication.SslProtocols>()));

            var factory = new Mock <IWebsocketFactory>();

            factory.Setup(s => s.CreateWebsocket(It.IsAny <string>())).Returns(socket.Object);

            BinanceOrderBook result = null;
            var client = new BinanceSocketClient {
                SocketFactory = factory.Object
            };

            client.SubscribeToPartialBookDepthStream("test", 10, (test) => result = test);

            var data = new BinanceOrderBook()
            {
                Asks = new List <BinanceOrderBookEntry>()
                {
                    new BinanceOrderBookEntry()
                    {
                        Price    = 0.1m,
                        Quantity = 0.2m
                    },
                    new BinanceOrderBookEntry()
                    {
                        Price    = 0.3m,
                        Quantity = 0.4m
                    }
                },
                LastUpdateId = 1,
                Bids         = new List <BinanceOrderBookEntry>()
            };

            // act
            socket.Raise(r => r.OnMessage += null, JsonConvert.SerializeObject(data));

            // assert
            Assert.IsNotNull(result);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data, result, "Asks", "Bids"));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data.Asks[0], result.Asks[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data.Asks[1], result.Asks[1]));
        }
Beispiel #14
0
        public void GetOrderBook_Should_RespondWithOrderBook()
        {
            // arrange
            var orderBook = new BinanceOrderBook()
            {
                LastUpdateId = 123,
                Asks         = new List <BinanceOrderBookEntry>()
                {
                    new BinanceOrderBookEntry()
                    {
                        Price    = 0.1m,
                        Quantity = 1.1m
                    },
                    new BinanceOrderBookEntry()
                    {
                        Price    = 0.2m,
                        Quantity = 2.2m
                    }
                },
                Bids = new List <BinanceOrderBookEntry>()
                {
                    new BinanceOrderBookEntry()
                    {
                        Price    = 0.3m,
                        Quantity = 3.3m
                    },
                    new BinanceOrderBookEntry()
                    {
                        Price    = 0.4m,
                        Quantity = 4.4m
                    }
                }
            };

            var client = PrepareClient("{\"lastUpdateId\":123,\"asks\": [[0.1, 1.1], [0.2, 2.2]], \"bids\": [[0.3,3.3], [0.4,4.4]]}");

            // act
            var result = client.GetOrderBook("BNBBTC");

            // assert
            Assert.IsTrue(result.Success);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(orderBook, result.Data, "Asks", "Bids"));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(orderBook.Asks[0], result.Data.Asks[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(orderBook.Asks[1], result.Data.Asks[1]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(orderBook.Bids[0], result.Data.Bids[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(orderBook.Bids[1], result.Data.Bids[1]));
        }
        public void GetOrderBook_Should_RespondWithOrderBook()
        {
            // arrange
            var orderBook = new BinanceOrderBook()
            {
                LastUpdateId = 123,
                Asks         = new List <BinanceOrderBookEntry>()
                {
                    new BinanceOrderBookEntry()
                    {
                        Price    = 0.1,
                        Quantity = 1.1
                    },
                    new BinanceOrderBookEntry()
                    {
                        Price    = 0.2,
                        Quantity = 2.2
                    }
                },
                Bids = new List <BinanceOrderBookEntry>()
                {
                    new BinanceOrderBookEntry()
                    {
                        Price    = 0.3,
                        Quantity = 3.3
                    },
                    new BinanceOrderBookEntry()
                    {
                        Price    = 0.4,
                        Quantity = 4.4
                    }
                }
            };

            var client = PrepareClient(JsonConvert.SerializeObject(orderBook));

            // act
            var result = client.GetOrderBook("BNBBTC");

            // assert
            Assert.IsTrue(result.Success);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(orderBook, result.Data, "Asks", "Bids"));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(orderBook.Asks[0], result.Data.Asks[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(orderBook.Asks[1], result.Data.Asks[1]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(orderBook.Bids[0], result.Data.Bids[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(orderBook.Bids[1], result.Data.Bids[1]));
        }
        public void GetKlines_Should_RespondWithKlines()
        {
            // arrange
            var klines = new []
            {
                new BinanceKline()
                {
                    AssetVolume              = 0.1,
                    Close                    = 0.2,
                    CloseTime                = new DateTime(2017, 1, 1),
                    High                     = 0.3,
                    Low                      = 0.4,
                    Open                     = 0.5,
                    OpenTime                 = new DateTime(2016, 1, 1),
                    TakerBuyBaseAssetVolume  = 0.6,
                    TakerBuyQuoteAssetVolume = 0.7,
                    Trades                   = 10,
                    Volume                   = 0.8
                },
                new BinanceKline()
                {
                    AssetVolume              = 0.9,
                    Close                    = 1.0,
                    CloseTime                = new DateTime(2015, 1, 1),
                    High                     = 1.1,
                    Low                      = 1.2,
                    Open                     = 1.3,
                    OpenTime                 = new DateTime(2014, 1, 1),
                    TakerBuyBaseAssetVolume  = 1.4,
                    TakerBuyQuoteAssetVolume = 1.5,
                    Trades                   = 20,
                    Volume                   = 1.6
                }
            };

            var client = PrepareClient(JsonConvert.SerializeObject(klines));

            // act
            var result = client.GetKlines("BNBBTC", KlineInterval.OneMinute);

            // assert
            Assert.IsTrue(result.Success);
            Assert.AreEqual(result.Data.Length, klines.Length);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(klines[0], result.Data[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(klines[1], result.Data[1]));
        }
        public void StartUserStream_Should_RespondWithListenKey()
        {
            // arrange
            var key = new BinanceListenKey()
            {
                ListenKey = "123"
            };

            var client = PrepareClient(JsonConvert.SerializeObject(key));

            // act
            var result = client.StartUserStream();

            // assert
            Assert.IsTrue(result.Success);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(key, result.Data));
        }
        public void Withdraw_Should_RespondWithSuccess()
        {
            // arrange
            var order = new BinanceWithdrawalPlaced()
            {
                Success = true
            };

            var client = PrepareClient(JsonConvert.SerializeObject(order));

            // act
            var result = client.Withdraw("BNBBTC", "test", 1);

            // assert
            Assert.IsTrue(result.Success);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(order, result.Data));
        }
        public void SubscribingToTradeStream_Should_TriggerWhenTradeStreamMessageIsReceived()
        {
            // arrange
            var socket = new Mock <IWebsocket>();

            socket.Setup(s => s.Close());
            socket.Setup(s => s.Connect()).Returns(Task.FromResult(true));
            socket.Setup(s => s.SetEnabledSslProtocols(It.IsAny <System.Security.Authentication.SslProtocols>()));

            var factory = new Mock <IWebsocketFactory>();

            factory.Setup(s => s.CreateWebsocket(It.IsAny <string>())).Returns(socket.Object);

            BinanceStreamTrade result = null;
            var client = new BinanceSocketClient {
                SocketFactory = factory.Object
            };

            client.SubscribeToTradesStream("test", (test) => result = test);

            var data = new BinanceCombinedStream <BinanceStreamTrade>()
            {
                Stream = "test",
                Data   = new BinanceStreamTrade()
                {
                    Event         = "TestTradeStream",
                    EventTime     = new DateTime(2017, 1, 1),
                    Symbol        = "test",
                    TradeId       = 1000000000000,
                    BuyerIsMaker  = true,
                    BuyerOrderId  = 10000000000000,
                    SellerOrderId = 2000000000000,
                    Price         = 1.1m,
                    Quantity      = 2.2m,
                    TradeTime     = new DateTime(2017, 1, 1)
                }
            };

            // act
            socket.Raise(r => r.OnMessage += null, JsonConvert.SerializeObject(data));

            // assert
            Assert.IsNotNull(result);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data.Data, result));
        }
        public void GetWithdrawHistory_Should_RespondWithWithdrawHistory()
        {
            // arrange
            var history = new BinanceWithdrawalList()
            {
                Success = true,
                List    = new List <BinanceWithdrawal>()
                {
                    new BinanceWithdrawal()
                    {
                        Address       = "test",
                        Amount        = 0.1,
                        ApplyTime     = new DateTime(2017, 1, 1),
                        Asset         = "BNB",
                        Status        = WithdrawalStatus.AwaitingApproval,
                        SuccessTime   = new DateTime(2017, 1, 2),
                        TransactionId = "1"
                    },
                    new BinanceWithdrawal()
                    {
                        Address       = "test2",
                        Amount        = 0.2,
                        ApplyTime     = new DateTime(2017, 1, 1),
                        Asset         = "ETH",
                        Status        = WithdrawalStatus.Completed,
                        SuccessTime   = new DateTime(2017, 1, 2),
                        TransactionId = "2"
                    }
                }
            };

            var client = PrepareClient(JsonConvert.SerializeObject(history));

            // act
            var result = client.GetWithdrawHistory();

            // assert
            Assert.IsTrue(result.Success);
            Assert.IsTrue(result.Data.Success);
            Assert.AreEqual(result.Data.List.Count, history.List.Count);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(history.List[0], result.Data.List[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(history.List[1], result.Data.List[1]));
        }
        public void GetMyTrades_Should_RespondWithTrades()
        {
            // arrange
            var trades = new []
            {
                new BinanceTrade()
                {
                    Commission      = 0.1,
                    CommissionAsset = "bnb",
                    Id          = 10000000000,
                    IsBestMatch = true,
                    IsBuyer     = false,
                    IsMaker     = true,
                    Price       = 0.3,
                    Quantity    = 0.4,
                    Time        = new DateTime(2017, 1, 1)
                },
                new BinanceTrade()
                {
                    Commission      = 0.5,
                    CommissionAsset = "eth",
                    Id          = 10000000000,
                    IsBestMatch = false,
                    IsBuyer     = true,
                    IsMaker     = false,
                    Price       = 0.6,
                    Quantity    = 0.7,
                    Time        = new DateTime(2016, 1, 1)
                }
            };

            var client = PrepareClient(JsonConvert.SerializeObject(trades));

            // act
            var result = client.GetMyTrades("BNBBTC");

            // assert
            Assert.IsTrue(result.Success);
            Assert.AreEqual(result.Data.Length, trades.Length);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(trades[0], result.Data[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(trades[1], result.Data[1]));
        }
        public void CancelOrder_Should_RespondWithCanceledOrder()
        {
            // arrange
            var canceled = new BinanceCanceledOrder()
            {
                ClientOrderId         = "test",
                OrderId               = 100000000000,
                Symbol                = "BNBBTC",
                OriginalClientOrderId = "test2"
            };

            var client = PrepareClient(JsonConvert.SerializeObject(canceled));

            // act
            var result = client.CancelOrder("BNBBTC");

            // assert
            Assert.IsTrue(result.Success);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(canceled, result.Data));
        }
        public void PlaceOrder_Should_RespondWithPlacedOrder()
        {
            // arrange
            var placed = new BinancePlacedOrder()
            {
                ClientOrderId = "test",
                OrderId       = 100000000000,
                Symbol        = "BNBBTC",
                TransactTime  = new DateTime(2017, 1, 1)
            };

            var client = PrepareClient(JsonConvert.SerializeObject(placed));

            // act
            var result = client.PlaceOrder("BNBBTC", OrderSide.Buy, OrderType.Limit, TimeInForce.GoodTillCancel, 1, 2);

            // assert
            Assert.IsTrue(result.Success);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(placed, result.Data));
        }
        public void GetAccountInfo_Should_RespondWithAccountInfo()
        {
            // arrange
            var accountInfo = new BinanceAccountInfo()
            {
                BuyerCommission  = 0.1,
                CanDeposit       = true,
                CanTrade         = false,
                CanWithdraw      = true,
                MakerCommission  = 0.2,
                SellerCommission = 0.3,
                TakerCommission  = 0.4,
                Balances         = new List <BinanceBalance>()
                {
                    new BinanceBalance()
                    {
                        Asset  = "bnb",
                        Free   = 0.1,
                        Locked = 0.2
                    },
                    new BinanceBalance()
                    {
                        Asset  = "btc",
                        Free   = 0.3,
                        Locked = 0.4
                    }
                }
            };

            var client = PrepareClient(JsonConvert.SerializeObject(accountInfo));

            // act
            var result = client.GetAccountInfo();

            // assert
            Assert.IsTrue(result.Success);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(accountInfo, result.Data, "Balances"));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(accountInfo.Balances[0], result.Data.Balances[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(accountInfo.Balances[1], result.Data.Balances[1]));
        }
        public void GetAggregatedTrades_Should_RespondWithGetAggregatedTrades()
        {
            // arrange
            var trades = new []
            {
                new BinanceAggregatedTrades()
                {
                    AggregateTradeId  = 1,
                    BuyerWasMaker     = true,
                    FirstTradeId      = 10000000000,
                    LastTradeId       = 200000000000,
                    Price             = 1.1,
                    Quantity          = 2.2,
                    Timestamp         = new DateTime(2017, 1, 1),
                    WasBestPriceMatch = true
                },
                new BinanceAggregatedTrades()
                {
                    AggregateTradeId  = 2,
                    BuyerWasMaker     = false,
                    FirstTradeId      = 30000000000,
                    LastTradeId       = 400000000000,
                    Price             = 3.3,
                    Quantity          = 4.4,
                    Timestamp         = new DateTime(2016, 1, 1),
                    WasBestPriceMatch = false
                }
            };

            var client = PrepareClient(JsonConvert.SerializeObject(trades));

            // act
            var result = client.GetAggregatedTrades("BNBBTC");

            // assert
            Assert.IsTrue(result.Success);
            Assert.AreEqual(trades.Length, result.Data.Length);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(trades[0], result.Data[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(trades[1], result.Data[1]));
        }
        public void GetDepositHistory_Should_RespondWithDepositHistory()
        {
            // arrange
            var history = new BinanceDepositList()
            {
                Success = true,
                List    = new List <BinanceDeposit>()
                {
                    new BinanceDeposit()
                    {
                        Amount     = 1.1,
                        Asset      = "BNB",
                        InsertTime = new DateTime(2017, 1, 1),
                        Status     = DepositStatus.Pending
                    },
                    new BinanceDeposit()
                    {
                        Amount     = 2.2,
                        Asset      = "BTC",
                        InsertTime = new DateTime(2016, 1, 1),
                        Status     = DepositStatus.Success
                    }
                }
            };

            var client = PrepareClient(JsonConvert.SerializeObject(history));

            // act
            var result = client.GetDepositHistory();

            // assert
            Assert.IsTrue(result.Success);
            Assert.IsTrue(result.Data.Success);
            Assert.AreEqual(result.Data.List.Count, history.List.Count);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(history.List[0], result.Data.List[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(history.List[1], result.Data.List[1]));
        }
Beispiel #27
0
        public void SubscribingToDepthStream_Should_TriggerWhenDepthStreamMessageIsReceived()
        {
            // arrange
            var socket = new Mock <IWebsocket>();

            socket.Setup(s => s.Close());
            socket.Setup(s => s.Connect());
            socket.Setup(s => s.Url).Returns("test");
            socket.Setup(s => s.SetEnabledSslProtocols(It.IsAny <System.Security.Authentication.SslProtocols>()));

            var factory = new Mock <IWebsocketFactory>();

            factory.Setup(s => s.CreateWebsocket(It.IsAny <string>())).Returns(socket.Object);

            BinanceStreamDepth result = null;
            var client = new BinanceSocketClient {
                SocketFactory = factory.Object
            };
            var subscibtion = client.SubscribeToDepthStream("test", (test) => result = test);

            var data = new BinanceStreamDepth()
            {
                Event     = "TestDepthStream",
                EventTime = new DateTime(2017, 1, 1),
                Symbol    = "test",
                UpdateId  = 1,
                Asks      = new List <BinanceOrderBookEntry>()
                {
                    new BinanceOrderBookEntry()
                    {
                        Price = 1.1, Quantity = 2.2
                    },
                    new BinanceOrderBookEntry()
                    {
                        Price = 3.3, Quantity = 4.4
                    }
                },
                Bids = new List <BinanceOrderBookEntry>()
                {
                    new BinanceOrderBookEntry()
                    {
                        Price = 5.5, Quantity = 6.6
                    },
                    new BinanceOrderBookEntry()
                    {
                        Price = 7.7, Quantity = 8.8
                    }
                }
            };

            // act
            socket.Raise(r => r.OnMessage += null, new MessagedEventArgs(JsonConvert.SerializeObject(data), false, false, true, new byte[2]));

            // assert
            Assert.IsTrue(subscibtion.Success);
            Assert.IsTrue(subscibtion.Data != 0);
            Assert.IsNotNull(result);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data, result, "Bids", "Asks"));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data.Asks[0], result.Asks[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data.Asks[1], result.Asks[1]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data.Bids[0], result.Bids[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data.Bids[1], result.Bids[1]));
        }