Skip to content

Latest commit

 

History

History
189 lines (111 loc) · 5.53 KB

margin.rst

File metadata and controls

189 lines (111 loc) · 5.53 KB

Margin Trading Endpoints

Market Data

info = client.get_margin_asset(asset='BNB')
info = client.get_margin_symbol(symbol='BTCUSDT')
info = client.get_margin_price_index(symbol='BTCUSDT')

Orders

Order Validation

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)

Place an order

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')
orders = client.get_all_margin_orders(symbol='BNBBTC')

Account

info = client.get_margin_account()
transaction = client.transfer_spot_to_margin(asset='BTC', amount='1.1')
transaction = client.transfer_margin_to_spot(asset='BTC', amount='1.1')
details = client.get_max_margin_transfer(asset='BTC')

Trades

trades = client.get_margin_trades(symbol='BNBBTC')

Loans

transaction = client.create_margin_loan(asset='BTC', amount='1.1')
transaction = client.repay_margin_loan(asset='BTC', amount='1.1')
details = client.get_margin_loan_details(asset='BTC', txId='100001')
details = client.get_margin_repay_details(asset='BTC', txId='100001')
details = client.get_max_margin_loan(asset='BTC')