Skip to content

Latest commit

 

History

History
188 lines (163 loc) · 4.85 KB

BinanceDEX.md

File metadata and controls

188 lines (163 loc) · 4.85 KB
Binance DEX

Binance DEX API Wrapper

Python 3.7+

PEP8

Async support (without cache)

Handles configurable requests cache, retries and general request errors.

Supports the latest API version: https://binance-chain.github.io/api-reference/dex-api/paths.html


Installation:

pip install xnr-cryptowrapper

Functions:

Build around raw API commands, each endpoint is made directly available.
Currently supported endpoints, functions:

  • Binance Chain HTTP API
    • time_GET
    • node_info_GET
    • validators_GET
    • peers_GET
    • account_GET
    • account_sequence_GET
    • transaction_GET
    • tokens_GET
    • markets_GET
    • fees_GET
    • depth_GET
    • broadcast_POST
    • klines_GET
    • orders_closed_GET
    • orders_open_GET
    • orders_id_GET
    • ticker_24h_GET
    • trades_GET
    • block_exchange_fee_GET
    • transactions_GET
    • transactions_in_block_GET

Examples:

If unspecified, result will not be cached.
Retries avoided for errors (400, 401, 403, 404, 429, 500).

BinanceDEX.time_GET() (+ cache example)

>>> from cryptowrapper import BinanceDEX
>>> binance_dex = BinanceDEX()
>>> binance_dex.time_GET()
{
    'ap_time': '2019-02-20T13:17:46Z',
    'block_time': '2019-02-20T13:17:46Z',
    'cached': False
}
>>> binance_dex.time_GET()
{
    'ap_time': '2019-02-20T13:17:46Z',
    'block_time': '2019-02-20T13:17:46Z',
    'cached': True
}

BinanceDEX.account_GET()

>>> from cryptowrapper import BinanceDEX
>>> binance_dex = BinanceDEX()
>>> address = "tbnb138u9djee6fwphhd2a3628q2h0j5w97yx48zqex"
>>> binance_dex.account_GET(address=address)
{
    'address': 'tbnb138u9djee6fwphhd2a3628q2h0j5w97yx48zqex',
    'public_key': [
        3, 138, 189, 229, 225, 39, 225, 196, 117, 109, 188,
        85, 70, 166, 28, 242, 150, 203, 188, 166, 50, 104,
        204, 99, 205, 164, 210, 154, 68, 201, 65, 74, 250
    ],
    'account_number': 71,
    'sequence': 438,
    'balances': [
        {
            'symbol': 'ADA.B-F2F',
            'free': '1.00000000',
            'locked': '0.00000000',
            'frozen': '0.00000000'
        },
        {
            'symbol': 'BNB',
            'free': '865993.19135384',
            'locked': '0.31243490',
            'frozen': '0.00000000'
        },
        {
            'symbol': 'EOS.B-5A7',
            'free': '1.00000000',
            'locked': '0.00000000',
            'frozen': '0.00000000'
        },
        {
            'symbol': 'XMR.B-B3D',
            'free': '1.00000000',
            'locked': '0.00000000',
            'frozen': '0.00000000'
        }
    ],
    'cached': False
}

BinanceDEX.orderbook_GET()

>>> from cryptowrapper import BinanceDEX
>>> binance_dex = BinanceDEX()
>>> symbol = "TUSD.B-241_BNB"
>>> binance_dex.orderbook_GET(symbol=symbol)
{
    'asks': [
        ['0.09570700', '69.58000000'],
        ['0.09949000', '159.45000000'],
        ['0.10723300', '366.71000000'],
        ['0.11118700', '218.98000000'],
        ['0.11407700', '348.97000000'],
        ['0.11605400', '263.11000000'],
        ['0.11855900', '326.03000000'],
        ['0.12292500', '396.11000000'],
        ['0.12477600', '426.55000000'],
        ['0.12528100', '505.55000000'],
        ['0.13051900', '784.53000000'],
        ['0.13382300', '731.65000000'],
        ['0.13613900', '962.12000000'],
        ['0.14084700', '600.33000000'],
        ['0.14382500', '990.51000000'],
        ['0.14687100', '1022.68000000']
    ],
    'bids': [
        ['0.09458800', '870.10000000'],
        ['0.08800000', '1727.32000000'],
        ['0.08717200', '654.80000000'],
        ['0.08653500', '119.11000000'],
        ['0.08501800', '229.28000000'],
        ['0.08238900', '164.54000000'],
        ['0.08031200', '308.05000000'],
        ['0.07673600', '200.20000000'],
        ['0.07500000', '1348.41000000'],
        ['0.07499600', '214.31000000'],
        ['0.07211600', '250.10000000'],
        ['0.06948300', '377.67000000'],
        ['0.06652300', '338.49000000'],
        ['0.06452300', '698.88000000'],
        ['0.06188600', '376.60000000'],
        ['0.05876400', '170.02000000'],
        ['0.05620800', '410.99000000'],
        ['0.05428300', '519.89000000'],
        ['0.05271500', '391.31000000'],
        ['0.00442400', '1.00000000']
    ],
    'height': 1465179,
    'cached': False
}

For a quick combined example see: example.py
For the async version see: async_example.py


Feedback:

Constructive feedback & bug reports are welcome.
Contact informations: