Skip to content

Commit d1fc416

Browse files
authored
Merge pull request #396 from binance/release_common_v1.1.0
Release Common v1.1.0
2 parents e707698 + ae52305 commit d1fc416

File tree

9 files changed

+131
-210
lines changed

9 files changed

+131
-210
lines changed

.github/workflows/ci.yaml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- master
7+
workflow_dispatch:
78

89
jobs:
910
detect-clients:
@@ -28,22 +29,19 @@ jobs:
2829
strategy:
2930
matrix:
3031
client: ${{ fromJson(needs.detect-clients.outputs.clients) }}
31-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
32-
poetry-version: ["latest", "main", "1.8.4"]
32+
python-version: ["3.12"]
33+
poetry-version: ["1.8.4"]
3334

3435
steps:
3536
- name: Checkout code
3637
uses: actions/checkout@v4
3738

38-
- name: Set up Python ${{ matrix.python-version }}
39-
uses: actions/setup-python@v5
40-
with:
41-
python-version: ${{ matrix.python-version }}
42-
43-
- name: Install poetry
44-
uses: abatilo/actions-poetry@v3
45-
with:
46-
poetry-version: ${{ matrix.poetry-version }}
39+
- name: Install dependencies
40+
run: |
41+
pip3 install --upgrade pip && \
42+
pip3 install ruff black && \
43+
curl -sSL https://install.python-poetry.org | python3 -
44+
echo "$HOME/.local/bin" >> $GITHUB_PATH
4745
4846
- name: Build ${{ matrix.client }} client
4947
run: |

