|
| 1 | +Margin Trading Endpoints |
| 2 | +======================== |
| 3 | + |
| 4 | +Market Data |
| 5 | +----------- |
| 6 | + |
| 7 | +`Get margin asset info <binance.html#binance.client.Client.get_margin_asset>`_ |
| 8 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 9 | + |
| 10 | +.. code:: python |
| 11 | +
|
| 12 | + info = client.get_margin_asset(asset='BNB') |
| 13 | +
|
| 14 | +`Get margin symbol info <binance.html#binance.client.Client.get_margin_symbol>`_ |
| 15 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 16 | + |
| 17 | +.. code:: python |
| 18 | +
|
| 19 | + info = client.get_margin_symbol(symbol='BTCUSDT') |
| 20 | +
|
| 21 | +`Get margin price index <binance.html#binance.client.Client.get_margin_price_index>`_ |
| 22 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 23 | + |
| 24 | +.. code:: python |
| 25 | +
|
| 26 | + info = client.get_margin_price_index(symbol='BTCUSDT') |
| 27 | +
|
| 28 | +Orders |
| 29 | +------ |
| 30 | + |
| 31 | +Order Validation |
| 32 | +^^^^^^^^^^^^^^^^ |
| 33 | + |
| 34 | +Binance has a number of rules around symbol pair orders with validation on minimum price, quantity and total order value. |
| 35 | + |
| 36 | +Read more about their specifics in the `Filters <https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#filters>`_ |
| 37 | +section of the official API. |
| 38 | + |
| 39 | +It can be helpful to format the output using the following snippet |
| 40 | + |
| 41 | +.. code:: python |
| 42 | +
|
| 43 | + amount = 0.000234234 |
| 44 | + precision = 5 |
| 45 | + amt_str = "{:0.0{}f}".format(amount, precision) |
| 46 | +
|
| 47 | +
|
| 48 | +`Fetch all margin_orders <binance.html#binance.client.Client.get_all_margin_orders>`_ |
| 49 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 50 | + |
| 51 | +.. code:: python |
| 52 | +
|
| 53 | + orders = client.get_all_margin_orders(symbol='BNBBTC', limit=10) |
| 54 | +
|
| 55 | +
|
| 56 | +`Place a margin order <binance.html#binance.client.Client.create_margin_order>`_ |
| 57 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 58 | + |
| 59 | +**Place an order** |
| 60 | + |
| 61 | +Use the `create_margin_order` function to have full control over creating an order |
| 62 | + |
| 63 | +.. code:: python |
| 64 | +
|
| 65 | + from binance.enums import * |
| 66 | + order = client.create_margin_order( |
| 67 | + symbol='BNBBTC', |
| 68 | + side=SIDE_BUY, |
| 69 | + type=ORDER_TYPE_LIMIT, |
| 70 | + timeInForce=TIME_IN_FORCE_GTC, |
| 71 | + quantity=100, |
| 72 | + price='0.00001') |
| 73 | +
|
| 74 | +
|
| 75 | +`Check order status <binance.html#binance.client.Client.get_margin_order>`_ |
| 76 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 77 | + |
| 78 | +.. code:: python |
| 79 | +
|
| 80 | + order = client.get_margin_order( |
| 81 | + symbol='BNBBTC', |
| 82 | + orderId='orderId') |
| 83 | +
|
| 84 | +
|
| 85 | +`Cancel a margin order <binance.html#binance.client.Client.cancel_margin_order>`_ |
| 86 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 87 | + |
| 88 | +.. code:: python |
| 89 | +
|
| 90 | + result = client.cancel_margin_order( |
| 91 | + symbol='BNBBTC', |
| 92 | + orderId='orderId') |
| 93 | +
|
| 94 | +
|
| 95 | +`Get all open margin orders <binance.html#binance.client.Client.get_open_margin_orders>`_ |
| 96 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 97 | + |
| 98 | +.. code:: python |
| 99 | +
|
| 100 | + orders = client.get_open_margin_orders(symbol='BNBBTC') |
| 101 | +
|
| 102 | +`Get all margin orders <binance.html#binance.client.Client.get_all_margin_orders>`_ |
| 103 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 104 | + |
| 105 | +.. code:: python |
| 106 | +
|
| 107 | + orders = client.get_all_margin_orders(symbol='BNBBTC') |
| 108 | +
|
| 109 | +
|
| 110 | +Account |
| 111 | +------- |
| 112 | + |
| 113 | +`Get margin account info <binance.html#binance.client.Client.get_margin_account>`_ |
| 114 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 115 | + |
| 116 | +.. code:: python |
| 117 | +
|
| 118 | + info = client.get_margin_account() |
| 119 | +
|
| 120 | +`Transfer spot to margin <binance.html#binance.client.Client.transfer_spot_to_margin>`_ |
| 121 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 122 | + |
| 123 | +.. code:: python |
| 124 | +
|
| 125 | + transaction = client.transfer_spot_to_margin(asset='BTC', amount='1.1') |
| 126 | +
|
| 127 | +`Transfer margin to spot <binance.html#binance.client.Client.transfer_margin_to_spot>`_ |
| 128 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 129 | + |
| 130 | +.. code:: python |
| 131 | +
|
| 132 | + transaction = client.transfer_margin_to_spot(asset='BTC', amount='1.1') |
| 133 | +
|
| 134 | +`Get max transfer amount <binance.html#binance.client.Client.get_max_margin_transfer>`_ |
| 135 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 136 | + |
| 137 | +.. code:: python |
| 138 | +
|
| 139 | + details = client.get_max_margin_transfer(asset='BTC') |
| 140 | +
|
| 141 | +
|
| 142 | +Trades |
| 143 | +----- |
| 144 | + |
| 145 | +`Get all margin trades <binance.html#binance.client.Client.get_margin_trades>`_ |
| 146 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 147 | + |
| 148 | +.. code:: python |
| 149 | +
|
| 150 | + trades = client.get_margin_trades(symbol='BNBBTC') |
| 151 | +
|
| 152 | +Loans |
| 153 | +----- |
| 154 | + |
| 155 | + |
| 156 | +`Create loan <binance.html#binance.client.Client.create_margin_loan>`_ |
| 157 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 158 | + |
| 159 | +.. code:: python |
| 160 | +
|
| 161 | + transaction = client.create_margin_loan(asset='BTC', amount='1.1') |
| 162 | +
|
| 163 | +`Repay loan <binance.html#binance.client.Client.repay_margin_loan>`_ |
| 164 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 165 | + |
| 166 | +.. code:: python |
| 167 | +
|
| 168 | + transaction = client.repay_margin_loan(asset='BTC', amount='1.1') |
| 169 | +
|
| 170 | +`Get loan details <binance.html#binance.client.Client.get_margin_loan_details>`_ |
| 171 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 172 | + |
| 173 | +.. code:: python |
| 174 | +
|
| 175 | + details = client.get_margin_loan_details(asset='BTC', txId='100001') |
| 176 | +
|
| 177 | +`Get repay details <binance.html#binance.client.Client.get_margin_repay_details>`_ |
| 178 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 179 | + |
| 180 | +.. code:: python |
| 181 | +
|
| 182 | + details = client.get_margin_repay_details(asset='BTC', txId='100001') |
| 183 | +
|
| 184 | +`Get max loan amount <binance.html#binance.client.Client.get_max_margin_loan>`_ |
| 185 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 186 | + |
| 187 | +.. code:: python |
| 188 | +
|
| 189 | + details = client.get_max_margin_loan(asset='BTC') |
0 commit comments