Skip to content

Commit

Permalink
Add margin docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam McHardy committed Aug 1, 2019
1 parent ecc7460 commit f0d5a8b
Show file tree
Hide file tree
Showing 2 changed files with 190 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Contents
general
market_data
account
margin
websockets
depth_cache
withdraw
Expand Down
189 changes: 189 additions & 0 deletions docs/margin.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
Margin Trading Endpoints
========================

Market Data
-----------

`Get margin asset info <binance.html#binance.client.Client.get_margin_asset>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
info = client.get_margin_asset(asset='BNB')
`Get margin symbol info <binance.html#binance.client.Client.get_margin_symbol>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
info = client.get_margin_symbol(symbol='BTCUSDT')
`Get margin price index <binance.html#binance.client.Client.get_margin_price_index>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
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 <https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#filters>`_
section of the official API.

It can be helpful to format the output using the following snippet

.. code:: python
amount = 0.000234234
precision = 5
amt_str = "{:0.0{}f}".format(amount, precision)
`Fetch all margin_orders <binance.html#binance.client.Client.get_all_margin_orders>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
orders = client.get_all_margin_orders(symbol='BNBBTC', limit=10)
`Place a margin order <binance.html#binance.client.Client.create_margin_order>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

**Place an order**

Use the `create_margin_order` function to have full control over creating an order

.. code:: python
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')
`Check order status <binance.html#binance.client.Client.get_margin_order>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
order = client.get_margin_order(
symbol='BNBBTC',
orderId='orderId')
`Cancel a margin order <binance.html#binance.client.Client.cancel_margin_order>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
result = client.cancel_margin_order(
symbol='BNBBTC',
orderId='orderId')
`Get all open margin orders <binance.html#binance.client.Client.get_open_margin_orders>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
orders = client.get_open_margin_orders(symbol='BNBBTC')
`Get all margin orders <binance.html#binance.client.Client.get_all_margin_orders>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
orders = client.get_all_margin_orders(symbol='BNBBTC')
Account
-------

`Get margin account info <binance.html#binance.client.Client.get_margin_account>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
info = client.get_margin_account()
`Transfer spot to margin <binance.html#binance.client.Client.transfer_spot_to_margin>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
transaction = client.transfer_spot_to_margin(asset='BTC', amount='1.1')
`Transfer margin to spot <binance.html#binance.client.Client.transfer_margin_to_spot>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
transaction = client.transfer_margin_to_spot(asset='BTC', amount='1.1')
`Get max transfer amount <binance.html#binance.client.Client.get_max_margin_transfer>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
details = client.get_max_margin_transfer(asset='BTC')
Trades
-----

`Get all margin trades <binance.html#binance.client.Client.get_margin_trades>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
trades = client.get_margin_trades(symbol='BNBBTC')
Loans
-----


`Create loan <binance.html#binance.client.Client.create_margin_loan>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
transaction = client.create_margin_loan(asset='BTC', amount='1.1')
`Repay loan <binance.html#binance.client.Client.repay_margin_loan>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
transaction = client.repay_margin_loan(asset='BTC', amount='1.1')
`Get loan details <binance.html#binance.client.Client.get_margin_loan_details>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
details = client.get_margin_loan_details(asset='BTC', txId='100001')
`Get repay details <binance.html#binance.client.Client.get_margin_repay_details>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
details = client.get_margin_repay_details(asset='BTC', txId='100001')
`Get max loan amount <binance.html#binance.client.Client.get_max_margin_loan>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
details = client.get_max_margin_loan(asset='BTC')

0 comments on commit f0d5a8b

Please sign in to comment.