.github/workflows/release.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Release Python Connector
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
9+
jobs:
10+
detect-clients:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
clients: ${{ steps.detect.outputs.clients }}
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v3
17+
18+
- name: Detect all clients
19+
id: detect
20+
run: |
21+
ALL_CLIENTS=$(ls -d clients/*/ | xargs -n 1 basename | jq -R -s -c 'split("\n")[:-1]')
22+
echo "Detected clients: $ALL_CLIENTS"
23+
echo "clients=$ALL_CLIENTS" >> $GITHUB_ENV
24+
echo "::set-output name=clients::$ALL_CLIENTS"
25+
26+
release:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
32+
- name: Compare versions
33+
id: version
34+
run: |
35+
if [ "${{ matrix.client }}" == "common" ]; then
36+
cd common
37+
else
38+
cd clients/${{ matrix.client }}
39+
fi
40+
41+
old_version=$(git show HEAD^:pyproject.toml | grep '^version' | head -1 | sed -E 's/version = "(.*)"/\1/')
42+
new_version=$(grep '^version' pyproject.toml | head -1 | sed -E 's/version = "(.*)"/\1/')
43+
44+
if [ "$old_version" = "$new_version" ]; then
45+
echo "::error ::Version was not bumped in pyproject.toml — skipping release"
46+
exit 1
47+
fi
48+
49+
- name: Set working directory path
50+
id: path
51+
run: echo "dir=$([[ '${{ matrix.client }}' == 'common' ]] && echo 'common' || echo 'clients/${{ matrix.client }}')" >> $GITHUB_OUTPUT
52+
53+
- name: Install dependencies
54+
working-directory: ${{ steps.path.outputs.dir }}
55+
run: |
56+
curl -sSL https://install.python-poetry.org | python3 -
57+
echo "$HOME/.local/bin" >> $GITHUB_PATH
58+
59+
- name: Configure Poetry
60+
working-directory: ${{ steps.path.outputs.dir }}
61+
run: |
62+
poetry install
63+
if [ "${{ matrix.client }}" == "common" ]; then
64+
poetry config pypi-token.pypi ${{ secrets.PYPI_COMMON_TOKEN }}
65+
else
66+
poetry config pypi-token.pypi ${{ secrets.PYPI_CLIENTS_TOKEN }}
67+
fi
68+
69+
- name: Build (release)
70+
working-directory: ${{ steps.path.outputs.dir }}
71+
run: poetry build
72+
73+
- name: Publish to pypi
74+
working-directory: ${{ steps.path.outputs.dir }}
75+
run: poetry publish --build

.github/workflows/sync-private-public.yaml

Lines changed: 0 additions & 192 deletions
This file was deleted.

common/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 1.1.0 - 2025-08-06
4+
5+
### Changed (2)
6+
7+
- Updated `list_subscribe` method `json_msg` format and response.
8+
- Added Enum serialization in `utils.py` to handle Enum values.
9+
310
## 1.0.0 - 2025-01-16
411

512
First release

common/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Code Style: Black](https://img.shields.io/badge/code_style-black-black)](https://black.readthedocs.io/en/stable/)
44
[![PyPI version](https://img.shields.io/pypi/v/binance-common)](https://pypi.python.org/pypi/binance-common)
55
[![PyPI Downloads](https://img.shields.io/pypi/dm/binance-common.svg)](https://pypi.org/project/binance-common/)
6-
[![Python version](https://img.shields.io/pypi/pyversions/binance-connector)](https://www.python.org/downloads/)
6+
[![Python version](https://img.shields.io/pypi/pyversions/binance-common)](https://www.python.org/downloads/)
77
[![Known Vulnerabilities](https://img.shields.io/badge/security-scanned-brightgreen)](https://github.com/binance/binance-connector-python/security)
88
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
99

common/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "binance-common"
3-
version = "1.0.0"
3+
version = "1.1.0"
44
description = "Binance Common Types and Utilities for Binance Connectors"
55
authors = ["Binance"]
66
license = "MIT"
@@ -11,7 +11,7 @@ packages = [
1111
]
1212

1313
[tool.poetry.dependencies]
14-
python = ">=3.9,<=3.13"
14+
python = ">=3.9,<=3.14"
1515
requests = ">=2.31.0"
1616
pydantic = ">=2.10.0"
1717
websockets = "^15.0.1"

common/src/binance_common/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from base64 import b64encode
1212
from Crypto.Hash import SHA256
1313
from Crypto.Signature.pkcs1_15 import PKCS115_SigScheme
14+
from enum import Enum
1415
from pydantic import BaseModel
1516
from typing import Dict, List, Optional, Type, TypeVar, Union
1617
from urllib.parse import urlencode
@@ -119,6 +120,8 @@ def make_serializable(val) -> Union[dict, list, str, int, float, bool]:
119120
return [v.__dict__ if hasattr(v, '__dict__') else v for v in val]
120121
if isinstance(val, bool):
121122
return str(val).lower()
123+
if isinstance(val , Enum):
124+
return val.value
122125
return val
123126

124127

common/src/binance_common/websocket.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,12 +498,24 @@ async def unsubscribe(self, streams: list[str]):
498498
else:
499499
raise ValueError(f"Stream {stream} not connected.")
500500

501-
async def list_subscribe(self):
502-
"""List all subscriptions."""
501+
async def list_subscribe(self) -> dict:
502+
"""List all subscriptions.
503+
504+
Returns:
505+
dict: Current subscriptions.
506+
"""
503507

504508
for connection in self.connections:
505-
json_msg = json.dumps({"method": "LIST_SUBSCRIPTIONS", "id": get_uuid()})
506-
await self.send_message(json_msg, connection)
509+
json_msg = {"method": "LIST_SUBSCRIPTIONS", "id": get_uuid()}
510+
future = await self.send_message(json_msg, connection)
511+
try:
512+
response = await asyncio.wait_for(future, timeout=20)
513+
logging.info(f"Current subscriptions: {response}")
514+
return response
515+
except asyncio.TimeoutError:
516+
logging.warning(
517+
f"Timeout waiting for response to LIST_SUBSCRIPTIONS for connection {connection.id}"
518+
)
507519

508520
async def ping_ws_stream(self, connection: WebSocketConnection):
509521
"""Send a ping message to the WebSocket server.

0 commit comments

Comments
 (0)