{"id":16740341,"url":"https://github.com/lmacken/binance-chain-python","last_synced_at":"2025-03-21T22:31:33.799Z","repository":{"id":57415051,"uuid":"181519156","full_name":"lmacken/binance-chain-python","owner":"lmacken","description":"Binance chain SDK in Python","archived":false,"fork":false,"pushed_at":"2019-05-01T06:00:35.000Z","size":215,"stargazers_count":24,"open_issues_count":3,"forks_count":6,"subscribers_count":7,"default_branch":"develop","last_synced_at":"2025-03-15T05:47:11.205Z","etag":null,"topics":["aiohttp","asyncio","binance","binancechain","blockchain","bnb","crypto","dex","python","trading","wallet"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lmacken.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-15T15:50:50.000Z","updated_at":"2024-01-04T21:06:39.000Z","dependencies_parsed_at":"2022-09-01T16:40:46.837Z","dependency_job_id":null,"html_url":"https://github.com/lmacken/binance-chain-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmacken%2Fbinance-chain-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmacken%2Fbinance-chain-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmacken%2Fbinance-chain-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmacken%2Fbinance-chain-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lmacken","download_url":"https://codeload.github.com/lmacken/binance-chain-python/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244880211,"owners_count":20525505,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aiohttp","asyncio","binance","binancechain","blockchain","bnb","crypto","dex","python","trading","wallet"],"created_at":"2024-10-13T00:57:50.077Z","updated_at":"2025-03-21T22:31:33.498Z","avatar_url":"https://github.com/lmacken.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# binance-chain-python\n\n[![Build Status](https://travis-ci.org/lmacken/binance-chain-python.svg?branch=master\u0026color=green)](https://travis-ci.org/lmacken/binance-chain-python)\n[![Coverage Status](https://coveralls.io/repos/github/lmacken/binance-chain-python/badge.svg)](https://coveralls.io/github/lmacken/binance-chain-python)\n![GitHub](https://img.shields.io/github/license/lmacken/binance-chain-python.svg)\n![PyPI](https://img.shields.io/pypi/v/binancechain.svg)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/binancechain.svg)\n\nAn unofficial asyncio Python API for the Binance Chain.\n\n## Installation\n\n    pip install binancechain\n\n## Implementation Details\n\n- [Extensive test suite](https://github.com/lmacken/binance-chain-python/tree/master/test)\n- Optional rate limiter with the `HTTPClient(rate_limit=True)`, which uses a token-bucket style queue for each endpoint.\n- [aiohttp](https://aiohttp.readthedocs.io) for all HTTP requests, which automatically performs connection-pooling\n- [SPDX license identifiers](https://spdx.org/)\n- Python [type hints](https://docs.python.org/3/library/typing.html) for ease of development\n- Python3.6+ f-strings for faster string interpolation\n- Exception-chaining with [`raise from`](https://docs.python.org/3/library/exceptions.html#built-in-exceptions)\n- Clean and consistent syntax formatting with [Black](https://github.com/ambv/black)\n- Example [CLI tool](https://github.com/lmacken/binance-chain-python/blob/master/examples/cli.py) that just outputs raw JSON responses\n- Event-driven WebSocket using [pyee](https://github.com/jfhbrook/pyee)\n- Automatically sends `keepAlive` WebSocket messages every 30 minutes\n- Utilizes [orjson](https://github.com/ijl/orjson), the fastest JSON library in Python.\n\n### Utilizes popular crypto libraries\n- [bitcoinlib](https://github.com/1200wd/bitcoinlib)\n- [bech32](https://github.com/sipa/bech32)\n- [secp256k1](https://github.com/ludbb/secp256k1-py)\n- [eth_keyfile](https://github.com/ethereum/eth-keyfile)\n\n## API SECTIONS\n\n- [WEBSOCKET](https://github.com/lmacken/binance-chain-python#websocket)\n- [REST API](https://github.com/lmacken/binance-chain-python#rest-api)\n- [NODE RPC](https://github.com/lmacken/binance-chain-python#node-rpc)\n- [WALLET](https://github.com/lmacken/binance-chain-python#binance-chain-wallet)\n- [TRANSACTION](https://github.com/lmacken/binance-chain-python#binance-chain-transaction)\n\n### NAMESPACE\n\n```python\nfrom binancechain import HTTPClient, NodeRPC, WebSocket, Wallet, Transaction, BinanceChainException\n```\n\n------------------\n\n## WEBSOCKET\n\n### Decorator API\n\n```python\ndex = WebSocket(address, testnet=True)\n\n@dex.on(\"open\")\nasync def on_open(): …\n\n@dex.on(\"allTickers\", symbols=[\"$all\"])\nasync def on_ticker(msg): …\n\n@dex.on(\"kline_1m\", symbols=[\"000-0E1_BNB\"])\nasync def on_kline(kline): …\n\n@dex.on(\"orders\")\nasync def user_orders(msg): …\n\n@dex.on(\"accounts\")\nasync def user_accounts(msg): …\n\n@dex.on(\"transfers\")\nasync def user_transfers(msg): …\n\n@dex.on(\"error\")\nasync def on_error(msg): …\n\ndex.start() # or dex.start_async() coroutine\n```\n### Callback API\n```python\ndex = WebSocket(address, testnet=True)\n\ndef on_open():\n    dex.subscribe_user_orders(callback=user_orders)\n    dex.subscribe_user_accounts(callback=user_accounts)\n    dex.subscribe_user_transfers(callback=user_transfers)\n    dex.subscribe_trades(callback=callback, symbols=symbols)\n    dex.subscribe_market_depth(callback=callback, symbols=symbols)\n    dex.subscribe_market_diff(callback=callback, symbols=symbols)\n    dex.subscribe_klines(callback=callback, symbols=symbols)\n    dex.subscribe_ticker(callback=callback, symbols=symbols)\n    dex.subscribe_all_tickers(callback=callback)\n    dex.subscribe_mini_ticker(callback=callback, symbols=symbols)\n    dex.subscribe_all_mini_tickers(callback=callback)\n    dex.subscribe_blockheight(callback=callback)\n\ndex.start(on_open, on_error)\n```\n\nSee the WebSocket [examples](https://github.com/lmacken/binance-chain-python/tree/master/examples) for more information.\n\n----------------\n\n## REST API\n\n### Query information\n```python\n\nclient = HTTPClient(testnet=True)\n\nserver_time = await client.get_time()\n\nnode_info = await client.get_node_info()\n\nvalidators = await client.get_validators()\n\npeers = await client.get_peers()\n\naccount_info = await client.get_account_info(address)\n\nsequence_info = await client.get_account_sequence(address)\n\ntransaction = await client.get_transaction(hash)\n\ntoken_list = await client.get_token_list()\n\nmarkets = await client.get_markets(limit=500, offset=0)\n\nfees = await client.get_fees()\n\ndepth = await client.get_depth(symbol, limit=100)\n\nklines = await client.get_klines(symbol, interval, limit=300, start=None, end=None)\n\nclosed_orders = await client.get_closed_orders(\n    address,\n    end=None,\n    limit=None,\n    offset=None,\n    side=None,\n    start=None,\n    status=None,\n    symbol=None,\n    total=None,\n)\n\nopen_orders = await client.get_open_orders(\n    self, address, limit=None, offset=None, symbol=None, total=None\n)\n\norder = await client.get_order(id)\n\nticker = await client.get_ticker(symbol)\n\ntrades = await client.get_trades(\n    address=None,\n    buyerOrderId=None,\n    height=None,\n    limit=None,\n    offset=None,\n    quoteAsset=None,\n    sellerOrderId=None,\n    side=None,\n    start=None,\n    end=None,\n    total=None,\n    symbol=None,\n)\n\nblock_fee = await client.block_exchange_fee(\n    address=None, end=None, limit=None, offset=None, start=None, total=None\n)\n\ntransactions = await client.get_transactions(\n    address,\n    height=None,\n    end=None,\n    limit=None,\n    offset=None,\n    side=None,\n    start=None,\n    tx_asset=None,\n    tx_type=None,\n)\n```\n### Broadcast transaction\n```python\nbroadcast_info = await client.broadcast(hash)\n\n```\n\n------------------\n\n## NODE RPC\n### Query Information\n```python\nnoderpc = binancechain.NodeRPC(testnet=True)\n\nabic_info = await noderpc.get_abci_info(path, data=None, height=\"0\", prove=False)\n\nconcensus_state = await noderpc.get_consensus_state()\n\ndump_concensus_state = await noderpc.get_dump_consensus_state()\n\ngenesis = await noderpc.get_genesis()\n\nhealth = await noderpc.get_health()\n\nnet_info = await noderpc.get_net_info()\n\nstatus = await noderpc.get_status()\n\nquery = await noderpc.abci_query(\"/param/fees\")\n\nblock = await noderpc.block(height=None)\n\nblock_hash = await noderpc.block_by_hash(hash)\n\nblock_results = await noderpc.block_results(height=None)  # ABCIResults\n\nblockchain = await noderpc.blockchain(min_height, max_height)\n\nconcensus_params = await noderpc.consensus_params(\"1\")\n\nvalidators = await noderpc.validators(height=None)\n\ntransaction = await noderpc.tx(txid, prove=False)\n\ntx_search = await noderpc.tx_search(query, prove=False, page=1, per_page=30)\n\npending_transactions = await noderpc.unconfirmed_txs(limit=None)\n\npendings_number = await noderpc.get_num_unconfirmed_txs()\n```\n\n### NodeRPC WebSocket\n\n```python\nquery = \"tm.event = 'Tx'\"\n\ndef on_open():\n    noderpc.subscribe(query)\n\ndef on_msg(msg): …\n\nnoderpc.start(on_open=on_open, on_msg=on_msg, on_error=on_error)\n\nnoderpc.unsubscribe(query=query)\nnoderpc.unsubscribe_all()\n```\n\nSee list of all possible events here\nhttps://godoc.org/github.com/tendermint/tendermint/types#pkg-constants\n\nFor complete query syntax, check out https://godoc.org/github.com/tendermint/tendermint/libs/pubsub/query.\n\n### Broadcast transaction\n```python\ntx_hash = await noderpc.broadcast_tx_async(hash)\n\ntx_onchain = await noderpc.broadcast_tx_sync(hash)\n\ntx_confirmed = await noderpc.commit(height=None)\n```\n-------------------\n\n## BINANCE CHAIN WALLET\n\n### Create or recover wallet and keystore\n```python\nwallet = Wallet.create_wallet(password=None, testnet=False)\n\nwallet = Wallet.create_wallet_mnemonic(language=\"english\", password=None, testnet=False)\n\nkeystore = Wallet.create_keystore(password=None)\n\nwallet = Wallet(key=\"HDKEY object\", testnet=False)\n\nwallet = Wallet.wallet_from_keystore(keystore=keystore, password=None, testnet=False)\n\nwallet = Wallet.wallet_from_mnemonic(words=\"mnemonic words\", password=None, testnet=False)\n\nwallet = Wallet.wallet_from_privatekey(privatekey=\"private_key\", password=None, testnet=False)\n```\n\n### Using the wallet\n```python\naddress = wallet.get_adress()\n\npriv = wallet.get_privatekey()\n\npub = wallet.get_publickey()\n\npub, signature = wallet.sign(msg)\n\nis_valid = wallet.verify_signature(msg, signature)\n```\n\n-------------------\n\n## BINANCE CHAIN TRANSACTION\n\n### Using Transaction with wallet and client, handle signing and broadcast internally\n```python\nfrom binancechain.enums import Ordertype, Side, Timeinforce, Votes\n\n#if client is passed in , testnet arg will be ignored\ntransaction = Transaction(wallet=wallet, client=client)\n\ntransfer = await transaction.transfer(\n    to_address=wallet_two.get_address(), symbol=\"BNB\", amount=0.1\n)\n\nmulti_transfer = await transaction.multi_transfer(\n      to_address,\n      transfers=[{\"symbol\": \"BTC\", \"amount\": 0.1}, {\"symbol\": \"BNB\", \"amount\": 0.1}],\n  )\n\nnew_order_txid = await transaction.create_new_order(\n    symbol=\"binance_pair\",\n    side=Side.BUY,\n    ordertype=Ordertype.LIMIT,\n    price=1,\n    quantity=1,\n    timeInForce=Timeinforce.GTE,\n)\n\ncancel_order_txid = await transaction.cancel_order(symbol=\"BTC-531_BNB\", refid=\"\")\n\nfreeze_token_txid = await transaction.freeze_token(symbol=\"BNB\", amount=1)\n\nunfreeze_token_txid = await transaction.unfreeze_token(symbol=\"BNB\", amount=1)\n\nvote_txid = await transaction.vote(proposal_id, option=Votes.YES)  # only validator can vote\n\nissue_token_txid = await transaction.issue_token(symbol, name, supply, mintable)\n\nmint_token_txid = await transaction.mint_token(symbol, amount)\n\nburn_token_txid = await transaction.burn_token(symbol, amount)\n```\n### Create Transaction Message. This message can be signed and broadcast somewhere else\n\n```python\ntransfer_transaction = await Transaction.transfer_transaction(\n      from_address, to_address, symbol, amount\n  )\n\nmulti_transfer_transaction = await Transaction.multi_transfer_transaction(\n    from_address,\n    to_address,\n    transfers=[{\"symbol\": \"BTC\", \"amount\": 0.1}, {\"symbol\": \"BNB\", \"amount\": 0.1}],\n)\n\nlimit_buy_transaction = await Transaction.new_order_transaction(\n      address=\"owner address\",\n      symbol=\"pair\",\n      side=Side.BUY,\n      ordertype=Ordertype.LIMIT,\n      price=1,\n      quantity=1,\n      timeInForce=Timeinforce.GTE,\n      testnet=True,\n      client=None,\n  )\n\nlimit_sell_transaction = await Transaction.new_order_transaction(\n    address=\"owner address\",\n    symbol=\"pair\",\n    side=Side.BUY,\n    ordertype=Ordertype.LIMIT,\n    price=1,\n    quantity=1,\n    timeInForce=Timeinforce.GTE,\n    testnet=True,\n    client=None,\n)\n\ncancel_order_transaction = await Transaction.cancel_order(\n    address=\"owner_address\", symbol=\"pair\", refid=\"\", testnet=True, client=None\n)\n\nfreeze_token_transaction = await Transaction.freeze_token(\n    address=\"ownder_address\", symbol=\"BNB\", amount=1, testnet=True, client=None\n)\n\nunfreeze_token_tranasaction = await Transaction.unfreeze_token_transaction(\n    address=\"ownder_address\", symbol=\"BNB\", amount=1, testnet=True, client=None\n)\n\nvote_transaction = await Transaction.vote_transaction(\n    voter, proposal_id, option=Votes.YES, client=None, testnet=True\n)\n\nissue_token_transaction = await Transaction.issue_token_transaction(\n    owner, name, symbol, sypply, mintable, client=None, testnet=True\n)\n\nmint_token_transaction = await Transaction.mint_token_transaction(\n    owner, symbol, amount, client=None, testnet=True\n)\n\nburn_token_transaction = Transaction.burn_token_transaction(\n    owner, symbol, amount, client=None, testnet=True\n)\n\n\"\"\" Get transaction message to sign\"\"\"\n\nsign_message_bytes_format = Limit_Buy_Transaction.get_sign_message()\n```\n- Example transaction message :\n\n```\nb'{\"account_number\":\"668107\",\"chain_id\":\"Binance-Chain-Nile\",\"data\":null,\"memo\":\"\",\"msgs\":[{\"inputs\":[{\"address\":\"tbnb1r5jc35v338tlphnjx65wy7tecm6vm82tftfkt7\",\"coins\":[{\"amount\":10000000,\"denom\":\"BNB\"}]}],\"outputs\":[{\"address\":\"tbnb1nhvpuq0u5pgpry0x2ap2hqv9n5jfkj90eps6qx\",\"coins\":[{\"amount\":10000000,\"denom\":\"BNB\"}]}]}],\"sequence\":\"35\",\"source\":\"1\"}'\n```\n\n----------------------\n\n## Running the test suite\n\n```bash\ngit clone https://github.com/lmacken/binance-chain-python.git\ncd binance-chain-python\npip install -r test-requirements.txt -r requirements.txt\npython setup.py develop\npytest\n```\n\n----------------------\n\n## Contributors\n\n[@lmacken](https://github.com/lmacken)\n[@propulsor](https://github.com/propulsor)\n\n## Donate\n\nBNB: `bnb1qx8u39hqcykjy5puv582gvqy5520dsz7fdh9ak`\n\nBTC: `39n2J2hWY5FHCnGwNgRSZTe4TdFKcQea9v`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmacken%2Fbinance-chain-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flmacken%2Fbinance-chain-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmacken%2Fbinance-chain-python/lists"}