.. note::
    :class: sphx-glr-download-link-note

    Click :ref:`here <sphx_glr_download_generated_sphinx_gallery_run-01-subscribe-to-trading-channel.py>` to download the full example code
.. rst-class:: sphx-glr-example-title

.. _sphx_glr_generated_sphinx_gallery_run-01-subscribe-to-trading-channel.py:


============================
Subscribe to Trading Channel
============================

.. contents:: Table of Contents
    :local:
    :depth: 1




.. rst-class:: sphx-glr-script-out

 Out:

 .. code-block:: none

    [AuthChannel(is_subscribed=True), BalancesChannel(is_subscribed=True)]
    [AuthChannel(is_subscribed=True),
     TradingChannel(is_subscribed=True),
     BalancesChannel(is_subscribed=True)]
    Submit Market Order
    Submit Market Order






|


.. code-block:: default


    import time
    import logging
    from pprint import pprint
    from blockchain_exchange.client import BlockchainWebsocketClient


    logging.basicConfig(level=logging.INFO)


    def main():
        client = BlockchainWebsocketClient()

        client.subscribe_to_balances()
        time.sleep(2)

        pprint(client.connected_channels)
        time.sleep(2)

        client.subscribe_to_trading()
        time.sleep(2)

        pprint(client.connected_channels)
        time.sleep(2)

        print("Submit Market Order")
        time.sleep(2)
        client.create_market_order(
            order_id="my-order",
            symbol="BTC-USD",
            time_in_force="GTC",
            side="sell",
            quantity=0.000000000001,
        )
        time.sleep(2)

        print("Submit Market Order")
        time.sleep(2)
        client.create_limit_order(
            order_id="my-order",
            price=100000000000000.0,
            symbol="BTC-USD",
            time_in_force="GTC",
            side="sell",
            quantity=0.000000000001,
        )

        time.sleep(10)
        client.cancel_all_orders()


    if __name__ == '__main__':
        main()


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ( 0 minutes  24.732 seconds)


.. _sphx_glr_download_generated_sphinx_gallery_run-01-subscribe-to-trading-channel.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download

     :download:`Download Python source code: run-01-subscribe-to-trading-channel.py <run-01-subscribe-to-trading-channel.py>`



  .. container:: sphx-glr-download

     :download:`Download Jupyter notebook: run-01-subscribe-to-trading-channel.ipynb <run-01-subscribe-to-trading-channel.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
