Example #1
0
        public void UpdateServerTime_ShouldReturnServerTime()
        {
            //Arrange
            _httpMessageHandlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(),
                                                 ItExpr.IsAny <CancellationToken>())
            .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(@"{""serverTime"":1592395836992}")
            }))
            .Verifiable();
            HttpClient httpClient = new HttpClient(_httpMessageHandlerMock.Object);

            _connectionAdapter.HttpClient = httpClient;
            Binance subjectUnderTest = new Binance {
                ConnectionAdapter = _connectionAdapter
            };

            //Act
            subjectUnderTest.UpdateTimeServerAsync().Wait();
            //Assert
            Assert.IsNotNull(subjectUnderTest.ServerTime);
            Assert.AreEqual(1592395836992, subjectUnderTest.ServerTime.ServerTimeLong);
        }
        public void UpdateProductHistoricCandles_ShouldReturnOrderBook_WhenAccountExists()
        {
            //Arrange
            _httpMessageHandlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(
                    $@"[
                    [1594131000000,""8244.44000000"",""8247.71000000"",""8234.56000000"",""8247.53000000"",""0.57541000"",1594131299999,""4743.74677830"",29,""0.51348500"",""4233.45949059"",""0""],
                    [1594131300000,""8251.92000000"",""8263.73000000"",""8235.49000000"",""8261.31000000"",""0.73944300"",1594131599999,""6104.99268016"",73,""0.44151600"",""3646.66755442"",""0""],
                    [1594131600000,""8258.99000000"",""8266.70000000"",""8253.56000000"",""8265.01000000"",""0.21730200"",1594131899999,""1795.04159624"",61,""0.12557200"",""1037.27246541"",""0""]]")
            }))
            .Verifiable();
            HttpClient        httpClient        = new HttpClient(_httpMessageHandlerMock.Object);
            ConnectionAdapter connectionFactory = new ConnectionAdapter(httpClient, _exchangeSettings);
            Binance           subjectUnderTest  = new Binance(connectionFactory);
            Product           product           = new Product
            {
                ID = "BTCEUR"
            };
            DateTime startingDateTime = new DateTime(2015, 4, 23).Date.ToUniversalTime();
            DateTime endingDateTime   = startingDateTime.AddMonths(6).ToUniversalTime();

            //Act
            subjectUnderTest.UpdateProductHistoricCandlesAsync(product, startingDateTime, endingDateTime).Wait();
            //Assert
            Assert.IsNotNull(subjectUnderTest.HistoricRates);
            Assert.AreEqual(3, subjectUnderTest.HistoricRates.Count);
            Assert.AreEqual((decimal)8234.56000000, subjectUnderTest.HistoricRates[0].Low);
            Assert.AreEqual((decimal)0.57541000, subjectUnderTest.HistoricRates[0].Volume);
        }
Example #3
0
        public AlertLayout(Exchanges Exchange, Coins Coin, Coins Pair)
        {
            childList = new List <AlertCard>();
            InitializeComponent();

            this.Exchange = Exchange;
            this.Coin     = Coin;
            this.Pair     = Pair;

            Header.alert    = this;
            Header.Exchange = Exchange;
            Header.Symbol   = Coin.ToString() + Pair.ToString();

            if (Exchange == Exchanges.Binance)
            {
                Binance b = Binance.Instance;
                exchangeIF = b;
            }

            /*AlertCard card = new AlertCard();
             * card.KlineWidth = KLineWidth.m5;
             * card.Indicator = Indicators.RSI;
             * card.Coin = Coins.ETH;
             * card.Pair = Coins.BTC;
             * this.addTo(card);*/
        }
Example #4
0
        public static async Task <string> GetBinancePrice(string crypto)
        {
            string USDTString = await GetUSDTPrice();

            double USDTPrice = Convert.ToDouble(USDTString);

            string cryptoUpper = crypto.ToUpper();

            if (cryptoUpper == "BTC")
            {
                return(USDTPrice.ToString());
            }

            HttpResponseMessage response = await client.GetAsync($"https://api.binance.com/api/v1/ticker/24hr?symbol={cryptoUpper}BTC");

            if (response.IsSuccessStatusCode)
            {
                string jsonResult = await response.Content.ReadAsStringAsync();

                Binance coin = JsonConvert.DeserializeObject <Binance>(jsonResult);

                double cryptoPrice = Convert.ToDouble(coin.lastPrice);

                double USDPrice = cryptoPrice * USDTPrice;
                string USD      = USDPrice.ToString();
                return(USD);
            }
            return("Put in a real coin you jagoff");
        }
        public void UpdateTickers_ShouldReturnProductsAndTickers_WhenProductsAndTickersExists()
        {
            //Arrange
            _httpMessageHandlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(
                    $@"{{""symbol"":""BTCEUR"",""price"":""8287.76000000""}}")
            }))
            .Verifiable();
            HttpClient        httpClient        = new HttpClient(_httpMessageHandlerMock.Object);
            ConnectionAdapter connectionFactory = new ConnectionAdapter(httpClient, _exchangeSettings);
            Binance           subjectUnderTest  = new Binance(connectionFactory);
            List <Product>    products          = new List <Product>
            {
                new Product {
                    ID = "BTCEUR"
                },
            };

            //Act
            subjectUnderTest.UpdateTickersAsync(products).Wait();
            //Assert
            Assert.IsNotNull(subjectUnderTest.Tickers);
            Assert.AreEqual(1, subjectUnderTest.Tickers.Count);
            Assert.AreEqual("BTCEUR", subjectUnderTest.Tickers[0].ProductID);
            Assert.AreEqual((decimal)8287.76000000, subjectUnderTest.Tickers[0].Price.ToDecimal());
            Assert.IsNotNull(subjectUnderTest.CurrentPrices);
            Assert.AreEqual(subjectUnderTest.CurrentPrices[subjectUnderTest.Tickers[0].ProductID], subjectUnderTest.Tickers[0].Price.ToDecimal());
        }
Example #6
0
        public void Ctor_WebsocketNull_ThrowsException()
        {
            var e = Expect.Throw <ArgumentNullException>(() => {
                var subject = new Binance(null, Mock.Of <IBinanceClient>(), Mock.Of <ITime>());
            });

            Assert.AreEqual("websocket", e.ParamName);
        }
Example #7
0
        public void Ctor_TimeNull_ThrowsException()
        {
            var e = Expect.Throw <ArgumentNullException>(() => {
                var subject = new Binance(Mock.Of <IWebSocket>(), Mock.Of <IBinanceClient>(), null);
            });

            Assert.AreEqual("time", e.ParamName);
        }
Example #8
0
        public async void BookTickerAllOnline()
        {
            var r   = new Maybe <IDownloadData>();
            var b   = new Binance(r);
            var res = await b.BookTicker(new Maybe <string>());

            Assert.NotEmpty(res);
        }
Example #9
0
        public Client(Binance exchange, ICurrencyFactory currencyFactory, ISymbolFactory symbolFactory)
        {
            Exchange        = exchange;
            CurrencyFactory = currencyFactory;
            SymbolFactory   = symbolFactory;

            RateLimiter = new BinanceRateLimiter();
        }
Example #10
0
        public async void BookTickerOneSymbolOnline()
        {
            var r   = new Maybe <IDownloadData>();
            var b   = new Binance(r);
            var res = await b.BookTicker(new Maybe <string>("ETHBTC"));

            Assert.Single(res);
        }
Example #11
0
        public async void TickerPriceAllOnline()
        {
            var r   = new Maybe <IDownloadData>();
            var b   = new Binance(r);
            var res = await b.TickerPrice("");

            Assert.NotEmpty(res);
        }
Example #12
0
        public async void DepthInfoOnlineWithLimit()
        {
            var r   = new Maybe <IDownloadData>();
            var b   = new Binance(r);
            var res = await b.Depth("ETHBTC", 5);

            Assert.Equal(5, res.Asks.Count);
        }
