Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def private_api():

    client = BinanceAPI(API_KEY, API_SECRET)
    # or
    # client = BinanceAPI()
    # client.set_api(API_KEY, API_SECRET)

    print(client.openOrders('KNCETH'))

    print(client.allOrders('KNCETH'))

    print(client.account())

    print(client.myTrades('KNCETH'))

    print(client.newLimitBuyOrder('BTCUSDT', quantity=1.0, price=5203.0))

    print(client.queryOrder('BNBETH', orderId=387643))

    print(client.deleteOrder('BNBETH', orderId=387643))