Skip to main content

Python Library for Binance DEX, including API, Websocket, JSONRPC and Crypto

Project description

Binance DEX / Binance Chain Python Package


This Python package develop based on Binance Chain official doc and tested all functionalities on test-net as well as main-net.

Dex Links:

According to official doc, ways to connect to Binance DEX are:

  • CLI
  • Web Socket
  • Node RPC

This python package will provide all methods available as from binance official document except cli:

  • CLI
  • WebSocket
  • Node NRPC


Due to time limitation, we didn't test different python version + os environment combinations, below are what we tested so far:

  • Python3.5 + MacOs
  • Python3.5 + Windows10

we are not sure if there would be any compatibility issues for python2.7, let us know if you encounter any issue.

BTW, we do suggest to use Virtual Environment.

Python SDK Sample Usage:

Install package:

pip install binance-dex
  • Notes: If you are working on Windows platform, compiling tools Microsoft Visual C++ 14.0 is required.

Full Code Example

Find full Sample Usage from

Code Examples Sector by Sector

- API Sample Usage

from binance_dex.api import BinanceChainClient

# create API Client instance
api_client = BinanceChainClient(is_test_net=True)

# call corresponding methods

Sample return:

{'status': True, 'result': {'ap_time': '2019-04-06T04:43:48Z', 'block_time': '2019-04-06T04:43:47Z'}}

++Find more API information by clicking this link++

- Crypto Sample Usage

from binance_dex.crypto import BinanceChainCrypto

# Create crypto instance
crypto_instance = BinanceChainCrypto(is_test_net=True)

# Generate Mnemonic words
mnemonic_words = crypto_instance.generate_mnemonic()
print("Generating Mnemonic Words: ")

# Generate Private Key, Public Address and mnemonic
key = crypto_instance.generate_key()
print('Generating Private Key / Public Key / Mnemonic words: ')

Sample return:

Generating Mnemonic Words: 
early solid bronze civil version orange prize curve glory cricket ticket already weekend home early buyer zebra olive melody enrich park jeans apart tower

Generating Private Key / Public Key / Mnemonic words: 
{'private_key': '65dba225a6965020ff7aae6efc8b9494cbf52bea36e44341d471a7b4b8207e1a', 'public_address': 'tbnb1uvjsrw2pstxqwk45n8k6ke53yw8fsegjery2en', 'mnemonic': 'allow adult frown ivory coffee inhale calm assist galaxy indoor credit oyster tower exclude popular veteran first hint flag boost right zone clown flower'}

++Find more Crypto information by clicking this link++

- Socket Sample Usage

from binance_dex.sockets import BinanceChainSocket

# --- Notice: Need to provide customized Call Back function to handle socket return data ---

# Sample of Customized Callback function to handle received data
def customized_call_back(ws, received_message):
    ''' Simply print out '''
    print('----- Customized handler -----')

# Create Socket Instance
socket_instance = BinanceChainSocket(IS_TEST_NET)

# 24hr Ticker statistics for a single symbol, push every second
                                     one_off=False, # long lived connection

Sample return:

----- Customized handler -----

----- Customized handler -----

----- Customized handler -----

++Find more Web Socket Doc by clicking this link++

- Node RPC Sample Usage

from binance_dex.node_rpc import BinanceChainNodeRPC

# Create Instance

# OPTION 1: using existing RPC node
node_rpc_instance = BinanceChainNodeRPC(is_test_net=True,

# OPTION 2: using your own node
# node_rpc_instance = BinanceChainNodeRPC(node_rpc_url='')

# Get number of unconfirmed transactions

Sample return

Using Existing RPC server, trying to find a healthy node server...

Request URL: ... ...

Successfully found healthy node RPC server:

Request URL: ... ...
{'status': True, 'result': {'jsonrpc': '2.0', 'id': '', 'result': {'n_txs': '0', 'txs': None}}}

++Find more Node RPC Doc by clicking this link++

SDK Overview

As you might noticed from above code sample, this SDK is composed with 4 parts:

  • API
  • WebSockets
  • Node RPC
  • Crypto


  • API: HTTP API provides access to a Binance Chain node deployment and market data services DETAILED API DOC

  • Web Sockets: The DEX exposes several data streams over standard WebSocket connections, which can be consumed by modern web browsers and server-side WebSocket libraries DETAILED SOCKET DOC

  • Node RPC: May be used to interact with a node directly over HTTP or websockets. Using RPC, you may perform low-level operations like executing ABCI queries, viewing network/consensus state or broadcasting a transaction DETAILED NODE DOC

  • Crypto: Crypto related functions (such as key managment) DETAILED CRYPTO DOC


API WebSockets Node RPC Crypto
Key generate mnemonic
generate key
generate keys
Chain get block height
get block info
get consensue info
get network info
get unconfirmed tx
get Tendermint status
Node get block time
get node info
get validators
get peers
get end points
get abci info
Market get listing tokens
get trading pairs
get depth
get klines
get updated ticker statistics
Account get account balance
get account sequence
get account orders
Transaction get transaction info
broadcast transaction
Others view chain fees

Network requirement:

API WebSockets JSONRPC Crypto
Requir Network X

Join us:

You are always welcomed to join us! Leave your suggestions / or submit your codes


We promise will stick to MIT license permanently.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

binance_dex-0.1.3.tar.gz (41.3 kB view hashes)

Uploaded source

Built Distribution

binance_dex-0.1.3-py3-none-any.whl (42.1 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page