Example #13
0
        public void UpdateBinanceFills_ShouldReturnFills_WhenFillsExists()
        {
            //Arrange
            _httpMessageHandlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync",
                                                 ItExpr.Is <HttpRequestMessage>(x => x.RequestUri.AbsoluteUri.Contains("/api/v1/time")),
                                                 ItExpr.IsAny <CancellationToken>())
            .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(
                    @"{""serverTime"":1592395836992}")
            }))
            .Verifiable();
            _httpMessageHandlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync",
                                                 ItExpr.Is <HttpRequestMessage>(x => x.RequestUri.AbsoluteUri.Contains("/api/v3/myTrades?")),
                                                 ItExpr.IsAny <CancellationToken>())
            .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(
                    @"[{
                            ""symbol"": ""BNBBTC"",
                            ""id"": 28457,
                            ""orderId"": 100234,
                            ""orderListId"": -1,
                            ""price"": ""4.00000100"",
                            ""qty"": ""12.00000000"",
                            ""quoteQty"": ""48.000012"",
                            ""commission"": ""10.10000000"",
                            ""commissionAsset"": ""BNB"",
                            ""time"": 1499865549590,
                            ""isBuyer"": true,
                            ""isMaker"": false,
                            ""isBestMatch"": true
                            }]")
            }))
            .Verifiable();
            HttpClient httpClient = new HttpClient(_httpMessageHandlerMock.Object);

            _connectionAdapter.HttpClient = httpClient;
            Binance subjectUnderTest = new Binance {
                ConnectionAdapter = _connectionAdapter
            };
            Product product = new Product {
                ID = "BNBBTC"
            };

            //Act
            subjectUnderTest.UpdateFillsAsync(product).Wait();
            //Assert
            Assert.IsNotNull(subjectUnderTest.BinanceFill);
            Assert.AreEqual(1, subjectUnderTest.BinanceFill.Count);
            Assert.AreEqual(product.ID, subjectUnderTest.BinanceFill[0].ID);
        }
Example #14
0
        public async void TickerPriceSingleOnline()
        {
            var r   = new Maybe <IDownloadData>();
            var b   = new Binance(r);
            var res = await b.TickerPrice("ETHBTC");

            Assert.NotEmpty(res);
            Assert.Single(res);
            Assert.Equal("ETHBTC", res[0].Symbol);
        }
Example #15
0
        public void GetCurrentPrice_NotInitialized_ThrowsException()
        {
            var subject = new Binance(Mock.Of <IWebSocket>(), Mock.Of <IBinanceClient>(), Mock.Of <ITime>());

            var exception = Expect.ThrowAsync <InvalidOperationException>(async() => {
                await subject.GetCurrentPrice();
            });

            Assert.AreEqual("Binance cannot GetCurrentPrice until Initialized!", exception.Message);
        }
Example #16
0
        public void Sell_NullRate_ThrowsException()
        {
            var subject = new Binance(Mock.Of <IWebSocket>(), Mock.Of <IBinanceClient>(), Mock.Of <ITime>());

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

            Assert.AreEqual("rate", e.ParamName);
        }
Example #17
0
        public void Sell_ZeroQuantity_ThrowsException()
        {
            var subject = new Binance(Mock.Of <IWebSocket>(), Mock.Of <IBinanceClient>(), Mock.Of <ITime>());

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

            Assert.AreEqual("quantity", e.ParamName);
        }
Example #18
0
        public void Sell_NotInitialized_ThrowsException()
        {
            var subject = new Binance(Mock.Of <IWebSocket>(), Mock.Of <IBinanceClient>(), Mock.Of <ITime>());

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

            Assert.AreEqual("Cannot Sell until Initialized", e.Message);
        }
Example #19
0
        public void CheckOrder_NullOrderId_ThrowsException()
        {
            var binanceClient = new Mock <IBinanceClient>();
            var subject       = new Binance(Mock.Of <IWebSocket>(), binanceClient.Object, Mock.Of <ITime>());

            var e = Expect.ThrowAsync <ArgumentException>(async() =>
            {
                await subject.CheckOrder(new Order());
            });

            Assert.AreEqual("order", e.ParamName);
        }
