binance-sdk-algo 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- binance_sdk_algo-1.0.0/CHANGELOG.md +5 -0
- binance_sdk_algo-1.0.0/LICENCE +21 -0
- binance_sdk_algo-1.0.0/PKG-INFO +197 -0
- binance_sdk_algo-1.0.0/README.md +170 -0
- binance_sdk_algo-1.0.0/pyproject.toml +40 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/__init__.py +31 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/algo.py +34 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/metadata.py +1 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/__init__.py +13 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/api/__init__.py +12 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/api/future_algo_api.py +426 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/api/spot_algo_api.py +306 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/__init__.py +58 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/cancel_algo_order_future_algo_response.py +112 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/cancel_algo_order_spot_algo_response.py +112 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/enums.py +9 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/query_current_algo_open_orders_future_algo_response.py +129 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/query_current_algo_open_orders_future_algo_response_orders_inner.py +147 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/query_current_algo_open_orders_spot_algo_response.py +127 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/query_current_algo_open_orders_spot_algo_response_orders_inner.py +144 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/query_historical_algo_orders_future_algo_response.py +129 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/query_historical_algo_orders_future_algo_response_orders_inner.py +147 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/query_historical_algo_orders_spot_algo_response.py +127 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/query_historical_algo_orders_spot_algo_response_orders_inner.py +144 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/query_sub_orders_future_algo_response.py +136 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/query_sub_orders_future_algo_response_sub_orders_inner.py +147 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/query_sub_orders_spot_algo_response.py +136 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/time_weighted_average_price_future_algo_response.py +112 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/time_weighted_average_price_spot_algo_response.py +112 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/models/volume_participation_future_algo_response.py +112 -0
- binance_sdk_algo-1.0.0/src/binance_sdk_algo/rest_api/rest_api.py +507 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 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.
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: binance-sdk-algo
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Binance Algo SDK - A lightweight library that provides a convenient interface to Binance's Algo REST API
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Binance
|
|
7
|
+
Requires-Python: >=3.9,<=3.13
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: aiohttp (>=3.9,<4.0)
|
|
17
|
+
Requires-Dist: binance-common (==1.0.0)
|
|
18
|
+
Requires-Dist: black (>=25.1.0,<26.0.0)
|
|
19
|
+
Requires-Dist: pycryptodome (>=3.17,<4.0)
|
|
20
|
+
Requires-Dist: pydantic (>=2.10.0)
|
|
21
|
+
Requires-Dist: pytest (>=6.2.5) ; extra == "dev"
|
|
22
|
+
Requires-Dist: requests (>=2.31.0)
|
|
23
|
+
Requires-Dist: ruff (>=0.12.0,<0.13.0)
|
|
24
|
+
Requires-Dist: websocket-client (>=1.6.3)
|
|
25
|
+
Requires-Dist: websockets (>=15.0.1,<16.0.0)
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# Binance Python Algo SDK
|
|
29
|
+
|
|
30
|
+
[](https://github.com/binance/binance-connector-python/actions)
|
|
31
|
+
[](https://github.com/binance/binance-connector-python/issues)
|
|
32
|
+
[](https://black.readthedocs.io/en/stable/)
|
|
33
|
+
[](https://pypi.python.org/pypi/binance-sdk-algo)
|
|
34
|
+
[](https://pypi.org/project/binance-sdk-algo/)
|
|
35
|
+
[](https://www.python.org/downloads/)
|
|
36
|
+
[](https://github.com/binance/binance-connector-python/security)
|
|
37
|
+
[](https://opensource.org/licenses/MIT)
|
|
38
|
+
|
|
39
|
+
This is a client library for the Binance Algo SDK API, enabling developers to interact programmatically with Binance's Algo trading platform. The library provides tools to programmatically leverage Binance in-house algorithmic trading capability to automate order execution strategy, improve execution transparency and give users smart access to the available market liquidity through the REST API:
|
|
40
|
+
- [REST API](./src/binance_sdk_algo/rest_api/rest_api.py)
|
|
41
|
+
|
|
42
|
+
## Table of Contents
|
|
43
|
+
|
|
44
|
+
- [Supported Features](#supported-features)
|
|
45
|
+
- [Installation](#installation)
|
|
46
|
+
- [Documentation](#documentation)
|
|
47
|
+
- [REST APIs](#rest-apis)
|
|
48
|
+
- [Testing](#testing)
|
|
49
|
+
- [Contributing](#contributing)
|
|
50
|
+
- [Licence](#licence)
|
|
51
|
+
|
|
52
|
+
## Supported Features
|
|
53
|
+
|
|
54
|
+
- REST API Endpoints:
|
|
55
|
+
- `/sapi/v1/algo/*`
|
|
56
|
+
- Inclusion of test cases and examples for quick onboarding.
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
To use this library, ensure your environment is running Python version **3.9** or later.
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install binance-sdk-algo
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Documentation
|
|
67
|
+
|
|
68
|
+
For detailed information, refer to the [Binance API Documentation](https://developers.binance.com/docs/algo/Introduction).
|
|
69
|
+
|
|
70
|
+
### REST APIs
|
|
71
|
+
|
|
72
|
+
All REST API endpoints are available through the [`rest_api`](./src/binance_sdk_algo/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.
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from binance_common.configuration import ConfigurationRestAPI
|
|
76
|
+
from binance_common.constants import ALGO_REST_API_PROD_URL
|
|
77
|
+
from binance_sdk_algo.algo import Algo
|
|
78
|
+
|
|
79
|
+
logging.basicConfig(level=logging.INFO)
|
|
80
|
+
configuration = ConfigurationRestAPI(api_key="your-api-key", api_secret="your-api-secret", base_path=ALGO_REST_API_PROD_URL)
|
|
81
|
+
|
|
82
|
+
client = Algo(config_rest_api=configuration)
|
|
83
|
+
|
|
84
|
+
try:
|
|
85
|
+
response = client.rest_api.query_historical_algo_orders_spot_algo()
|
|
86
|
+
|
|
87
|
+
data = response.data()
|
|
88
|
+
logging.info(f"query_historical_algo_orders_spot_algo() response: {data}")
|
|
89
|
+
except Exception as e:
|
|
90
|
+
logging.error(f"query_historical_algo_orders_spot_algo() error: {e}")
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
More examples can be found in the [`examples/rest_api`](./examples/rest_api/) folder.
|
|
94
|
+
|
|
95
|
+
#### Configuration Options
|
|
96
|
+
|
|
97
|
+
The REST API supports the following advanced configuration options:
|
|
98
|
+
|
|
99
|
+
- `timeout`: Timeout for requests in milliseconds (default: 1000 ms).
|
|
100
|
+
- `proxy`: Proxy configuration:
|
|
101
|
+
- `host`: Proxy server hostname.
|
|
102
|
+
- `port`: Proxy server port.
|
|
103
|
+
- `protocol`: Proxy protocol (http or https).
|
|
104
|
+
- `auth`: Proxy authentication credentials:
|
|
105
|
+
- `username`: Proxy username.
|
|
106
|
+
- `password`: Proxy password.
|
|
107
|
+
- `keep_alive`: Enable HTTP keep-alive (default: true).
|
|
108
|
+
- `compression`: Enable response compression (default: true).
|
|
109
|
+
- `retries`: Number of retry attempts for failed requests (default: 3).
|
|
110
|
+
- `backoff`: Delay in milliseconds between retries (default: 1000 ms).
|
|
111
|
+
- `https_agent`: Custom HTTPS agent for advanced TLS configuration.
|
|
112
|
+
- `private_key`: RSA or ED25519 private key for authentication.
|
|
113
|
+
- `private_key_passphrase`: Passphrase for the private key, if encrypted.
|
|
114
|
+
|
|
115
|
+
##### Timeout
|
|
116
|
+
|
|
117
|
+
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.
|
|
118
|
+
|
|
119
|
+
##### Proxy
|
|
120
|
+
|
|
121
|
+
The REST API supports HTTP/HTTPS proxy configurations. See the [Proxy example](./docs/rest_api/proxy.md) for detailed usage.
|
|
122
|
+
|
|
123
|
+
##### Keep-Alive
|
|
124
|
+
|
|
125
|
+
Enable HTTP keep-alive for persistent connections. See the [Keep-Alive example](./docs/rest_api/keepAlive.md) for detailed usage.
|
|
126
|
+
|
|
127
|
+
##### Compression
|
|
128
|
+
|
|
129
|
+
Enable or disable response compression. See the [Compression example](./docs/rest_api/compression.md) for detailed usage.
|
|
130
|
+
|
|
131
|
+
##### Retries
|
|
132
|
+
|
|
133
|
+
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.
|
|
134
|
+
|
|
135
|
+
##### HTTPS Agent
|
|
136
|
+
|
|
137
|
+
Customize the HTTPS agent for advanced TLS configurations. See the [HTTPS Agent example](./docs/rest_api/httpsAgent.md) for detailed usage.
|
|
138
|
+
|
|
139
|
+
##### Key Pair Based Authentication
|
|
140
|
+
|
|
141
|
+
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.
|
|
142
|
+
|
|
143
|
+
##### Certificate Pinning
|
|
144
|
+
|
|
145
|
+
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.
|
|
146
|
+
|
|
147
|
+
#### Error Handling
|
|
148
|
+
|
|
149
|
+
The REST API provides detailed error types to help you handle issues effectively:
|
|
150
|
+
|
|
151
|
+
- `ClientError`: Represents an error that occurred in the SDK client.
|
|
152
|
+
- `RequiredError`: Thrown when a required parameter is missing or undefined.
|
|
153
|
+
- `UnauthorizedError`: Indicates missing or invalid authentication credentials.
|
|
154
|
+
- `ForbiddenError`: Access to the requested resource is forbidden.
|
|
155
|
+
- `TooManyRequestsError`: Rate limit exceeded.
|
|
156
|
+
- `RateLimitBanError`: IP address banned for exceeding rate limits.
|
|
157
|
+
- `ServerError`: Internal server error, optionally includes a status code.
|
|
158
|
+
- `NetworkError`: Issues with network connectivity.
|
|
159
|
+
- `NotFoundError`: Resource not found.
|
|
160
|
+
- `BadRequestError`: Invalid request or one that cannot be served.
|
|
161
|
+
|
|
162
|
+
See the [Error Handling example](./docs/rest_api/error-handling.md) for detailed usage.
|
|
163
|
+
|
|
164
|
+
If `base_path` is not provided, it defaults to `https://api.binance.com`.
|
|
165
|
+
|
|
166
|
+
## Testing
|
|
167
|
+
|
|
168
|
+
To run the tests, ensure you have [Poetry](https://python-poetry.org/) installed, then execute the following commands:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
poetry install
|
|
172
|
+
poetry run pytest ./tests
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The tests cover:
|
|
176
|
+
* REST API endpoints
|
|
177
|
+
* Error handling
|
|
178
|
+
* Edge cases
|
|
179
|
+
|
|
180
|
+
## Contributing
|
|
181
|
+
|
|
182
|
+
Contributions are welcome!
|
|
183
|
+
|
|
184
|
+
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.
|
|
185
|
+
|
|
186
|
+
To contribute:
|
|
187
|
+
|
|
188
|
+
1. Open a GitHub issue describing your suggestion or the bug you've identified.
|
|
189
|
+
2. If it's determined that changes are necessary, the maintainers will merge the changes into the main branch.
|
|
190
|
+
|
|
191
|
+
Please ensure that all tests pass if you're making a direct contribution. Submit a pull request only after discussing and confirming the change.
|
|
192
|
+
|
|
193
|
+
Thank you for your contributions!
|
|
194
|
+
|
|
195
|
+
## Licence
|
|
196
|
+
|
|
197
|
+
This project is licensed under the MIT License. See the [LICENCE](./LICENCE) file for details.
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# Binance Python Algo SDK
|
|
2
|
+
|
|
3
|
+
[](https://github.com/binance/binance-connector-python/actions)
|
|
4
|
+
[](https://github.com/binance/binance-connector-python/issues)
|
|
5
|
+
[](https://black.readthedocs.io/en/stable/)
|
|
6
|
+
[](https://pypi.python.org/pypi/binance-sdk-algo)
|
|
7
|
+
[](https://pypi.org/project/binance-sdk-algo/)
|
|
8
|
+
[](https://www.python.org/downloads/)
|
|
9
|
+
[](https://github.com/binance/binance-connector-python/security)
|
|
10
|
+
[](https://opensource.org/licenses/MIT)
|
|
11
|
+
|
|
12
|
+
This is a client library for the Binance Algo SDK API, enabling developers to interact programmatically with Binance's Algo trading platform. The library provides tools to programmatically leverage Binance in-house algorithmic trading capability to automate order execution strategy, improve execution transparency and give users smart access to the available market liquidity through the REST API:
|
|
13
|
+
- [REST API](./src/binance_sdk_algo/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
|
+
- `/sapi/v1/algo/*`
|
|
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-algo
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
For detailed information, refer to the [Binance API Documentation](https://developers.binance.com/docs/algo/Introduction).
|
|
42
|
+
|
|
43
|
+
### REST APIs
|
|
44
|
+
|
|
45
|
+
All REST API endpoints are available through the [`rest_api`](./src/binance_sdk_algo/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
|
+
from binance_common.configuration import ConfigurationRestAPI
|
|
49
|
+
from binance_common.constants import ALGO_REST_API_PROD_URL
|
|
50
|
+
from binance_sdk_algo.algo import Algo
|
|
51
|
+
|
|
52
|
+
logging.basicConfig(level=logging.INFO)
|
|
53
|
+
configuration = ConfigurationRestAPI(api_key="your-api-key", api_secret="your-api-secret", base_path=ALGO_REST_API_PROD_URL)
|
|
54
|
+
|
|
55
|
+
client = Algo(config_rest_api=configuration)
|
|
56
|
+
|
|
57
|
+
try:
|
|
58
|
+
response = client.rest_api.query_historical_algo_orders_spot_algo()
|
|
59
|
+
|
|
60
|
+
data = response.data()
|
|
61
|
+
logging.info(f"query_historical_algo_orders_spot_algo() response: {data}")
|
|
62
|
+
except Exception as e:
|
|
63
|
+
logging.error(f"query_historical_algo_orders_spot_algo() error: {e}")
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
More examples can be found in the [`examples/rest_api`](./examples/rest_api/) folder.
|
|
67
|
+
|
|
68
|
+
#### Configuration Options
|
|
69
|
+
|
|
70
|
+
The REST API supports the following advanced configuration options:
|
|
71
|
+
|
|
72
|
+
- `timeout`: Timeout for requests in milliseconds (default: 1000 ms).
|
|
73
|
+
- `proxy`: Proxy configuration:
|
|
74
|
+
- `host`: Proxy server hostname.
|
|
75
|
+
- `port`: Proxy server port.
|
|
76
|
+
- `protocol`: Proxy protocol (http or https).
|
|
77
|
+
- `auth`: Proxy authentication credentials:
|
|
78
|
+
- `username`: Proxy username.
|
|
79
|
+
- `password`: Proxy password.
|
|
80
|
+
- `keep_alive`: Enable HTTP keep-alive (default: true).
|
|
81
|
+
- `compression`: Enable response compression (default: true).
|
|
82
|
+
- `retries`: Number of retry attempts for failed requests (default: 3).
|
|
83
|
+
- `backoff`: Delay in milliseconds between retries (default: 1000 ms).
|
|
84
|
+
- `https_agent`: Custom HTTPS agent for advanced TLS configuration.
|
|
85
|
+
- `private_key`: RSA or ED25519 private key for authentication.
|
|
86
|
+
- `private_key_passphrase`: Passphrase for the private key, if encrypted.
|
|
87
|
+
|
|
88
|
+
##### Timeout
|
|
89
|
+
|
|
90
|
+
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.
|
|
91
|
+
|
|
92
|
+
##### Proxy
|
|
93
|
+
|
|
94
|
+
The REST API supports HTTP/HTTPS proxy configurations. See the [Proxy example](./docs/rest_api/proxy.md) for detailed usage.
|
|
95
|
+
|
|
96
|
+
##### Keep-Alive
|
|
97
|
+
|
|
98
|
+
Enable HTTP keep-alive for persistent connections. See the [Keep-Alive example](./docs/rest_api/keepAlive.md) for detailed usage.
|
|
99
|
+
|
|
100
|
+
##### Compression
|
|
101
|
+
|
|
102
|
+
Enable or disable response compression. See the [Compression example](./docs/rest_api/compression.md) for detailed usage.
|
|
103
|
+
|
|
104
|
+
##### Retries
|
|
105
|
+
|
|
106
|
+
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.
|
|
107
|
+
|
|
108
|
+
##### HTTPS Agent
|
|
109
|
+
|
|
110
|
+
Customize the HTTPS agent for advanced TLS configurations. See the [HTTPS Agent example](./docs/rest_api/httpsAgent.md) for detailed usage.
|
|
111
|
+
|
|
112
|
+
##### Key Pair Based Authentication
|
|
113
|
+
|
|
114
|
+
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.
|
|
115
|
+
|
|
116
|
+
##### Certificate Pinning
|
|
117
|
+
|
|
118
|
+
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.
|
|
119
|
+
|
|
120
|
+
#### Error Handling
|
|
121
|
+
|
|
122
|
+
The REST API provides detailed error types to help you handle issues effectively:
|
|
123
|
+
|
|
124
|
+
- `ClientError`: Represents an error that occurred in the SDK client.
|
|
125
|
+
- `RequiredError`: Thrown when a required parameter is missing or undefined.
|
|
126
|
+
- `UnauthorizedError`: Indicates missing or invalid authentication credentials.
|
|
127
|
+
- `ForbiddenError`: Access to the requested resource is forbidden.
|
|
128
|
+
- `TooManyRequestsError`: Rate limit exceeded.
|
|
129
|
+
- `RateLimitBanError`: IP address banned for exceeding rate limits.
|
|
130
|
+
- `ServerError`: Internal server error, optionally includes a status code.
|
|
131
|
+
- `NetworkError`: Issues with network connectivity.
|
|
132
|
+
- `NotFoundError`: Resource not found.
|
|
133
|
+
- `BadRequestError`: Invalid request or one that cannot be served.
|
|
134
|
+
|
|
135
|
+
See the [Error Handling example](./docs/rest_api/error-handling.md) for detailed usage.
|
|
136
|
+
|
|
137
|
+
If `base_path` is not provided, it defaults to `https://api.binance.com`.
|
|
138
|
+
|
|
139
|
+
## Testing
|
|
140
|
+
|
|
141
|
+
To run the tests, ensure you have [Poetry](https://python-poetry.org/) installed, then execute the following commands:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
poetry install
|
|
145
|
+
poetry run pytest ./tests
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The tests cover:
|
|
149
|
+
* REST API endpoints
|
|
150
|
+
* Error handling
|
|
151
|
+
* Edge cases
|
|
152
|
+
|
|
153
|
+
## Contributing
|
|
154
|
+
|
|
155
|
+
Contributions are welcome!
|
|
156
|
+
|
|
157
|
+
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.
|
|
158
|
+
|
|
159
|
+
To contribute:
|
|
160
|
+
|
|
161
|
+
1. Open a GitHub issue describing your suggestion or the bug you've identified.
|
|
162
|
+
2. If it's determined that changes are necessary, the maintainers will merge the changes into the main branch.
|
|
163
|
+
|
|
164
|
+
Please ensure that all tests pass if you're making a direct contribution. Submit a pull request only after discussing and confirming the change.
|
|
165
|
+
|
|
166
|
+
Thank you for your contributions!
|
|
167
|
+
|
|
168
|
+
## Licence
|
|
169
|
+
|
|
170
|
+
This project is licensed under the MIT License. See the [LICENCE](./LICENCE) file for details.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "binance-sdk-algo"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "Official Binance Algo SDK - A lightweight library that provides a convenient interface to Binance's Algo REST API"
|
|
5
|
+
authors = ["Binance"]
|
|
6
|
+
license = "MIT"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
include = ["CHANGELOG.md", "LICENSE", "README.md"]
|
|
9
|
+
packages = [
|
|
10
|
+
{ include = "binance_sdk_algo", from = "src" }
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
[tool.poetry.dependencies]
|
|
14
|
+
python = ">=3.9,<=3.13"
|
|
15
|
+
requests = ">=2.31.0"
|
|
16
|
+
pydantic = ">=2.10.0"
|
|
17
|
+
websockets = "^15.0.1"
|
|
18
|
+
websocket-client = ">=1.6.3"
|
|
19
|
+
black = "^25.1.0"
|
|
20
|
+
ruff = "^0.12.0"
|
|
21
|
+
pycryptodome = "^3.17"
|
|
22
|
+
aiohttp = "^3.9"
|
|
23
|
+
binance-common = "1.0.0"
|
|
24
|
+
pytest = { version = ">=6.2.5", optional = true }
|
|
25
|
+
|
|
26
|
+
[tool.poetry.extras]
|
|
27
|
+
dev = ["pytest"]
|
|
28
|
+
|
|
29
|
+
[tool.poetry.group.dev.dependencies]
|
|
30
|
+
tox = "^4.27.0"
|
|
31
|
+
pytest = ">=8.4.1"
|
|
32
|
+
pytest-asyncio = "^1.0.0"
|
|
33
|
+
|
|
34
|
+
[tool.ruff]
|
|
35
|
+
exclude = [".git", ".tox", "build", "dist"]
|
|
36
|
+
lint.ignore = ["E741"]
|
|
37
|
+
|
|
38
|
+
[build-system]
|
|
39
|
+
requires = ["poetry-core>=1.0.0"]
|
|
40
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from binance_sdk_algo.algo import Algo
|
|
2
|
+
from binance_common.errors import (
|
|
3
|
+
ClientError,
|
|
4
|
+
RequiredError,
|
|
5
|
+
UnauthorizedError,
|
|
6
|
+
ForbiddenError,
|
|
7
|
+
TooManyRequestsError,
|
|
8
|
+
RateLimitBanError,
|
|
9
|
+
ServerError,
|
|
10
|
+
NetworkError,
|
|
11
|
+
NotFoundError,
|
|
12
|
+
BadRequestError,
|
|
13
|
+
)
|
|
14
|
+
from binance_common.constants import (
|
|
15
|
+
ALGO_REST_API_PROD_URL,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"Algo",
|
|
20
|
+
"ALGO_REST_API_PROD_URL",
|
|
21
|
+
"ClientError",
|
|
22
|
+
"RequiredError",
|
|
23
|
+
"UnauthorizedError",
|
|
24
|
+
"ForbiddenError",
|
|
25
|
+
"TooManyRequestsError",
|
|
26
|
+
"RateLimitBanError",
|
|
27
|
+
"ServerError",
|
|
28
|
+
"NetworkError",
|
|
29
|
+
"NotFoundError",
|
|
30
|
+
"BadRequestError",
|
|
31
|
+
]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import platform
|
|
2
|
+
from importlib.metadata import version
|
|
3
|
+
|
|
4
|
+
from binance_common.configuration import ConfigurationRestAPI
|
|
5
|
+
from binance_common.constants import ALGO_REST_API_PROD_URL
|
|
6
|
+
from . import metadata
|
|
7
|
+
from .rest_api import AlgoRestAPI
|
|
8
|
+
|
|
9
|
+
LIB_NAME = metadata.NAME
|
|
10
|
+
LIB_VERSION = version(LIB_NAME)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Algo:
|
|
14
|
+
"""Algo API that exposes REST APIs in a single interface."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, config_rest_api: ConfigurationRestAPI = None) -> None:
|
|
17
|
+
self._rest_api = None
|
|
18
|
+
self._rest_api_config = (
|
|
19
|
+
ConfigurationRestAPI() if config_rest_api is None else config_rest_api
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def rest_api(self) -> AlgoRestAPI:
|
|
24
|
+
if self._rest_api is None and self._rest_api_config:
|
|
25
|
+
self._rest_api_config.base_headers["User-Agent"] = (
|
|
26
|
+
f"{LIB_NAME}/{LIB_VERSION} (Python/{platform.python_version()}; {platform.system()}; {platform.machine()})"
|
|
27
|
+
)
|
|
28
|
+
self._rest_api_config.base_path = (
|
|
29
|
+
ALGO_REST_API_PROD_URL
|
|
30
|
+
if self._rest_api_config.base_path is None
|
|
31
|
+
else self._rest_api_config.base_path
|
|
32
|
+
)
|
|
33
|
+
self._rest_api = AlgoRestAPI(self._rest_api_config)
|
|
34
|
+
return self._rest_api
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
NAME = "binance-sdk-algo"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Binance Algo REST API
|
|
3
|
+
|
|
4
|
+
OpenAPI Specification for the Binance Algo REST API
|
|
5
|
+
The version of the OpenAPI document: 1.0.0
|
|
6
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
7
|
+
|
|
8
|
+
Do not edit the class manually.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from .rest_api import AlgoRestAPI
|
|
12
|
+
|
|
13
|
+
__all__ = ["AlgoRestAPI"]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Binance Algo REST API
|
|
3
|
+
|
|
4
|
+
OpenAPI Specification for the Binance Algo REST API
|
|
5
|
+
The version of the OpenAPI document: 1.0.0
|
|
6
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
7
|
+
|
|
8
|
+
Do not edit the class manually.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from .future_algo_api import FutureAlgoApi as FutureAlgoApi
|
|
12
|
+
from .spot_algo_api import SpotAlgoApi as SpotAlgoApi
|