Skip to content

Commit 4f2320f

Browse files
authored
Merge pull request #485 from binance/release_clients_january_23
2 parents e06026c + ae94808 commit 4f2320f

118 files changed

Lines changed: 4080 additions & 313 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Before using the SDK, ensure you have:
2020
## Available SDK
2121

2222
- [binance-sdk-algo](./clients/algo) - Algo Trading connector
23+
- [binance-sdk-alpha](./clients/alpha/) - Alpha connector
2324
- [binance-sdk-c2c](./clients/c2c/) - C2C connector
2425
- [binance-sdk-convert](./clients/convert/) - Convert connector
2526
- [binance-sdk-copy-trading](./clients/copy_trading/) - Copy Trading connector

clients/algo/CHANGELOG.md

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

3+
## 2.2.0 - 2026-01-23
4+
5+
### Changed (1)
6+
7+
- Updated `binance-common` library to version `3.4.1`
8+
39
## 2.1.0 - 2026-01-13
410

511
### Changed (1)

clients/algo/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-sdk-algo"
3-
version = "2.1.0"
3+
version = "2.2.0"
44
description = "Official Binance Algo SDK - A lightweight library that provides a convenient interface to Binance's Algo REST API"
55
authors = ["Binance"]
66
license = "MIT"
@@ -20,7 +20,7 @@ black = "^25.1.0"
2020
ruff = "^0.12.0"
2121
pycryptodome = "^3.17"
2222
aiohttp = "^3.9"
23-
binance-common = "3.4.0"
23+
binance-common = "3.4.1"
2424
pytest = { version = ">=6.2.5", optional = true }
2525

2626
[tool.poetry.extras]