Example #20
0
        public void CancelOrders_ShouldReturnBinanceOrder()
        {
            //Arrange
            _httpMessageHandlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync",
                                                 ItExpr.Is <HttpRequestMessage>(x => x.RequestUri.AbsoluteUri.Contains("/api/v1/time")),
                                                 ItExpr.IsAny <CancellationToken>())
            .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(
                    @"{""serverTime"":1592395836992}")
            }))
            .Verifiable();
            _httpMessageHandlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync",
                                                 ItExpr.Is <HttpRequestMessage>(x => x.RequestUri.AbsoluteUri.Contains("/api/v3/openOrders")),
                                                 ItExpr.IsAny <CancellationToken>())
            .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(
                    @"[{""symbol"":""BNBBTC"",""origClientOrderId"":""dYJEVoHBmZ9wO55DWErawG"",""orderId"":1369,
                            ""orderListId"":-1,""clientOrderId"":""oy60PoMjhqSDSA8JrbAdbb"",""price"":""0.00100000"",
                            ""origQty"":""0.10000000"",""executedQty"":""0.00000000"",""cummulativeQuoteQty"":""0.00000000"",
                            ""status"":""CANCELED"",""timeInForce"":""GTC"",""type"":""LIMIT"",""side"":""BUY""},
                            {""symbol"":""BNBBTC"",""origClientOrderId"":""d81bitzsSWPjprIJhgHxR1"",""orderId"":1371,
                            ""orderListId"":-1,""clientOrderId"":""oy60PoMjhqSDSA8JrbAdbb"",""price"":""0.00100000"",""origQty"":""0.10000000"",
                            ""executedQty"":""0.00000000"",""cummulativeQuoteQty"":""0.00000000"",""status"":""CANCELED"",""timeInForce"":""GTC"",
                            ""type"":""LIMIT"",""side"":""BUY""},
                            {""symbol"":""BNBBTC"",""origClientOrderId"":""eE5TpVjDdljT3Q6121rbkD"",""orderId"":1373,""orderListId"":-1,
                              ""clientOrderId"":""oy60PoMjhqSDSA8JrbAdbb"",""price"":""0.00100000"",""origQty"":""0.10000000"",
                              ""executedQty"":""0.00000000"",""cummulativeQuoteQty"":""0.00000000"",""status"":""CANCELED"",
                            ""timeInForce"":""GTC"",""type"":""LIMIT"",""side"":""BUY""}]")
            }))
            .Verifiable();
            HttpClient httpClient = new HttpClient(_httpMessageHandlerMock.Object);

            _connectionAdapter.HttpClient = httpClient;
            Binance subjectUnderTest = new Binance {
                ConnectionAdapter = _connectionAdapter
            };
            Product product = new Product {
                ID = "BNBBTC"
            };
            //Act
            List <BinanceOrder> binanceOrders = subjectUnderTest.CancelBinanceOrdersAsync(product).Result;

            //Assert
            Assert.IsNotNull(binanceOrders);
        }
Example #21
0
        public void Initialize_ValidPair_OpensSocketAndSubscribesAndReturnsBalances()
        {
            var socketMock  = new Mock <IWebSocket>();
            var binanceMock = InitBinanceClientMock();

            var subject = new Binance(socketMock.Object, binanceMock.Object, Mock.Of <ITime>());

            var(asset1, asset2) = subject.Initialize(Assets.BTC, Assets.USDT).Result;

            socketMock.Verify(m => m.Connect("wss://stream.binance.com:9443/ws/btcusdt@ticker"));
            Assert.AreEqual(1M, asset1);
            Assert.AreEqual(10000M, asset2);
        }
Example #22
0
        public void Initialize_InvalidPair_ThrowsException()
        {
            var socketMock  = new Mock <IWebSocket>();
            var binanceMock = InitBinanceClientMock();

            var subject = new Binance(socketMock.Object, binanceMock.Object, Mock.Of <ITime>());

            var e = Expect.ThrowAsync <ArgumentException>(async() => {
                await subject.Initialize(Assets.BTC, Assets.DOGE);
            });

            Assert.AreEqual("Trading pair BTCDOGE is not available on Binance", e.Message);
        }
