{"repo":"sammchardy/python-binance","free":true,"listed":false,"github":"https://github.com/sammchardy/python-binance","clone":"git clone https://github.com/sammchardy/python-binance.git","description":"Binance Exchange API python implementation for automated trading","language":"Python","stars":7199,"topics":["api","binance","cryptocurrency","python","python2","python3","websockets"],"license":"MIT","category":"trading_bot","readme_excerpt":"=================================\nWelcome to python-binance v1.0.37\n=================================\n\n.. image:: https://img.shields.io/pypi/v/python-binance.svg\n    :target: https://pypi.python.org/pypi/python-binance\n\n.. image:: https://img.shields.io/pypi/l/python-binance.svg\n    :target: https://pypi.python.org/pypi/python-binance\n\n.. image:: https://img.shields.io/coveralls/sammchardy/python-binance.svg\n    :target: https://coveralls.io/github/sammchardy/python-binance\n\n.. image:: https://img.shields.io/pypi/wheel/python-binance.svg\n    :target: https://pypi.python.org/pypi/python-binance\n\n.. image:: https://img.shields.io/pypi/pyversions/python-binance.svg\n    :target: https://pypi.python.org/pypi/python-binance\n\n.. image:: https://img.shields.io/badge/Telegram-Join%20Us-blue?logo=Telegram\n    :target: https://t.me/python_binance\n\n\nThis is an unofficial Python wrapper for the `Binance exchange REST API v3 <https://binance-docs.github.io/apidocs/spot/en>`_.\n\nIf you came here looking for the `Binance exchange <https://accounts.binance.com/register?ref=PGDFCE46>`_ to purchase cryptocurrencies, then `go here <https://accounts.binance.com/register?ref=PGDFCE46>`_.\nIf you want to automate interactions with Binance stick around.\n\n.. |ico1| image:: https://avatars.githubusercontent.com/u/31901609?s=48&v=4\n    :target: https://github.com/ccxt/ccxt\n    :height: 3ex\n    :align: middle\n\n**This project is powered by** |ico1|\n\n*Please make sure your* `python-binance` *version is* **v.1.0.20** *or higher.*\n*The previous versions are no longer recommended because some endpoints have been deprecated.*\n\nSource code\n  https://github.com/sammchardy/python-binance\n\nDocumentation\n  https://python-binance.readthedocs.io/en/latest/\n\nCommunity Telegram Chat\n  https://t.me/python_binance\n\nAnnouncements Channel\n  https://t.me/python_binance_announcements\n\nExamples including async\n  https://github.com/sammchardy/python-binance/tree/master/examples\n\n- `Async basics for Binance <https://sammchardy.github.io/binance/2021/05/01/async-binance-basics.html>`_\n- `Understanding Binance Order Filters <https://sammchardy.github.io/binance/2021/05/03/binance-order-filters.html>`_\n\nMake sure you update often and check the `Changelog <https://python-binance.readthedocs.io/en/latest/changelog.html>`_ for new features and bug fixes.\n\nYour contributions, suggestions, and fixes are always welcome! Don't hesitate to open a GitHub issue or reach out to us on our Telegram chat\n\nFeatures\n--------\n\n- Implementation of all General, Market Data and Account endpoints.\n- Asyncio implementation\n- Demo trading support (by providing demo=True)\n- Testnet support for Spot, Futures and Vanilla Options (deprecated)\n- Simple handling of authentication include RSA and EDDSA keys\n- Verbose mode for inspecting requests (verbose=True)\n- No need to generate timestamps yourself, the wrapper does it for you\n- RecvWindow sent by default\n- Response exception handling\n- Customizable HTTP headers\n- Websocket handling with reconnection and multiplexed connections\n- CRUD over websockets, create/fetch/edit through websockets for minimum latency.\n- Symbol Depth Cache\n- Historical Kline/Candle fetching function\n- Withdraw functionality\n- Deposit addresses\n- Margin Trading\n- Futures Trading\n- Porfolio Margin Trading\n- Vanilla Options\n- Proxy support (REST and WS)\n- Orjson support for faster JSON parsing\n- Support other domains (.us, .jp, etc)\n- Support for the Gift Card API\n\nUpgrading to v1.0.0+\n--------------------\n\nThe breaking changes include the migration from wapi to sapi endpoints which related to the\nwallet endpoints detailed in the `Binance Docs <https://binance-docs.github.io/apidocs/spot/en/#wallet-endpoints>`_\n\nThe other breaking change is for websocket streams and the Depth Cache Manager which have been\nconverted to use Asynchronous Context Managers. See examples in the Async section below or view the\n`websockets <https://python-binance.readthedocs.io/en/latest/websockets.html>`_ and\n`depth cache <https://python-binance.readthedocs.io/en/latest/depth_cache.html>`_ docs.\n\nQuick Start\n-----------\n\n`Register an account with Binance <https://accounts.binance.com/register?ref=PGDFCE46>`_.\n\n`Generate an API Key <https://www.binance.com/en/my/settings/api-management>`_ and assign relevant permissions.\n\nIf you are using an exchange from the US, Japan or other TLD then make sure pass `tld='us'` when creating the\nclient.\n\nTo use the `Spot <https://testnet.binance.vision/>`_, `Vanilla Options <https://testnet.binanceops.com/>`_ , or `Futures <https://testnet.binancefuture.com>`_ Testnet\npass `testnet=True` when creating the client.\n\n\n.. code:: bash\n\n    pip install python-binance\n\n\n.. code:: python\n\n    from binance import Client, ThreadedWebsocketManager, ThreadedDepthCacheManager\n    client = Client(api_key, api_secret)\n\n    # get market depth\n    depth = client.get_order_book(symbol='BNBBTC')\n\n    # place a test market buy order, to place an actual order use the create_order function\n    order = client.create_test_order(\n        symbol='BNBBTC',\n        side=Client.SIDE_BUY,\n        type=Client.ORDER_TYPE_MARKET,\n        quantity=100)\n\n    # get all symbol prices\n    prices = client.get_all_tickers()\n\n    # withdraw 100 ETH\n    # check docs for assumptions around withdrawals\n    from binance.exceptions import BinanceAPIException\n    try:\n        result = client.withdraw(\n            asset='ETH',\n            address='<eth_address>',\n            amount=100)\n    except BinanceAPIException as e:\n        print(e)\n    else:\n        print(\"Success\")\n\n    # fetch list of withdrawals\n    withdraws = client.get_withdraw_history()\n\n    # fetch list of ETH withdrawals\n    eth_withdraws = client.get_withdraw_history(coin='ETH')\n\n    # get a deposit address for BTC\n    address = client.get_deposit_address(coin='BTC')\n\n    # get historical kline data from any date range\n\n    # fetch 1 minute klines for the last day up until now\n    klines = client.get_historical_klines(\"BNBBTC\", Client.KLINE_INTERVAL_1MINUTE, \"1 day ago UTC\")\n\n    # fetch 30 minute klines for the last month of 2017\n    klines = client.get_historical_klines(\"ETHBTC\", Client.KLINE_INTERVAL_30MINUTE, \"1 Dec, 2017\", \"1 Jan, 2018\")\n\n    # fetch weekly klines since it listed\n    klines = client.get_historical_klines(\"NEOBTC\", Client.KLINE_INTERVAL_1WEEK, \"1 Jan, 2017\")\n\n    # create conditional order using the dedicated method\n    algo_order = client.futures_create_algo_order(symbol=\"LTCUSDT\", side=\"BUY\", type=\"STOP_MARKET\", quantity=0.1, triggerPrice = 120)\n\n    # create conditional order using the create_order method (will redirect to the algoOrder as well)\n    order2 = await client.futures_create_order(symbol=\"LTCUSDT\", side=\"BUY\", type=\"STOP_MARKET\", quantity=0.1, triggerPrice = 120)\n\n    # cancel algo/conditional order\n    cancel2 = await client.futures_cancel_algo_order(orderId=order2[\"orderId\"], symbol=\"LTCUSDT\")\n\n    # fetch open algo/conditional orders\n    open_orders = await client.futures_get_open_algo_orders(symbol=\"LTCUSDT\")\n\n    # create order through websockets\n    order_ws = client.ws_create_order( symbol=\"LTCUSDT\", side=\"BUY\", type=\"MARKET\", quantity=0.1)\n\n    # get account using custom headers\n    account = client.get_account(headers={'MyCustomKey': 'MyCustomValue'})\n\n    # socket manager using threads\n    twm = ThreadedWebsocketManager()\n    twm.start()\n\n    # depth cache manager using threads\n    dcm = ThreadedDepthCacheManager()\n    dcm.start()\n\n    def handle_socket_message(msg):\n        print(f\"message type: {msg['e']}\")\n        print(msg)\n\n    def handle_dcm_message(depth_cache):\n        print(f\"symbol {depth_cache.symbol}\")\n        print(\"top 5 bids\")\n        print(depth_cache.get_bids()[:5])\n        print(\"top 5 asks\")\n        print(depth_cache.get_asks()[:5])\n        print(\"last update time {}\".format(depth_cache.update_time))\n\n    twm.start_kline_socket(callback=handle_socket_message, symbol='BNBBTC')\n\n    dcm.start_depth_cache(callback=handle_dcm_message, symbol='ETHBTC')\n\n    # replace with a current options symbol\n    options_symbol = 'BTC-241227-41000-C'\n    dcm.start_options_depth_cache(callback=handle_dcm_message, symbol=options_symbol)\n\n    # join the threaded managers to the main thread\n    twm.join()\n    dcm.join()\n\nFor more `check out the documentation <https://python-binance.readthedocs.io/en/latest/>`_.\n\nAsync Example\n-------------\n\nRead `Async basics for Binance <https://sammchardy.github.io/binance/2021/05/01/async-binance-basics.html>`_\nfor more information.\n\n.. code:: python\n\n    import asyncio\n    import json\n\n    from binance import AsyncClient, DepthCacheManager, BinanceSocketManager\n\n    async def main():\n\n        # initialise the client\n        client = await AsyncClient.create()\n\n        # run some simple requests\n        print(json.dumps(await client.get_exchange_info(), indent=2))\n\n        print(json.dumps(await client.get_symbol_ticker(symbol=\"BTCUSDT\"), indent=2))\n\n        # initialise websocket factory manager\n        bsm = BinanceSocketManager(client)\n\n        # create listener using async with\n        # this will exit and close the connection after 5 messages\n        async with bsm.trade_socket('ETHBTC') as ts:\n            for _ in range(5):\n                res = await ts.recv()\n                print(f'recv {res}')\n\n        # get historical kline data from any date range\n\n        # fetch 1 minute klines for the last day up until now\n        klines = client.get_historical_klines(\"BNBBTC\", AsyncClient.KLINE_INTERVAL_1MINUTE, \"1 day ago UTC\")\n\n        # use generator to fetch 1 minute klines for the last day up until now\n        async for kline in await client.get_historical_klines_generator(\"BNBBTC\", AsyncClient.KLINE_INTERVAL_1MINUTE, \"1 day ago UTC\"):\n            print(kline)\n\n        # fetch 30 minute klines for the last month of 2017\n        klines = await client.get_historical_klines(\"ETHBTC\", Client.KLINE_INTERVAL_30MINUTE, \"1 Dec, 2017\", \"1 Jan, 2018\")\n\n        # fetch ","default_branch":"master","files":116,"tree":[".agents/skills/python-binance/SKILL.md",".agents/skills/python-binance/references/REFERENCE.md",".coverage",".github/CODEOWNERS",".github/ISSUE_TEMPLATE/bug_report.md",".github/workflows/python-app.yml",".gitignore",".pre-commit-config.yaml",".readthedocs.yaml",".travis.yml","Endpoints.md","LICENSE","PYPIREADME.rst","README.rst","binance/__init__.py","binance/async_client.py","binance/base_client.py","binance/client.py","binance/enums.py","binance/exceptions.py","binance/helpers.py","binance/ws/__init__.py","binance/ws/constants.py","binance/ws/depthcache.py","binance/ws/keepalive_websocket.py","binance/ws/reconnecting_websocket.py","binance/ws/streams.py","binance/ws/threaded_stream.py","binance/ws/websocket_api.py","code-generator.py","docs/Makefile","docs/account.rst","docs/binance.rst","docs/changelog.rst","docs/conf.py","docs/constants.rst","docs/depth_cache.rst","docs/exceptions.rst","docs/faqs.rst","docs/general.rst","docs/helpers.rst","docs/index.rst","docs/margin.rst","docs/market_data.rst","docs/overview.rst","docs/requirements.txt","docs/sub_accounts.rst","docs/websockets.rst","docs/withdraw.rst","examples/binace_socket_manager.py","examples/create_oco_order.py","examples/create_order.py","examples/create_order_async.py","examples/depth_cache_example.py","examples/depth_cache_threaded_example.py","examples/futures_algo_order_examples.py","examples/save_historical_data.py","examples/verbose_example.py","examples/websocket.py","examples/ws_create_order.py","examples/ws_create_order_async.py","generate_llms_txt.py","llms-full.txt","llms.txt","pyproject.toml","pyrightconfig.json","pytest.ini","requirements.txt","setup.cfg","setup.py","test-requirements.txt","tests/__init__.py","tests/conftest.py","tests/test_api_request.py","tests/test_async_client.py","tests/test_async_client_futures.py","tests/test_async_client_gift_card copy.py","tests/test_async_client_margin.py","tests/test_async_client_options.py","tests/test_async_client_portfolio.py","tests/test_async_client_ws_api.py","tests/test_async_client_ws_futures_requests.py","tests/test_client.py","tests/test_client_futures.py","tests/test_client_gift_card.py","tests/test_client_margin.py","tests/test_client_options.py","tests/test_client_portfolio.py","tests/test_client_ws_api.py","tests/test_client_ws_futures_requests.py","tests/test_cryptography.py","tests/test_depth_cache.py","tests/test_error_propagation.py","tests/test_futures.py","tests/test_get_order_book.py","tests/test_headers.py","tests/test_historical_klines.py","tests/test_ids.py","tests/test_init.py","tests/test_keepalive_reconnect.py","tests/test_order.py","tests/test_ping.py","tests/test_reconnecting_websocket.py","tests/test_region_exception.py","tests/test_socket_manager.py","tests/test_streams.py","tests/test_streams_options.py","tests/test_threaded_socket_manager.py","tests/test_threaded_stream.py","tests/test_user_socket_integration.py","tests/test_verbose_mode.py","tests/test_websocket_verbose.py","tests/test_ws_api.py","tests/test_ws_urls_integration.py","tests/utils.py","tox.ini"],"storefront":"/r/sammchardy","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/sammchardy/python-binance/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}