Note
Cross-margin vs isolated margin trading
Binance offers both cross-margin trading (where all margin is in one account) and isolated margin trading (where each pair is a separate margin account). Make sure you are interacting with the right one.
Some of the API endpoints apply to the cross-margin or isolated margin accounts only. Other endpoints, such as the trade execution endpoints, are used for the cross-margin account trades by default, but you can use your isolated margin accounts by using the isIsolated or isolatedSymbol parameters. See the documentation below.
info = client.get_margin_asset(asset='BNB')info = client.get_margin_symbol(symbol='BTCUSDT')info = client.get_isolated_margin_symbol(symbol='BTCUSDT')info = client.get_all_isolated_margin_symbols()info = client.get_margin_price_index(symbol='BTCUSDT')By default, these trade execution endpoints will create an order using the cross-margin account.
To use the isolated margin account for the symbol you have specified, simply add the isIsolated='TRUE' parameter to the API calls below in this 'Orders' section.
Binance has a number of rules around symbol pair orders with validation on minimum price, quantity and total order value.
Read more about their specifics in the Filters section of the official API.
It can be helpful to format the output using the following snippet
amount = 0.000234234
precision = 5
amt_str = "{:0.0{}f}".format(amount, precision)orders = client.get_all_margin_orders(symbol='BNBBTC', limit=10)Use the create_margin_order function to have full control over creating an order
from binance.enums import *
order = client.create_margin_order(
symbol='BNBBTC',
side=SIDE_BUY,
type=ORDER_TYPE_LIMIT,
timeInForce=TIME_IN_FORCE_GTC,
quantity=100,
price='0.00001')order = client.get_margin_order(
symbol='BNBBTC',
orderId='orderId')result = client.cancel_margin_order(
symbol='BNBBTC',
orderId='orderId')orders = client.get_open_margin_orders(symbol='BNBBTC')For isolated margin, add the isIsolated='TRUE' parameter.
orders = client.get_all_margin_orders(symbol='BNBBTC')For isolated margin, add the isIsolated='TRUE' parameter.
info = client.get_margin_account()account = client.create_isolated_margin_account(base='BTC', quote='ETH')info = client.get_isolated_margin_account()transaction = client.transfer_spot_to_margin(asset='BTC', amount='1.1')transaction = client.transfer_margin_to_spot(asset='BTC', amount='1.1')transaction = client.transfer_spot_to_isolated_margin(asset='BTC',
symbol='ETHBTC', amount='1.1')transaction = client.transfer_isolated_margin_to_spot(asset='BTC',
symbol='ETHBTC', amount='1.1')details = client.get_max_margin_transfer(asset='BTC')This max transfer is for the cross-margin account by default. For isolated margin records, add the isolatedSymbol=symbol_name parameter.
trades = client.get_margin_trades(symbol='BNBBTC')For isolated margin trades, add the isIsolated='TRUE' parameter.
transaction = client.create_margin_loan(asset='BTC', amount='1.1')This for the cross-margin account by default. For isolated margin, add the isIsolated='TRUE' and the symbol=symbol_name parameters.
transaction = client.repay_margin_loan(asset='BTC', amount='1.1')This for the cross-margin account by default. For isolated margin, add the isIsolated='TRUE' and the symbol=symbol_name parameters.
details = client.get_margin_loan_details(asset='BTC', txId='100001')This for the cross-margin account by default. For isolated margin records, add the isolatedSymbol=symbol_name parameter.
details = client.get_margin_repay_details(asset='BTC', txId='100001')This for the cross-margin account by default. For isolated margin records, add the isolatedSymbol=symbol_name parameter.
details = client.get_max_margin_loan(asset='BTC')The max loan is for the cross-margin account by default. For isolated margin records, add the isolatedSymbol=symbol_name parameter.