binance / binance-futures-connector-python

Simple python connector to Binance Futures API
MIT License
848 stars 231 forks source link

Placing market order by USDT (not quantity) #162

Closed dontpnc closed 6 months ago

dontpnc commented 10 months ago

Hello,

How do i change "quantity=0.01" to use USDT instead.. for example Market sell BTCUSDT with 1000 USDT.

Here is code i'm using

import logging from binance.um_futures import UMFutures from binance.lib.utils import config_logging from binance.error import ClientError

config_logging(logging, logging.DEBUG)

key = "" secret = "" testnet_url = "https://testnet.binancefuture.com"

Set the testnet URL when creating the UMFutures instance um_futures_client = UMFutures(key=key, secret=secret) um_futures_client.base_url = testnet_url

try: response = um_futures_client.new_order( symbol="BTCUSDT", side="SELL", type="MARKET", # Set type to "MARKET" for a market order quantity=0.01 ) logging.info(response) except ClientError as error: logging.error( "Found error. status: {}, error code: {}, error message: {}".format( error.status_code, error.error_code, error.error_message ) )

aisling-2 commented 6 months ago

That's known as quote quantity, which is unfortunately not available to send as input directly, although you could look into this workaround: https://dev.binance.vision/t/creating-market-order-with-underlying-currency-amount-instead-of-quantity-quoteorderqty-futures-api/10117