Example #1
0
        public void When_ApiReturnsWalletData_Expect_WalletWithSameData(
            string walletType, string currency, double balance, double unsettledInterest, double?balanceAvailable)
        {
            // arrange
            var responseJson = string.Format("[[\"{0}\",\"{1}\",{2},{3},{4}]]",
                                             walletType,
                                             currency,
                                             balance.ToString(CultureInfo.InvariantCulture),
                                             unsettledInterest.ToString(CultureInfo.InvariantCulture),
                                             balanceAvailable?.ToString(CultureInfo.InvariantCulture) ?? "null");

            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When($"*{Endpoints.Wallets}")
            .Respond(MediaTypes.ApplicationJson, responseJson);

            // act
            var bfClient = new BitfinexApiClient(Config.ApiKey, Config.SecretKey, new HttpClient(mockHttp));
            var wallets  = bfClient.GetWalletsAsync().Result;
            var wallet   = wallets.FirstOrDefault(w => w.Currency.Equals(currency));

            // assert
            Assert.IsNotNull(wallet);
            Assert.AreEqual(wallet.WalletType, walletType);
            Assert.AreEqual(wallet.Currency, currency);
            Assert.AreEqual(wallet.Balance, balance);
            Assert.AreEqual(wallet.UnsettledInterest, unsettledInterest);
            Assert.AreEqual(wallet.BalanceAvailable, balanceAvailable);
        }
        public void When_ApiNotReachable_Expect_AggregateException()
        {
            // arrange
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When($"*{Endpoints.PlatformStatus}")
            .Respond(new ExceptionThrowingContent(
                         new HttpRequestException("An error occured while sending the request.")));

            // act
            var bfClient       = new BitfinexApiClient(Config.ApiKey, Config.SecretKey, new HttpClient(mockHttp));
            var platformStatus = bfClient.GetPlatformStatusAsync().Result;
        }
        public void When_ApiReturnsNoValue_PlatformStatusIsNull()
        {
            // arrange
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When($"*{Endpoints.PlatformStatus}")
            .Respond(MediaTypes.ApplicationJson, "[]");

            // act
            var bfClient       = new BitfinexApiClient(Config.ApiKey, Config.SecretKey, new HttpClient(mockHttp));
            var platformStatus = bfClient.GetPlatformStatusAsync().Result;

            // assert
            Assert.IsNull(platformStatus);
        }
        public void When_ApiReturnsPlatformNotWorking_OperativeEqualsZero()
        {
            // arrange
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When($"*{Endpoints.PlatformStatus}")
            .Respond(MediaTypes.ApplicationJson, "[0]");

            // act
            var bfClient       = new BitfinexApiClient(Config.ApiKey, Config.SecretKey, new HttpClient(mockHttp));
            var platformStatus = bfClient.GetPlatformStatusAsync().Result;

            // assert
            Assert.AreEqual(platformStatus.Operative, 0);
        }
Example #5
0
        public void When_ApiReturnsNWallets_WalletsListContainsNWallets(string responseJson, int walletCount)
        {
            // arrange
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When($"*{Endpoints.Wallets}")
            .Respond(MediaTypes.ApplicationJson, responseJson);

            // act
            var bfClient = new BitfinexApiClient(Config.ApiKey, Config.SecretKey, new HttpClient(mockHttp));
            var wallets  = bfClient.GetWalletsAsync().Result;

            // assert
            Assert.AreEqual(wallets.Count, walletCount);
        }
        static void Main(string[] args)
        {
            BitfinexApiClient bfRestClient = new BitfinexApiClient(Config.ApiKey, Config.SecretKey, new HttpClient());

            var platformStatus = bfRestClient.GetPlatformStatusAsync().Result;

            Console.WriteLine($"API State (1=up / 0=down): {platformStatus.Operative}");

            var alerts = bfRestClient.GetAlertsAsync().Result;

            Console.WriteLine("Alerts:");
            alerts.ForEach(alert => Console.WriteLine(alert.ToString()));

            var wallets = bfRestClient.GetWalletsAsync().Result;

            Console.WriteLine("Wallets:");
            wallets.ForEach(wallet => Console.WriteLine(wallet.ToString()));

            Console.ReadLine();
        }
Example #7
0
        public void When_ApiReturnsAlertAsJson_Expect_AlertWithSameData(string responseJson, string id, string type, string symbol, double price, int unknown)
        {
            // arrange
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When($"*{Endpoints.Alerts}")
            .Respond(MediaTypes.ApplicationJson, responseJson);

            // act
            var bfClient = new BitfinexApiClient(Config.ApiKey, Config.SecretKey, new HttpClient(mockHttp));
            var alerts   = bfClient.GetAlertsAsync().Result;
            var alert    = alerts.FirstOrDefault();

            // assert
            Assert.IsNotNull(alert);
            Assert.AreEqual(alert.Id, id);
            Assert.AreEqual(alert.Type, type);
            Assert.AreEqual(alert.Symbol, symbol);
            Assert.AreEqual(alert.Price, price);
            Assert.AreEqual(alert.Unknown, unknown);
        }