Skip to content

Commit d0eaa53

Browse files
orjson, unittest, ...
1 parent 983a19d commit d0eaa53

File tree

13 files changed

+159
-107
lines changed

13 files changed

+159
-107
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
2121
- Support for `Websocket API Futures`:
2222
- `manager.api.futures.get_aggregate_trades()`
2323
### Changed
24+
- ujson has been replaced by orjson
2425
- Websocket API functions are no longer available under `manager.api` but under `manager.api.spot`. In addition, there
2526
is now also `manager.api.futures`.
2627

binance_websocket_api_futures.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ async def handle_socket_message(stream_id=None):
1616
data = await ubwa.get_stream_data_from_asyncio_queue(stream_id=stream_id)
1717
print(f"received data:\r\n{data}\r\n")
1818

19+
print(f"Starting Stream:")
1920
api_stream = ubwa.create_stream(api=True,
2021
api_key=os.getenv('BINANCE_API_KEY'),
2122
api_secret=os.getenv('BINANCE_API_SECRET'),
@@ -28,7 +29,7 @@ async def handle_socket_message(stream_id=None):
2829
orig_client_order_id = ubwa.api.futures.create_order(stream_id=api_stream, price=1.0, order_type="LIMIT",
2930
quantity=15.0, side="SELL", symbol=market)
3031
ubwa.api.futures.ping(stream_id=api_stream)
31-
ubwa.api.futures.get_order_book(stream_id=api_stream, symbol=market, limit=2)
32+
orderbook = ubwa.api.futures.get_order_book(stream_id=api_stream, symbol=market, limit=2, return_response=True)
3233
ubwa.api.futures.cancel_order(stream_id=api_stream, symbol=market, orig_client_order_id=orig_client_order_id)
3334
ubwa.api.futures.get_order(stream_id=api_stream, symbol=market, orig_client_order_id=orig_client_order_id)
3435

binance_websocket_api_spot.py

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ async def binance_api(ubwa):
1414
async def handle_socket_message(stream_id=None):
1515
while ubwa.is_stop_request(stream_id=stream_id) is False:
1616
data = await ubwa.get_stream_data_from_asyncio_queue(stream_id=stream_id)
17-
print(f"received data:\r\n{data}\r\n")
17+
print(f"Received data:\r\n{data}\r\n")
18+
1819
print(f"Starting Stream:")
1920
api_stream = ubwa.create_stream(api=True,
2021
api_key=os.getenv('BINANCE_API_KEY'),
@@ -23,24 +24,58 @@ async def handle_socket_message(stream_id=None):
2324
process_asyncio_queue=handle_socket_message)
2425
print(f"Commands")
2526
ubwa.api.spot.get_listen_key(stream_id=api_stream)
27+
2628
ubwa.api.spot.get_server_time(stream_id=api_stream)
27-
ubwa.api.spot.get_account_status(stream_id=api_stream)
29+
30+
server_time = ubwa.api.spot.get_server_time(stream_id=api_stream, return_response=True)
31+
print(f"Server Time: {server_time['result']['serverTime']}\r\n")
32+
33+
account_status = ubwa.api.spot.get_account_status(stream_id=api_stream, return_response=True)
34+
print(f"Status of account_status request: {account_status['status']}\r\n")
35+
2836
orig_client_order_id = ubwa.api.spot.create_order(stream_id=api_stream, price=1.0, order_type="LIMIT",
2937
quantity=15.0, side="SELL", symbol=market)
38+
3039
ubwa.api.spot.create_test_order(stream_id=api_stream, price=1.2, order_type="LIMIT",
3140
quantity=12.0, side="SELL", symbol=market)
41+
3242
ubwa.api.spot.ping(stream_id=api_stream)
33-
ubwa.api.spot.get_exchange_info(stream_id=api_stream, symbols=[market, ])
34-
ubwa.api.spot.get_order_book(stream_id=api_stream, symbol=market, limit=2)
35-
ubwa.api.spot.get_aggregate_trades(stream_id=api_stream, symbol=market)
36-
ubwa.api.spot.get_historical_trades(stream_id=api_stream, symbol=market)
37-
ubwa.api.spot.get_klines(stream_id=api_stream, symbol=market, interval="1m")
38-
ubwa.api.spot.get_ui_klines(stream_id=api_stream, symbol=market, interval="1d")
39-
ubwa.api.spot.get_recent_trades(stream_id=api_stream, symbol=market)
40-
ubwa.api.spot.cancel_order(stream_id=api_stream, symbol=market, orig_client_order_id=orig_client_order_id)
43+
44+
exchange_info = ubwa.api.spot.get_exchange_info(stream_id=api_stream, symbols=[market, ], return_response=True)
45+
print(f"Status of exchange_info request: {exchange_info['status']}\r\n")
46+
47+
order_book = ubwa.api.spot.get_order_book(stream_id=api_stream, symbol=market, limit=2, return_response=True)
48+
print(f"Orderbook, lastUpdateId={order_book['result']['lastUpdateId']}: {order_book['result']['asks']}, "
49+
f"{order_book['result']['bids']}\r\n")
50+
51+
aggregate_trades = ubwa.api.spot.get_aggregate_trades(stream_id=api_stream, symbol=market, return_response=True)
52+
print(f"aggregate_trades: {aggregate_trades['result'][:5]}\r\n")
53+
54+
historical_trades = ubwa.api.spot.get_historical_trades(stream_id=api_stream, symbol=market, return_response=True)
55+
print(f"historical_trades: {historical_trades['result'][:5]}\r\n")
56+
57+
recent_trades = ubwa.api.spot.get_recent_trades(stream_id=api_stream, symbol=market, return_response=True)
58+
print(f"recent_trades: {recent_trades['result'][:5]}\r\n")
59+
60+
klines = ubwa.api.spot.get_klines(stream_id=api_stream, symbol=market, interval="1m", return_response=True)
61+
print(f"A few klines: {klines['result'][:5]}\r\n")
62+
63+
ui_klines = ubwa.api.spot.get_ui_klines(stream_id=api_stream, symbol=market, interval="1d", return_response=True)
64+
print(f"A few ui_klines: {ui_klines['result'][:5]}\r\n")
65+
66+
replaced_client_order_id = ubwa.api.spot.cancel_and_replace_order(stream_id=api_stream, price=1.1,
67+
order_type="LIMIT",
68+
quantity=15.0, side="SELL", symbol=market,
69+
cancel_orig_client_order_id=orig_client_order_id)
70+
71+
ubwa.api.spot.cancel_order(stream_id=api_stream, symbol=market, orig_client_order_id=replaced_client_order_id)
72+
4173
ubwa.api.spot.get_open_orders(stream_id=api_stream, symbol=market)
74+
4275
ubwa.api.spot.get_open_orders(stream_id=api_stream)
76+
4377
ubwa.api.spot.cancel_open_orders(stream_id=api_stream, symbol=market)
78+
4479
ubwa.api.spot.get_order(stream_id=api_stream, symbol=market, orig_client_order_id=orig_client_order_id)
4580

4681
print(f"Finished! Waiting for responses:")
@@ -54,11 +89,13 @@ async def handle_socket_message(stream_id=None):
5489
filename=os.path.basename(__file__) + '.log',
5590
format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
5691
style="{")
92+
93+
# Loading os.getenv() vars from .env
5794
load_dotenv()
5895

