|
1 | 1 | ================================ |
2 | | -Welcome to python-binance v1.0.7 |
| 2 | +Welcome to python-binance v1.0.8 |
3 | 3 | ================================ |
4 | 4 |
|
| 5 | +Updated 11th May 2021 |
| 6 | + |
5 | 7 | .. image:: https://img.shields.io/pypi/v/python-binance.svg |
6 | 8 | :target: https://pypi.python.org/pypi/python-binance |
7 | 9 |
|
@@ -95,7 +97,7 @@ pass `testnet=True` when creating the client. |
95 | 97 |
|
96 | 98 | .. code:: python |
97 | 99 |
|
98 | | - from binance.client import Client |
| 100 | + from binance import Client, ThreadedWebsocketManager, ThreadedDepthCacheManager |
99 | 101 | client = Client(api_key, api_secret) |
100 | 102 |
|
101 | 103 | # get market depth |
@@ -144,6 +146,35 @@ pass `testnet=True` when creating the client. |
144 | 146 | # fetch weekly klines since it listed |
145 | 147 | klines = client.get_historical_klines("NEOBTC", Client.KLINE_INTERVAL_1WEEK, "1 Jan, 2017") |
146 | 148 |
|
| 149 | + # socket manager using threads |
| 150 | + twm = ThreadedWebsocketManager() |
| 151 | + twm.start() |
| 152 | +
|
| 153 | + # depth cache manager using threads |
| 154 | + dcm = ThreadedDepthCacheManager() |
| 155 | + dcm.start() |
| 156 | +
|
| 157 | + def handle_socket_message(msg): |
| 158 | + print(f"message type: {msg['e']}") |
| 159 | + print(msg) |
| 160 | +
|
| 161 | + def handle_dcm_message(depth_cache): |
| 162 | + print(f"symbol {depth_cache.symbol}") |
| 163 | + print("top 5 bids") |
| 164 | + print(depth_cache.get_bids()[:5]) |
| 165 | + print("top 5 asks") |
| 166 | + print(depth_cache.get_asks()[:5]) |
| 167 | + print("last update time {}".format(depth_cache.update_time)) |
| 168 | +
|
| 169 | + twm.start_kline_socket(callback=handle_socket_message, symbol='BNBBTC') |
| 170 | +
|
| 171 | + dcm.start_depth_cache(callback=handle_dcm_message, symbol='ETHBTC') |
| 172 | +
|
| 173 | + # replace with a current options symbol |
| 174 | + options_symbol = 'BTC-210430-36000-C' |
| 175 | + dcm.start_options_depth_cache(callback=handle_dcm_message, symbol=options_symbol) |
| 176 | +
|
| 177 | +
|
147 | 178 | For more `check out the documentation <https://python-binance.readthedocs.io/en/latest/>`_. |
148 | 179 |
|
149 | 180 | Async Example |
|
0 commit comments