Skip to content

Commit

Permalink
api
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-zehentleitner committed Nov 13, 2024
1 parent 8eb97a6 commit ca3994f
Show file tree
Hide file tree
Showing 39 changed files with 4,861 additions and 4,057 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- `manager.api.spot.get_recent_trades()`
- `manager.api.spot.get_unfilled_order_count()`
- Support for `Websocket API Futures`:
- `manager.api.futures.get_aggregate_trades()`
- `manager.api.futures.cancel_order()`
- `manager.api.futures.create_order()`
- `manager.api.futures.get_order()`
- `manager.api.futures.get_order_book()`
- `manager.api.futures.modify_order()`

### Changed
- ujson has been replaced by orjson
- Websocket API functions are no longer available under `manager.api` but under `manager.api.spot`. In addition, there
Expand Down
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,23 @@ api_stream = ubwa.create_stream(api=True,
output="UnicornFy",
process_asyncio_queue=process_api_responses)
response = ubwa.api.get_server_time(return_response=True)
response = ubwa.api.spot.get_server_time(return_response=True)
print(f"Binance serverTime: {response['result']['serverTime']}")
orig_client_order_id = ubwa.api.create_order(order_type="LIMIT",
price = 1.1,
quantity = 15.0,
side = "SELL",
symbol = "BUSDUSDT")
orig_client_order_id = ubwa.api.spot.create_order(order_type="LIMIT",
price = 1.1,
quantity = 15.0,
side = "SELL",
symbol = "BUSDUSDT")
ubwa.api.cancel_order(orig_client_order_id=orig_client_order_id, symbol="BUSDUSDT")
ubwa.api.spot.cancel_order(orig_client_order_id=orig_client_order_id, symbol="BUSDUSDT")
```

All available methods:
- [Futures]()
- [Spot]()


[Here](https://medium.lucit.tech/create-and-cancel-orders-via-websocket-on-binance-7f828831404) you can find a complete
guide on
[how to process requests via the Binance WebSocket API](https://medium.lucit.tech/create-and-cancel-orders-via-websocket-on-binance-7f828831404)!
Expand Down
6 changes: 3 additions & 3 deletions binance_websocket_api_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ async def handle_socket_message(stream_id=None):
data = await ubwa.get_stream_data_from_asyncio_queue(stream_id=stream_id)
print(f"received data:\r\n{data}\r\n")

print(f"Starting Stream:")
print(f"Starting the stream:")
api_stream = ubwa.create_stream(api=True,
api_key=os.getenv('BINANCE_API_KEY'),
api_secret=os.getenv('BINANCE_API_SECRET'),
stream_label="Bobs Future Websocket API",
process_asyncio_queue=handle_socket_message)
print(f"Start:")

print(f"Executing API requests on Binance Futures:")
ubwa.api.futures.get_account_status(stream_id=api_stream)
ubwa.api.futures.get_listen_key(stream_id=api_stream)
ubwa.api.futures.get_server_time(stream_id=api_stream)
Expand All @@ -37,7 +38,6 @@ async def handle_socket_message(stream_id=None):
await asyncio.sleep(5)

print(f"Stopping!")
ubwa.stop_manager()

if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG,
Expand Down
31 changes: 30 additions & 1 deletion dev/sphinx/source/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,36 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

[How to upgrade to the latest version!](https://unicorn-binance-websocket-api.docs.lucit.tech/readme.html#installation-and-upgrade)

## 2.8.1.dev (development stage/unreleased/unstable)
## 2.9.0.dev (development stage/unreleased/unstable)
### Added
- New `Websocket API Spot` functions:
- `manager.api.spot.cancel_and_replace_order()`
- `manager.api.spot.get_aggregate_trades()`
- `manager.api.spot.get_current_average_price()`
- `manager.api.spot.get_historical_trades()`
- `manager.api.spot.get_klines()`
- `manager.api.spot.get_ui_klines()`
- `manager.api.spot.get_recent_trades()`
- `manager.api.spot.get_unfilled_order_count()`
- Support for `Websocket API Futures`:
- `manager.api.futures.cancel_order()`
- `manager.api.futures.create_order()`
- `manager.api.futures.get_order()`
- `manager.api.futures.get_order_book()`
- `manager.api.futures.modify_order()`

### Changed
- ujson has been replaced by orjson
- Websocket API functions are no longer available under `manager.api` but under `manager.api.spot`. In addition, there
is now also `manager.api.futures`.
- No more use of deepcopy in ws api (faster!)

## 2.9.0
### Added
- Support for 'binance.com-futures' WebSocket API.
- Error handling if someone tries to use the WebSocket API Feature with an unsupported exchange.
### Fixed
- Type Error of returned value of `api.create_order()` and `api.create_test_order()`.

## 2.8.1
### Changed
Expand Down
28 changes: 16 additions & 12 deletions dev/sphinx/source/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,23 @@ api_stream = ubwa.create_stream(api=True,
output="UnicornFy",
process_asyncio_queue=process_api_responses)
response = ubwa.api.get_server_time(return_response=True)
response = ubwa.api.spot.get_server_time(return_response=True)
print(f"Binance serverTime: {response['result']['serverTime']}")
orig_client_order_id = ubwa.api.create_order(order_type="LIMIT",
price = 1.1,
quantity = 15.0,
side = "SELL",
symbol = "BUSDUSDT")
orig_client_order_id = ubwa.api.spot.create_order(order_type="LIMIT",
price = 1.1,
quantity = 15.0,
side = "SELL",
symbol = "BUSDUSDT")
ubwa.api.cancel_order(orig_client_order_id=orig_client_order_id, symbol="BUSDUSDT")
ubwa.api.spot.cancel_order(orig_client_order_id=orig_client_order_id, symbol="BUSDUSDT")
```