5996
# To use this library you need a valid UNICORN Binance Suite License:
6097
# https://shop.lucit.services
61-
with BinanceWebSocketApiManager(exchange='binance.com') as ubwa_manager:
98+
with BinanceWebSocketApiManager(exchange='binance.com', output_default="dict") as ubwa_manager:
6299
try:
63100
asyncio.run(binance_api(ubwa_manager))
64101
except KeyboardInterrupt:

dev/test_websocket_api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import logging
3737
import os
3838
import time
39-
import ujson as json
4039

4140
api_key = ""
4241
api_secret = ""

environment.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ dependencies:
1515
- Cython
1616
- flask
1717
- flask-restful
18+
- orjson
1819
- psutil
1920
- PySocks
2021
- requests>=2.31.0
21-
- ujson
22+
- simplejson
2223
- websocket-client
2324
- websockets==11.0.3
2425
- typing_extensions

meta.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ requirements:
3434
- Cython
3535
- flask
3636
- flask-restful
37+
- orjson
3738
- psutil
3839
- PySocks
3940
- requests >=2.31.0
40-
- ujson
41+
- simplejson
4142
- websocket-client
4243
- websockets==11.0.3
4344
- typing_extensions
@@ -51,10 +52,11 @@ requirements:
5152
- Cython
5253
- flask
5354
- flask-restful
55+
- orjson
5456
- psutil
5557
- PySocks
5658
- requests >=2.31.0
57-
- ujson
59+
- simplejson
5860
- websocket-client
5961
- websockets==11.0.3
6062
- typing_extensions

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ Cython = "*"
3030
flask = "*"
3131
flask_restful = "*"
3232
lucit-licensing-python = ">=1.8.2"
33+
orjson = "*"
3334
psutil = "*"
3435
PySocks = "*"
3536
requests = ">=2.31.0"
36-
ujson = "*"
37+
simplejson = "*"
3738
unicorn-fy = ">=0.14.2"
3839
unicorn-binance-rest-api = ">=2.5.1"
3940
websocket-client = "*"

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ psutil
1414
PySocks
1515
requests>=2.31.0
1616
simplejson
17-
ujson
17+
orjson
1818
unicorn-fy>=0.14.2
1919
unicorn-binance-rest-api>=2.5.1
2020
websocket-client

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
long_description_content_type="text/markdown",
6868
license='LSOSL - LUCIT Synergetic Open Source License',
6969
install_requires=['colorama', 'requests>=2.31.0', 'websocket-client', 'websockets==11.0.3', 'flask_restful',
70-
'cheroot', 'flask', 'lucit-licensing-python>=1.8.2', 'ujson', 'psutil', 'PySocks',
70+
'cheroot', 'flask', 'lucit-licensing-python>=1.8.2', 'orjson', 'psutil', 'PySocks', 'simplejson',
7171
'unicorn-fy>=0.14.2', 'unicorn-binance-rest-api>=2.5.1', 'typing_extensions', 'Cython'],
7272
keywords='binance, asyncio, async, asynchronous, concurrent, websocket-api, webstream-api, '
7373
'binance-websocket, binance-webstream, webstream, websocket, api, binance-dex, '

0 commit comments

Comments
 (0)