clients/alpha/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
build
2+
dist
3+
4+
__pycache__
5+
*.pyc
6+
.tox
7+
.python-version
8+
.DS_Store
9+
poetry.lock
10+
11+
# Environments
12+
.env
13+
.venv
14+
venv/
15+
16+
# IDE
17+
.idea/
18+
.vscode/
19+
20+
# document build
21+
docs/build/
22+
23+
examples/*.ini

clients/alpha/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## 1.0.0 - 2026-01-23
4+
5+
- Initial release

clients/alpha/LICENCE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Binance
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

clients/alpha/README.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# Binance Python Alpha SDK
2+
3+
[![Build Status](https://img.shields.io/github/actions/workflow/status/binance/binance-connector-python/ci.yaml)](https://github.com/binance/binance-connector-python/actions)
4+
[![Open Issues](https://img.shields.io/github/issues/binance/binance-connector-python)](https://github.com/binance/binance-connector-python/issues)
5+
[![Code Style: Black](https://img.shields.io/badge/code_style-black-black)](https://black.readthedocs.io/en/stable/)
6+
[![PyPI version](https://img.shields.io/pypi/v/binance-sdk-alpha)](https://pypi.python.org/pypi/binance-sdk-alpha)
7+
[![PyPI Downloads](https://img.shields.io/pypi/dm/binance-sdk-alpha.svg)](https://pypi.org/project/binance-sdk-alpha/)
8+
[![Python version](https://img.shields.io/pypi/pyversions/binance-sdk-alpha)](https://www.python.org/downloads/)
9+
[![Known Vulnerabilities](https://img.shields.io/badge/security-scanned-brightgreen)](https://github.com/binance/binance-connector-python/security)
10+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
11+
12+
This is a client library for the Binance Alpha API, enabling developers to interact programmatically with Binance Alpha. The library provides tools to access curated early-stage token data, track Alpha project metrics and integrate discovery-focused market information into applications through the REST API:
13+
- [REST API](./src/binance_sdk_alpha/rest_api/rest_api.py)
14+
15+
## Table of Contents
16+
17+
- [Supported Features](#supported-features)
18+
- [Installation](#installation)
19+
- [Documentation](#documentation)
20+
- [REST APIs](#rest-apis)
21+
- [Testing](#testing)
22+
- [Contributing](#contributing)
23+
- [Licence](#licence)
24+
25+
## Supported Features
26+
27+
- REST API Endpoints:
28+
- `/bapi/defi/v1/*`
29+
- Inclusion of test cases and examples for quick onboarding.
30+
31+
## Installation
32+
33+
To use this library, ensure your environment is running Python version **3.9** or later.
34+
35+
```bash
36+
pip install binance-sdk-alpha
37+
```
38+
39+
## Documentation
40+
41+
For detailed information, refer to the [Binance API Documentation](https://developers.binance.com/docs/alpha/Introduction).
42+
43+
### REST APIs
44+
45+
All REST API endpoints are available through the [`rest_api`](./src/binance_sdk_alpha/rest_api/rest_api.py) module. The REST API enables you to fetch market data, manage trades, and access account information. Note that some endpoints require authentication using your Binance API credentials.
46+
47+
```python
48+
import logging
49+
50+
from binance_common.configuration import ConfigurationRestAPI
51+
from binance_common.constants import ALPHA_REST_API_PROD_URL
52+
from binance_sdk_alpha.alpha import Alpha
53+
54+
logging.basicConfig(level=logging.INFO)
55+
configuration = ConfigurationRestAPI(api_key="your-api-key", api_secret="your-api-secret", base_path=ALPHA_REST_API_PROD_URL)
56+
57+
client = Alpha(config_rest_api=configuration)
58+
59+
try:
60+
response = client.rest_api.get_exchange_info()
61+
62+
data = response.data()
63+
logging.info(f"get_exchange_info() response: {data}")
64+
except Exception as e:
65+
logging.error(f"get_exchange_info() error: {e}")
66+
```
67+
68+
More examples can be found in the [`examples/rest_api`](./examples/rest_api/) folder.
69+
70+
#### Configuration Options
71+
72+
The REST API supports the following advanced configuration options:
73+
74+
- `timeout`: Timeout for requests in milliseconds (default: 1000 ms).
75+
- `proxy`: Proxy configuration:
76+
- `host`: Proxy server hostname.
77+
- `port`: Proxy server port.
78+
- `protocol`: Proxy protocol (http or https).
79+
- `auth`: Proxy authentication credentials:
80+
- `username`: Proxy username.
81+
- `password`: Proxy password.
82+
- `keep_alive`: Enable HTTP keep-alive (default: true).
83+
- `compression`: Enable response compression (default: true).
84+
- `retries`: Number of retry attempts for failed requests (default: 3).
85+
- `backoff`: Delay in milliseconds between retries (default: 1000 ms).
86+
- `https_agent`: Custom HTTPS agent for advanced TLS configuration.
87+
- `private_key`: RSA or ED25519 private key for authentication.
88+
- `private_key_passphrase`: Passphrase for the private key, if encrypted.
89+
90+
##### Timeout
91+
92+
You can configure a timeout for requests in milliseconds. If the request exceeds the specified timeout, it will be aborted. See the [Timeout example](./docs/rest_api/timeout.md) for detailed usage.
93+
94+
##### Proxy
95+
96+
The REST API supports HTTP/HTTPS proxy configurations. See the [Proxy example](./docs/rest_api/proxy.md) for detailed usage.
97+
98+
##### Keep-Alive
99+
100+
Enable HTTP keep-alive for persistent connections. See the [Keep-Alive example](./docs/rest_api/keepAlive.md) for detailed usage.
101+
102+
##### Compression
103+
104+
Enable or disable response compression. See the [Compression example](./docs/rest_api/compression.md) for detailed usage.
105+
106+
##### Retries
107+
108+
Configure the number of retry attempts and delay in milliseconds between retries for failed requests. See the [Retries example](./docs/rest_api/retries.md) for detailed usage.
109+
110+
##### HTTPS Agent
111+
112+
Customize the HTTPS agent for advanced TLS configurations. See the [HTTPS Agent example](./docs/rest_api/httpsAgent.md) for detailed usage.
113+
114+
##### Key Pair Based Authentication
115+
116+
The REST API supports key pair-based authentication for secure communication. You can use `RSA` or `ED25519` keys for signing requests. See the [Key Pair Based Authentication example](./docs/rest_api/key-pair-authentication.md) for detailed usage.
117+
118+
##### Certificate Pinning
119+
120+
To enhance security, you can use certificate pinning with the `https_agent` option in the configuration. This ensures the client only communicates with servers using specific certificates. See the [Certificate Pinning example](./docs/rest_api/certificate-pinning.md) for detailed usage.
121+
122+
#### Error Handling
123+
124+
The REST API provides detailed error types to help you handle issues effectively:
125+
126+
- `ClientError`: Represents an error that occurred in the SDK client.
127+
- `RequiredError`: Thrown when a required parameter is missing or undefined.
128+
- `UnauthorizedError`: Indicates missing or invalid authentication credentials.
129+
- `ForbiddenError`: Access to the requested resource is forbidden.
130+
- `TooManyRequestsError`: Rate limit exceeded.
131+
- `RateLimitBanError`: IP address banned for exceeding rate limits.
132+
- `ServerError`: Internal server error, optionally includes a status code.
133+
- `NetworkError`: Issues with network connectivity.
134+
- `NotFoundError`: Resource not found.
135+
- `BadRequestError`: Invalid request or one that cannot be served.
136+
137+
See the [Error Handling example](./docs/rest_api/error-handling.md) for detailed usage.
138+
139+
If `base_path` is not provided, it defaults to `https://www.binance.com`.
140+
141+
## Testing
142+
143+
To run the tests, ensure you have [Poetry](https://python-poetry.org/) installed, then execute the following commands:
144+
145+
```bash
146+
poetry install
147+
poetry run pytest ./tests
148+
```
149+
150+
The tests cover:
151+
* REST API endpoints
152+
* Error handling
153+
* Edge cases
154+
155+
## Contributing
156+
157+
Contributions are welcome!
158+
159+
Since this repository contains auto-generated code, we encourage you to start by opening a GitHub issue to discuss your ideas or suggest improvements. This helps ensure that changes align with the project's goals and auto-generation processes.
160+
161+
To contribute:
162+
163+
1. Open a GitHub issue describing your suggestion or the bug you've identified.
164+
2. If it's determined that changes are necessary, the maintainers will merge the changes into the main branch.
165+
166+
Please ensure that all tests pass if you're making a direct contribution. Submit a pull request only after discussing and confirming the change.
167+
168+
Thank you for your contributions!
169+
170+
## Licence
171+
172+
This project is licensed under the MIT License. See the [LICENCE](./LICENCE) file for details.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Certificate Pinning
2+
3+
```python
4+
import ssl
5+
import base64
6+
import hashlib
7+
8+
from socket import create_connection
9+
from OpenSSL.crypto import dump_publickey, load_certificate, FILETYPE_ASN1
10+
11+
from binance_common.configuration import ConfigurationRestAPI
12+
from binance_sdk_alpha.alpha import Alpha
13+
from binance_sdk_alpha.rest_api.models import GetExchangeInfoResponse
14+
15+
PINNED_PUBLIC_KEY = "YOUR-PINNED-PUBLIC-KEY"
16+
CA_CERT_PATH = "/path/to/certificate.pem"
17+
18+
def verify_certificate(hostname, port=443):
19+
"""Retrieve the certificate, extract the public key, and verify its hash."""
20+
# Establish an SSL connection
21+
context = ssl.create_default_context()
22+
conn = context.wrap_socket(create_connection((hostname, port)), server_hostname=hostname)
23+
24+
# Get the certificate in DER format
25+
der_cert = conn.getpeercert(binary_form=True)
26+
conn.close()
27+
28+
# Convert DER to X.509 certificate
29+
x509 = load_certificate(FILETYPE_ASN1, der_cert)
30+
31+
# Extract public key
32+
pubkey_der = dump_publickey(FILETYPE_ASN1, x509.get_pubkey())
33+
34+
# Compute the SHA-256 hash of the public key
35+
public_key_hash = base64.b64encode(hashlib.sha256(pubkey_der).digest()).decode()
36+
37+
# Validate public key hash against the pinned key
38+
if public_key_hash != PINNED_PUBLIC_KEY:
39+
raise ssl.SSLError(f"Certificate pinning validation failed: expected {PINNED_PUBLIC_KEY}, got {public_key_hash}")
40+
41+
class PinnedSSLContext(ssl.SSLContext):
42+
def __init__(self, hostname):
43+
super().__init__(ssl.PROTOCOL_TLS_CLIENT)
44+
self.verify_mode = ssl.CERT_REQUIRED
45+
self.load_verify_locations(CA_CERT_PATH)
46+
verify_certificate(hostname)
47+
48+
ssl_context = PinnedSSLContext("api.binance.com")
49+
50+
configuration = ConfigurationRestAPI(
51+
api_key="your-api-key",
52+
api_secret="your-api-secret",
53+
https_agent=ssl_context,
54+
)
55+
client = Alpha(config_rest_api=configuration)
56+
57+
try:
58+
response = client.rest_api.get_exchange_info()
59+
data: GetExchangeInfoResponse = response.data()
60+
print(data)
61+
except ssl.SSLError as ssl_err:
62+
print("SSL Certificate validation failed! Possible MITM attack.", ssl_err)
63+
except Exception as err:
64+
print("An error occurred:", err)
65+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Compression Configuration
2+
3+
```python
4+
from binance_common.configuration import ConfigurationRestAPI
5+
from binance_sdk_alpha.alpha import Alpha
6+
from binance_sdk_alpha.rest_api.models import GetExchangeInfoResponse
7+
8+
configuration = ConfigurationRestAPI(
9+
api_key="your-api-key",
10+
api_secret="your-api-secret",
11+
compression=False
12+
)
13+
client = Alpha(config_rest_api=configuration)
14+
15+
try:
16+
response = client.rest_api.get_exchange_info()
17+
data: GetExchangeInfoResponse = response.data()
18+
print(data)
19+
except Exception as e:
20+
print(e)
21+
```

0 commit comments

Comments
 (0)