Skip to content

Commit 17f42bb

Browse files
stubs
1 parent ada6723 commit 17f42bb

File tree

7 files changed

+52
-30
lines changed

7 files changed

+52
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ __pycache__/
1313

1414
# Distribution / packaging
1515
.Python
16+
stubs/
1617
build/
1718
develop-eggs/
1819
dist/

dev/reset.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ rm dev/*.log
66
rm build -r
77
rm dist -r
88
rm *.egg-info -r
9+
rm stubs -r
10+
rm out -r
911

1012
rm unicorn_binance_websocket_api/*.c
1113
rm unicorn_binance_websocket_api/*.html

example_binance_dex.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
# https://docs.python.org/3/library/logging.html#logging-levels
4242
logging.getLogger("unicorn_binance_websocket_api")
43-
logging.basicConfig(level=logging.INFO,
43+
logging.basicConfig(level=logging.DEBUG,
4444
filename=os.path.basename(__file__) + '.log',
4545
format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
4646
style="{")
@@ -51,7 +51,9 @@ def print_stream_data_from_stream_buffer(binance_websocket_api_manager):
5151
if binance_websocket_api_manager.is_manager_stopping():
5252
exit(0)
5353
oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer()
54-
if oldest_stream_data_from_stream_buffer is None:
54+
if oldest_stream_data_from_stream_buffer is not None:
55+
print(oldest_stream_data_from_stream_buffer)
56+
else:
5557
time.sleep(0.01)
5658

5759

@@ -60,7 +62,7 @@ def print_stream_data_from_stream_buffer(binance_websocket_api_manager):
6062

6163
# create instance of BinanceWebSocketApiManager for Binance Chain DEX
6264
# use `exchange="binance.org-testnet"` for testnet mode
63-
binance_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.org")
65+
binance_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.org-testnet", high_performance=False)
6466

6567
# start a worker process to move the received stream_data from the stream_buffer to a print function
6668
worker_thread = threading.Thread(target=print_stream_data_from_stream_buffer, args=(binance_websocket_api_manager,))
@@ -82,13 +84,6 @@ def print_stream_data_from_stream_buffer(binance_websocket_api_manager):
8284
binance_websocket_api_manager.create_stream('transfers', binance_dex_user_address)
8385
user_address_multi_stream_id = binance_websocket_api_manager.create_stream(['orders', 'transfers'],
8486
binance_dex_user_address)
85-
86-
# subscribe is going to be rewritten, dont use for now!
87-
#if binance_websocket_api_manager.wait_till_stream_has_started(user_address_multi_stream_id):
88-
# binance_websocket_api_manager.subscribe_to_stream(user_address_multi_stream_id,
89-
# 'accounts',
90-
# binance_dex_user_address)
91-
9287
# single streams
9388
if binance_websocket_api_manager.get_exchange() == "binance.org":
9489
markets = 'RAVEN-F66_BNB'
@@ -105,7 +100,7 @@ def print_stream_data_from_stream_buffer(binance_websocket_api_manager):
105100
channels = ['trades', 'kline_1m', 'kline_5m', 'kline_15m', 'marketDepth', 'ticker', 'miniTicker', 'marketDiff']
106101
markets = ['RAVEN-F66_BNB', 'ANKR-E97_BNB', 'AWC-986_BNB', 'COVA-218_BNB', 'BCPT-95A_BNB', 'WISH-2D5_BNB',
107102
'MITH-C76_BNB', 'BNB_BTCB-1DE', 'BNB_USDSB-1AC', 'BTCB-1DE_USDSB-1AC', 'NEXO-A84_BNB']
108-
#multiplex_stream_id = binance_websocket_api_manager.create_stream(channels, markets)
103+
multiplex_stream_id = binance_websocket_api_manager.create_stream(channels, markets)
109104

110105
while True:
111106
binance_websocket_api_manager.print_summary()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ requires = ["setuptools", "wheel", "Cython", "pip"]
4646
build-backend = "setuptools.build_meta"
4747

4848
[tool.poetry.package_data]
49-
unicorn_binance_websocket_api = ["*.so", "*.dll", "*.py"]
49+
"unicorn_binance_websocket_api" = ["*.so", "*.dll", "*.py", "*.pyi"]

setup.py

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,51 @@
1818
# Copyright (c) 2019-2024, LUCIT Systems and Development (https://www.lucit.tech)
1919
# All rights reserved.
2020

21-
from setuptools import setup
2221
from Cython.Build import cythonize
22+
from setuptools import setup
23+
import os
24+
import shutil
25+
import subprocess
26+
27+
source_dir = "unicorn_binance_websocket_api"
28+
stubs_dir = "stubs"
29+
30+
31+
def generate_stubs():
32+
print("Generating stub files ...")
33+
target_dir = os.path.join(stubs_dir)
34+
os.makedirs(target_dir, exist_ok=True)
35+
for filename in os.listdir(source_dir):
36+
if filename.endswith('.py'):
37+
source_path = os.path.join(source_dir, filename)
38+
stub_output_dir = os.path.join(stubs_dir, source_dir)
39+
os.makedirs(stub_output_dir, exist_ok=True)
40+
subprocess.run(['stubgen', '-o', stub_output_dir, source_path], check=True)
41+
for stub_file in os.listdir(stub_output_dir):
42+
if stub_file.endswith('.pyi'):
43+
source_stub_path = os.path.join(stub_output_dir, stub_file)
44+
shutil.move(source_stub_path, source_dir)
45+
print("Stub files generated and moved successfully.")
46+
2347

2448
with open("README.md", "r") as fh:
2549
long_description = fh.read()
2650

51+
generate_stubs()
52+
2753
setup(
2854
ext_modules=cythonize(
29-
['unicorn_binance_websocket_api/__init__.py',
30-
'unicorn_binance_websocket_api/api.py',
31-
'unicorn_binance_websocket_api/connection.py',
32-
'unicorn_binance_websocket_api/connection_settings.py',
33-
'unicorn_binance_websocket_api/exceptions.py',
34-
'unicorn_binance_websocket_api/manager.py',
35-
'unicorn_binance_websocket_api/restclient.py',
36-
'unicorn_binance_websocket_api/restserver.py',
37-
'unicorn_binance_websocket_api/sockets.py',
38-
'unicorn_binance_websocket_api/licensing_exceptions.py',
39-
'unicorn_binance_websocket_api/licensing_manager.py'],
55+
[f'{source_dir}/__init__.py',
56+
f'{source_dir}/api.py',
57+
f'{source_dir}/connection.py',
58+
f'{source_dir}/connection_settings.py',
59+
f'{source_dir}/exceptions.py',
60+
f'{source_dir}/manager.py',
61+
f'{source_dir}/restclient.py',
62+
f'{source_dir}/restserver.py',
63+
f'{source_dir}/sockets.py',
64+
f'{source_dir}/licensing_exceptions.py',
65+
f'{source_dir}/licensing_manager.py'],
4066
annotate=False),
4167
name='unicorn-binance-websocket-api',
4268
version="2.6.0",
@@ -54,7 +80,7 @@
5480
'unicorn-binance-rest-api', 'typing_extensions', 'Cython'],
5581
keywords='binance, asyncio, async, asynchronous, concurrent, websocket-api, webstream-api, '
5682
'binance-websocket, binance-webstream, webstream, websocket, api, binance-dex, '
57-
'binance-futures, binance-margin, binance-us',
83+
'binance-futures, binance-margin, binance-us',
5884
project_urls={
5985
'Howto': 'https://www.lucit.tech/unicorn-binance-websocket-api.html#howto',
6086
'Documentation': 'https://unicorn-binance-websocket-api.docs.lucit.tech',
@@ -69,9 +95,7 @@
6995
'LUCIT Online Shop': 'https://shop.lucit.services/software',
7096
},
7197
python_requires='>=3.7.0',
72-
package_data={'': ['unicorn_binance_websocket_api/*.so',
73-
'unicorn_binance_websocket_api/*.dll',
74-
'unicorn_binance_websocket_api/*.py']},
98+
package_data={'': ['*.so', '*.dll', '*.py', '*.pyi']},
7599
classifiers=[
76100
"Development Status :: 5 - Production/Stable",
77101
"Programming Language :: Python :: 3.7",

unicorn_binance_websocket_api/__init__.pyi

Whitespace-only changes.

unicorn_binance_websocket_api/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ def __init__(self,
428428
self.warn_on_update = warn_on_update
429429
if warn_on_update and self.is_update_available():
430430
update_msg = f"Release {self.name}_" + self.get_latest_version() + " is available, " \
431-
f"please consider updating! (Changelog: " \
432-
f"https://unicorn-binance-websocket-api.docs.lucit.tech/changelog.html)"
431+
f"please consider updating! Changelog: " \
432+
f"https://unicorn-binance-websocket-api.docs.lucit.tech/changelog.html"
433433
print(update_msg)
434434
logger.warning(update_msg)
435435
self.restclient = BinanceWebSocketApiRestclient(debug=self.debug,

0 commit comments

Comments
 (0)