Example #23
0
        public void BinancePostOrders_ShouldReturnBinanceOrder()
        {
            //Arrange
            _httpMessageHandlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync",
                                                 ItExpr.Is <HttpRequestMessage>(x => x.RequestUri.AbsoluteUri.Contains("/api/v1/time")),
                                                 ItExpr.IsAny <CancellationToken>())
            .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(
                    @"{""serverTime"":1592395836992}")
            }))
            .Verifiable();
            _httpMessageHandlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync",
                                                 ItExpr.Is <HttpRequestMessage>(x => x.RequestUri.AbsoluteUri.Contains("/api/v3/order")),
                                                 ItExpr.IsAny <CancellationToken>())
            .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(
                    @"{""symbol"":""BNBBTC"",""orderId"":156,
                            ""orderListId"":-1,""clientOrderId"":""Ovu4oRzIuBmzR7YKnZjQDg"",
                            ""transactTime"":1594418218604,""price"":""0.00000000"",""origQty"":""0.10000000"",
                            ""executedQty"":""0.10000000"",""cummulativeQuoteQty"":""0.00016933"",
                            ""status"":""FILLED"",""timeInForce"":""GTC"",""type"":""MARKET"",
                            ""side"":""BUY"",""fills"":[{""price"":""0.00169330"",""qty"":""0.10000000"",
                            ""commission"":""0.00000000"",""commissionAsset"":""BNB"",""tradeId"":72}]}")
            }))
            .Verifiable();
            HttpClient httpClient = new HttpClient(_httpMessageHandlerMock.Object);

            _connectionAdapter.HttpClient = httpClient;
            Binance subjectUnderTest = new Binance();

            subjectUnderTest.ConnectionAdapter = _connectionAdapter;
            BinanceOrder binanceOrder = new BinanceOrder();

            binanceOrder.OrderType = OrderType.Market;
            binanceOrder.OrderSide = OrderSide.Buy;
            binanceOrder.OrderSize = (decimal)0.1;
            binanceOrder.Symbol    = "BNBBTC";
            //Act
            BinanceOrder binanceOrderResult = subjectUnderTest.PostOrdersAsync(binanceOrder).Result;

            //Assert
            Assert.IsNotNull(binanceOrderResult);
        }
Example #24
0
        public void Dispose_NotInitialized_CantDoStuff()
        {
            var socketMock = new Mock <IWebSocket>();
            var subject    = new Binance(socketMock.Object, Mock.Of <IBinanceClient>(), Mock.Of <ITime>());

            subject.Dispose();

            var e = Expect.ThrowAsync <InvalidOperationException>(async() => {
                await subject.GetCurrentPrice();
            });

            Assert.AreEqual("Binance cannot GetCurrentPrice until Initialized!", e.Message);
            socketMock.Verify(m => m.Dispose());
        }
Example #25
0
        public static async Task <string> GetUSDTPrice()
        {
            HttpResponseMessage responseUSDT = await client.GetAsync($"https://api.binance.com/api/v1/ticker/24hr?symbol=BTCUSDT");

            if (responseUSDT.IsSuccessStatusCode)
            {
                string jsonResult = await responseUSDT.Content.ReadAsStringAsync();

                Binance coin = JsonConvert.DeserializeObject <Binance>(jsonResult);
                return(coin.lastPrice);
            }

            return("0");
        }
Example #26
0
        public async void Candlestick_Online_Default()
        {
            var r = new Maybe <IDownloadData>();
            var b = new Binance(r);

            var res = await b.Candlestick(
                "ETHBTC",
                "1h",
                new Maybe <string>(),
                new Maybe <string>(),
                new Maybe <int>());

            Assert.NotNull(res);
        }
