This module provides the official Rust client for Binance's Algo Trading REST API, enabling developers to interact programmatically with Binance's Algo trading platform. The module 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:
- Supported Features
- Installation
- Documentation
- REST APIs
- Logging
- Testing
- Migration Guide
- Contributing
- License
- REST API Endpoints:
/sapi/v1/algo/*
- Inclusion of test cases and examples for quick onboarding.
Enable the algo feature in your Cargo.toml under binance-sdk:
[dependencies]
binance-sdk = { version = "1.0.0", features = ["algo"] }In your code, import the algo client:
use binance_sdk::algo;- Crate documentation: docs.rs/binance_sdk
- Official Binance Algo API docs: Binance API Documentation
All REST API endpoints are available through the rest_api module. Note that some endpoints require authentication using your Binance API credentials.
use binance_sdk::config::ConfigurationRestApi;
use binance_sdk::algo;
let configuration = ConfigurationRestApi::builder()
.api_key("YOUR_API_KEY")
.api_secret("YOUR_SECRET_KEY")
.build()?;
let client = algo::AlgoRestApi::production(configuration);
let params = algo::rest_api::QueryHistoricalAlgoOrdersSpotAlgoParams::default();
let response = client.query_historical_algo_orders_spot_algo(params).await?;
let data = response.data().await?;
println!("{:#?}", data);The algo module can be configured with the following options via the ConfigurationRestApi builder pattern:
timeout(u64): Request timeout in milliseconds (default: 1000)proxy(ProxyConfig): HTTP/HTTPS proxy settingshost(String): Proxy server hostname.port(u16): Proxy server port.protocol(String): Proxy protocol (http or https).auth(ProxyAuth): Proxy authentication credentials:username(String): Proxy username.password(String): Proxy password.
keep_alive(bool): Enable HTTP keep-alive (default: true)compression(bool): Enable response compression (default: true)retries(u32): Number of retry attempts for failed requests (default: 3)backoff(u64): Delay in milliseconds between retries (default: 1000)agent(HttpAgent): Custom HTTP agent for advanced TLS configurationprivate_key(PrivateKey): RSA or ED25519 private key for request signing (raw string or PEM file path)private_key_passphrase(String): Passphrase for the private key, if encrypted
Refer to the configuration for more details.
You can configure a timeout for requests in milliseconds. If the request exceeds the specified timeout, it will be aborted. See the Timeout example for detailed usage.
The REST API supports HTTP/HTTPS proxy configurations. See the Proxy example for detailed usage.
Enable HTTP keep-alive for persistent connections. See the Keep-Alive example for detailed usage.
Enable or disable response compression. See the Compression example for detailed usage.
Configure the number of retry attempts and delay in milliseconds between retries for failed requests. See the Retries example for detailed usage.
Customize the HTTPS agent for advanced TLS configurations. See the HTTPS Agent example for detailed usage.
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 for detailed usage.
To enhance security, you can use certificate pinning with the agent option in the configuration. This ensures the client only communicates with servers using specific certificates. See the Certificate Pinning example for detailed usage.
Errors are represented by the following types:
ConnectorClientError: General client errorUnauthorizedError: Invalid or missing authenticationForbiddenError: Access to resource forbiddenTooManyRequestsError: Rate limit exceededRateLimitBanError: IP banned due to rate limitsServerError: Internal server errorNetworkError: Network connectivity issuesNotFoundError: Resource not foundBadRequestError: Invalid request parameters
See the Error Handling example for detailed usage. Refer to the error module for more information.
This crate ships with an optional default logger that you can enable with a single call:
use binance_sdk::logger;
fn main() {
// Initialize the default logger once at the start of your application
logger::init();
// ... rest of your code
}The logger integrates with the Rust tracing ecosystem and behaves as follows:
- If another global subscriber is already set,
logger::init()is a no-op and does not override your existing logging setup. - If no subscriber is set yet, it installs the crate’s default global subscriber (with sensible defaults) so you immediately get structured logs from the connector.
To run the tests for the Algo module:
cargo test --features algoTests cover:
- REST API endpoint integration
- Error scenarios and edge cases
If you are upgrading from a legacy, single-crate connector that included Algo support, see the Migration Guide for instructions on enabling the algo feature.
Contributions are welcome!
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.
To contribute:
- Open a GitHub issue describing your suggestion or the bug you've identified.
- If it's determined that changes are necessary, the maintainers will merge the changes into the main branch.
Please ensure that all tests pass with --features algo if you're making a direct contribution. Submit a pull request only after discussing and confirming the change.
Thank you for your contributions!
This project is licensed under the MIT License. See the LICENSE file for details.