class TestBinanceApiEndPoints(unittest.TestCase): def setUp(self): self.client = BinanceAPI(API_KEY,API_SECRET) def test_a_get_current_server_time(self): """ Test that we can get the current time. """ time = self.client.time() self.assertTrue(time.get("serverTime", None) is not None) logger.info("Able to get current server time.") def test_b_get_all_prices(self): """ Test that we can get all prices """ prices = self.client.allPrices() self.assertTrue(len(prices) > 0) logger.info("We got prices.") for each in prices: # assert we have {"symbol" : "<symbol>", "price":<price>}. self.assertTrue("price" in each and "symbol" in each) # assert that each price can be of float type / for calculations. self.assertTrue(isinstance(float(each["price"]), float)) logger.info("We can get all prices listed with this endpoint.") def test_c_get_all_orders(self): """ Test that the we get an exception if there are no orders for given <symbol> """ with self.assertRaises(excepts.MalformedRequest): self.client.allOrders('ETHBTC') logger.info("We have no orders from ETHBTC so the API raises MalformedRequest.") def test_d_get_time_stats(self): pass
def public_api(): client = BinanceAPI() print(client.ping()) print(client.time()) print(client.depth('BTCUSDT', limit=10)) print(client.aggTrades('ETHBTC')) print(client.klines('BNBBTC', '1h', limit=10)) print(client.stats24hr('ETHUSDT')) print(client.allPrices()) print(client.allBookTickers())