Example #27
0
        public void CancelOrder_ShouldReturnBinanceOrder()
        {
            //Arrange
            _httpMessageHandlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync",
                                                 ItExpr.Is <HttpRequestMessage>(x => x.RequestUri.AbsoluteUri.Contains("/api/v1/time")),
                                                 ItExpr.IsAny <CancellationToken>())
            .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(
                    @"{""serverTime"":1592395836992}")
            }))
            .Verifiable();
            _httpMessageHandlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync",
                                                 ItExpr.Is <HttpRequestMessage>(x => x.RequestUri.AbsoluteUri.Contains("/api/v3/order")),
                                                 ItExpr.IsAny <CancellationToken>())
            .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(
                    @"{""symbol"":""BNBBTC"",""origClientOrderId"":""IplSV4jLgOQVYO6o9UCeAv"",
                            ""orderId"":171,""orderListId"":-1,""clientOrderId"":""qpYlufBkQXlPI3bgSzHZE3"",
                            ""price"":""0.00100000"",""origQty"":""0.10000000"",""executedQty"":""0.00000000"",
                            ""cummulativeQuoteQty"":""0.00000000"",""status"":""CANCELED"",""timeInForce"":""GTC"",
                            ""type"":""LIMIT"",""side"":""BUY""}")
            }))
            .Verifiable();
            HttpClient httpClient = new HttpClient(_httpMessageHandlerMock.Object);

            _connectionAdapter.HttpClient = httpClient;
            Binance subjectUnderTest = new Binance();

            subjectUnderTest.ConnectionAdapter = _connectionAdapter;
            BinanceOrder binanceOrder = new BinanceOrder();

            binanceOrder.OrderType = OrderType.Market;
            binanceOrder.OrderSide = OrderSide.Buy;
            binanceOrder.OrderSize = (decimal)0.1;
            binanceOrder.Symbol    = "BNBBTC";
            //Act
            BinanceOrder binanceOrderResult = subjectUnderTest.CancelOrderAsync(binanceOrder).Result;

            //Assert
            Assert.IsNotNull(binanceOrderResult);
        }
Example #28
0
        public void TwentyFourHoursRollingStats_ShouldReturnStatistics()
        {
            //Arrange
            _httpMessageHandlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync",
                                                 ItExpr.Is <HttpRequestMessage>(x => x.RequestUri.AbsoluteUri.Contains("/api/v3/ticker/24hr")),
                                                 ItExpr.IsAny <CancellationToken>())
            .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(
                    @"{""symbol"": ""BNBBTC"",
                        ""priceChange"": ""-94.99999800"",
                        ""priceChangePercent"": ""-95.960"",
                        ""weightedAvgPrice"": ""0.29628482"",
                        ""prevClosePrice"": ""0.10002000"",
                        ""lastPrice"": ""4.00000200"",
                        ""lastQty"": ""200.00000000"",
                        ""bidPrice"": ""4.00000000"",
                        ""askPrice"": ""4.00000200"",
                        ""openPrice"": ""99.00000000"",
                        ""highPrice"": ""100.00000000"",
                        ""lowPrice"": ""0.10000000"",
                        ""volume"": ""8913.30000000"",
                        ""quoteVolume"": ""15.30000000"",
                        ""openTime"": 1499783499040,
                        ""closeTime"": 1499869899040,
                        ""firstId"": 28385,
                        ""lastId"": 28460,
                        ""count"": 76}")
            }))
            .Verifiable();
            HttpClient httpClient = new HttpClient(_httpMessageHandlerMock.Object);

            _connectionAdapter.HttpClient = httpClient;
            Binance subjectUnderTest = new Binance
            {
                ConnectionAdapter = _connectionAdapter
            };
            Product product = new Product {
                ID = "BNBBTC"
            };
            //Act
            Statistics statistics = subjectUnderTest.TwentyFourHoursRollingStatsAsync(product).Result;

            //Assert
            Assert.IsNotNull(statistics);
        }
Example #29
0
        public void Inicialize()
        {
            ChartBackground = new SolidColorBrush(Color.FromRgb(30, 30, 30));
            TickSize        = 0.01;
            BaseFontSize    = 18;
            FontBrush       = Brushes.White;
            LinesThickness  = 1;
            LinesBrush      = Brushes.DarkGray;

            Binance ex = new Binance();

            //ex.GeneralInfo();

            NewCandles = ex.GetCandles("ETH", "USDT", CandleIntervalKey.m15).Select(c => c).ToList();
        }
Example #30
0
        public void CheckOrder_NotInitialized_ThrowsException()
        {
            var binanceClient = new Mock <IBinanceClient>();
            var subject       = new Binance(Mock.Of <IWebSocket>(), binanceClient.Object, Mock.Of <ITime>());

            var e = Expect.ThrowAsync <InvalidOperationException>(async() =>
            {
                await subject.CheckOrder(new Order()
                {
                    Id = "123"
                });
            });

            Assert.AreEqual("Cannot CheckOrder until exchange has been Initialized", e.Message);
        }