All available methods:
- [Futures]()
- [Spot]()


[Here](https://medium.lucit.tech/create-and-cancel-orders-via-websocket-on-binance-7f828831404) you can find a complete
guide on
[how to process requests via the Binance WebSocket API](https://medium.lucit.tech/create-and-cancel-orders-via-websocket-on-binance-7f828831404)!
Expand Down Expand Up @@ -224,9 +229,8 @@ def process_stream_signals(signal_type=None, stream_id=None, data_record=None, e
with BinanceWebSocketApiManager(process_stream_signals=process_stream_signals) as ubwa:
ubwa.create_stream(channels="trade", markets="btcusdt", stream_label="TRADES")
time.sleep(2)
print(f"Waiting 5 seconds and then stop the stream ...")
time.sleep(5)
print(f"Waiting a few seconds and then stopping the stream ...")
time.sleep(7)
```

## More?
Expand Down Expand Up @@ -291,8 +295,8 @@ Use the [UNICORN Binance REST API](https://www.lucit.tech/unicorn-binance-rest-a
| [Binance Margin Testnet](https://testnet.binance.vision/) | `binance.com-margin-testnet` | ![yes](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/ok-icon.png) | ![no](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/x-icon.png) |
| [Binance Isolated Margin](https://www.binance.com) | `binance.com-isolated_margin` | ![yes](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/ok-icon.png) | ![no](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/x-icon.png) |
| [Binance Isolated Margin Testnet](https://testnet.binance.vision/) | `binance.com-isolated_margin-testnet` | ![yes](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/ok-icon.png) | ![no](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/x-icon.png) |
| [Binance USD-M Futures](https://www.binance.com) | `binance.com-futures` | ![yes](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/ok-icon.png) | ![no](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/x-icon.png) |
| [Binance USD-M Futures Testnet](https://testnet.binancefuture.com) | `binance.com-futures-testnet` | ![yes](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/ok-icon.png) | ![no](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/x-icon.png) |
| [Binance USD-M Futures](https://www.binance.com) | `binance.com-futures` | ![yes](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/ok-icon.png) | ![yes](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/ok-icon.png) |
| [Binance USD-M Futures Testnet](https://testnet.binancefuture.com) | `binance.com-futures-testnet` | ![yes](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/ok-icon.png) | ![yes](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/ok-icon.png) |
| [Binance Coin-M Futures](https://www.binance.com) | `binance.com-coin_futures` | ![yes](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/ok-icon.png) | ![no](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/x-icon.png) |
| [Binance US](https://www.binance.us) | `binance.us` | ![yes](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/ok-icon.png) | ![no](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/x-icon.png) |
| [Binance TR](https://www.trbinance.com) | `trbinance.com` | ![yes](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/ok-icon.png) | ![no](https://raw.githubusercontent.com/lucit-systems-and-development/unicorn-binance-websocket-api/master/images/misc/x-icon.png) |
Expand Down
18 changes: 16 additions & 2 deletions dev/sphinx/source/unicorn_binance_websocket_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ unicorn\_binance\_websocket\_api package
Submodules
----------



unicorn\_binance\_websocket\_api.api module
------------------------------------------------------------------------------------

Expand All @@ -14,6 +12,22 @@ unicorn\_binance\_websocket\_api.api module
:undoc-members:
:show-inheritance:

unicorn\_binance\_websocket\_api.api.futures module
------------------------------------------------------------------------------------

.. automodule:: unicorn_binance_websocket_api.api.futures
:members:
:undoc-members:
:show-inheritance:

unicorn\_binance\_websocket\_api.api.spot module
------------------------------------------------------------------------------------

.. automodule:: unicorn_binance_websocket_api.api.spot
:members:
:undoc-members:
:show-inheritance:

unicorn\_binance\_websocket\_api.connection module
------------------------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions docs/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: fd133eda891a50821eb39e080c87ce22
# This file records the configuration used when building these files. When it is not found, a full rebuild will be done.
config: d250c15ae63cde9bb6cd52f47021e5e4
tags: 645f666f9bcd5a90fca523b33c5a78b7
4 changes: 4 additions & 0 deletions docs/.buildinfo.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: fd133eda891a50821eb39e080c87ce22
tags: 645f666f9bcd5a90fca523b33c5a78b7
7 changes: 4 additions & 3 deletions docs/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ <h3>Navigation</h3>
<div class="body" role="main">

<h1>All modules for which code is available</h1>
<ul><li><a href="unicorn_binance_websocket_api/api.html">unicorn_binance_websocket_api.api</a></li>
<ul><li><a href="unicorn_binance_websocket_api/api/futures.html">unicorn_binance_websocket_api.api.futures</a></li>
<li><a href="unicorn_binance_websocket_api/api/spot.html">unicorn_binance_websocket_api.api.spot</a></li>
<li><a href="unicorn_binance_websocket_api/connection.html">unicorn_binance_websocket_api.connection</a></li>
<li><a href="unicorn_binance_websocket_api/exceptions.html">unicorn_binance_websocket_api.exceptions</a></li>
<li><a href="unicorn_binance_websocket_api/manager.html">unicorn_binance_websocket_api.manager</a></li>
Expand Down Expand Up @@ -254,10 +255,10 @@ <h3>Navigation</h3>
<a href="https://docs.lucit.tech">Index of all LUCIT Software Documentation</a><br />
&copy; <a href="/license.html">Copyright</a> 2023-2023, LUCIT Systems and Development. All Rights Reserved..
See <a href="/license.html">License</a> for more information.<br />
Last updated on Nov 01 2024 at 12:06 (CET).
Last updated on Nov 13 2024 at 18:52 (CET).
<a href="https://github.com/LUCIT-Systems-and-Development/unicorn-binance-websocket-api/issues/new/choose">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.4.7.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.1.3.
with <a href="https://github.com/LUCIT-Systems-and-Development/python-docs-theme-lucit">python-docs-theme-lucit</a>
by <a href="https://www.lucit.tech">LUCIT Systems and Development</a>.
</div>
Expand Down
6 changes: 2 additions & 4 deletions docs/_modules/unicorn_binance_websocket_api/connection.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,13 @@ <h1>Source code for unicorn_binance_websocket_api.connection</h1><div class="hig

<span class="kn">from</span> <span class="nn">.exceptions</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">urllib.parse</span> <span class="kn">import</span> <span class="n">urlparse</span>

<span class="kn">import</span> <span class="nn">asyncio</span>
<span class="kn">import</span> <span class="nn">copy</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">socks</span> <span class="c1"># PySocks https://pypi.org/project/PySocks/</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">websockets</span>


<span class="n">__logger__</span><span class="p">:</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s2">&quot;unicorn_binance_websocket_api&quot;</span><span class="p">)</span>

<span class="n">logger</span> <span class="o">=</span> <span class="n">__logger__</span>
Expand Down Expand Up @@ -469,10 +467,10 @@ <h3>Navigation</h3>
<a href="https://docs.lucit.tech">Index of all LUCIT Software Documentation</a><br />
&copy; <a href="/license.html">Copyright</a> 2023-2023, LUCIT Systems and Development. All Rights Reserved..
See <a href="/license.html">License</a> for more information.<br />
Last updated on Nov 01 2024 at 11:34 (CET).
Last updated on Nov 13 2024 at 18:50 (CET).
<a href="https://github.com/LUCIT-Systems-and-Development/unicorn-binance-websocket-api/issues/new/choose">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.4.7.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.1.3.
with <a href="https://github.com/LUCIT-Systems-and-Development/python-docs-theme-lucit">python-docs-theme-lucit</a>
by <a href="https://www.lucit.tech">LUCIT Systems and Development</a>.
</div>
Expand Down
Loading

0 comments on commit ca3994f

Please sign in to comment.