Ejemplo n.º 1
0
 def get_mid_price_orderbooks(self, products=None):
     prices_list = self.client.get_all_tickers()
     orderbooks = []
     for price_symbol in prices_list:
         currency_pair = binance_product_to_currencies(
             price_symbol['symbol'])
         product = '_'.join(currency_pair)
         if products is not None and product not in products:
             continue
         orderbook = OrderBook(product, Decimal(price_symbol['price']))
         if orderbook.get_wall_ask() <= Decimal('1e-8'):
             continue
         orderbooks.append(orderbook)
     return orderbooks
Ejemplo n.º 2
0
 def test_binance_product_to_currencies(self):
     gdax_products = [
         'BTC_USDT', 'ETH_USDT', 'ETH_BTC', 'LTC_BTC', 'ADA_BNB', 'ADA_BTC',
         'TUSD_USDT', 'VET_ETH', 'EOS_ETH'
     ]
     currency_pairs = [p.split('_') for p in gdax_products]
     binance_products = [''.join(p) for p in currency_pairs]
     binance_currency_pairs = [
         binance_product_to_currencies(p) for p in binance_products
     ]
     for real_pair, derived_pair in zip(currency_pairs,
                                        binance_currency_pairs):
         self.assertEqual(len(derived_pair), 2)
         self.assertEqual(real_pair[0], derived_pair[0])
         self.assertEqual(real_pair[1], derived_pair[1])
Ejemplo n.º 3
0
    def place_market_order(self, order, price_estimates):
        """
        place market order
        uses price estimates to check min notional and resources for buy orders
        returns dict with keys
        {'orderId', 'clientOrderId', 'executed_quantity', 'mean_price'}
        with corresponding values

        also returns commission_asset: fee
        for example
        {
            "orderId": 28,
            "clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
            "executed_quantity": Decimal("10.00000000"),
            "mean_price": Decimal("3998.30000000"),
            "commission_USDT": Decimal("19.99150000"),
            "commission_BNB": Decimal("11.66365227")
        }
        """
        logger.info("creating market order - {}".format(str(order)))
        order = self._validate_order(order, price_estimates)
        logger.info("validated order - {}".format(str(order)))
        if order is None:
            return
        symbol = ''.join(order.product.split('_'))
        side = order._action.name
        quantity = order._quantity
        newOrderRespType = 'FULL'
        try:
            resp = self.client.order_market(side=side,
                                            symbol=symbol,
                                            quantity=quantity,
                                            newOrderRespType=newOrderRespType)
        except BinanceAPIException as e:
            return e

        parsed_response = self.parse_market_order_response(resp)
        parsed_response['price_estimates'] = price_estimates
        parsed_response['product'] = '_'.join(
            binance_product_to_currencies(parsed_response['symbol']))
        logger.info("parsed order response - {}".format(str(parsed_response)))
        return parsed_response
Ejemplo n.º 4
0
 def get_orderbooks_of_depth1(self, products):
     """
     get all orderbooks with depth equal to 1, then filter out those,
     which symbol is not in specified products
     """
     books_list = self.client.get_orderbook_tickers()
     orderbooks = []
     for book in books_list:
         currency_pair = binance_product_to_currencies(book['symbol'])
         product = '_'.join(currency_pair)
         if products is not None and product not in products:
             continue
         orderbook = OrderBook(product, {
             'ask': Decimal(book['askPrice']),
             'bid': Decimal(book['bidPrice'])
         })
         if orderbook.get_wall_ask() <= Decimal('1e-8'):
             continue
         orderbooks.append(orderbook)
     return orderbooks