{"id":18895633,"url":"https://github.com/binance/binance-spot-connector-rust","last_synced_at":"2025-04-04T20:09:21.797Z","repository":{"id":64312725,"uuid":"574841721","full_name":"binance/binance-spot-connector-rust","owner":"binance","description":"Simple Rust connector to Binance API","archived":false,"fork":false,"pushed_at":"2024-10-31T09:05:41.000Z","size":155,"stargazers_count":166,"open_issues_count":6,"forks_count":44,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-03-28T19:08:18.844Z","etag":null,"topics":["binance-api","connector","crypto","library","market","real-time","rust","spot","trading"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/binance.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-06T07:32:32.000Z","updated_at":"2025-03-23T09:43:59.000Z","dependencies_parsed_at":"2024-11-08T08:30:40.089Z","dependency_job_id":"d529bfae-e5f4-4856-8049-7aeb080e6dfc","html_url":"https://github.com/binance/binance-spot-connector-rust","commit_stats":null,"previous_names":["binance/binance-connector-rust"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-spot-connector-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-spot-connector-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-spot-connector-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-spot-connector-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binance","download_url":"https://codeload.github.com/binance/binance-spot-connector-rust/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247242678,"owners_count":20907134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binance-api","connector","crypto","library","market","real-time","rust","spot","trading"],"created_at":"2024-11-08T08:29:07.764Z","updated_at":"2025-04-04T20:09:21.782Z","avatar_url":"https://github.com/binance.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Binance Public API Connector Rust\n\nThis is a lightweight library that works as a connector to [Binance public API](https://github.com/binance/binance-spot-api-docs)\n\n- Supported APIs:\n  - `/api/*`\n  - `/sapi/*`\n  - Spot Websocket Market Stream\n  - Spot User Data Stream\n- Test cases and examples\n- Customizable base URL and request timeout\n- Blocking and Non-blocking clients\n- Response Metadata\n- Supports HMAC and ED25519 authentications but not RSA authentication.\n\n## RESTful APIs\n\nThe Binance Rust Connector exposes two abstraction layers to integrete with Binance RESTful APIs; a high level\nabstraction consisting of maintained functions mapped one-to-one with Binance API endpoints, and a low level\ngeneric abstraction for more control over the request.\n\n**High Level Usage Example**\n\n```rust\nuse env_logger::Builder;\nuse binance_spot_connector_rust::{\n    http::Credentials,\n    hyper::{BinanceHttpClient, Error},\n    market::{self, klines::KlineInterval},\n    trade\n};\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Error\u003e {\n    Builder::from_default_env()\n        .filter(None, log::LevelFilter::Info)\n        .init();\n\n    let credentials = Credentials::from_hmac(\"api-key\".to_owned(), \"api-secret\".to_owned());\n    let client = BinanceHttpClient::default().credentials(credentials);\n\n    // Get candlesticks for BTCUSDT with a 1 minute interval\n    let data = client.send(market::klines(\"BTCUSDT\", KlineInterval::Minutes1)).await\n        .expect(\"Request failed\")\n        .into_body_str().await\n        .expect(\"Failed to read response body\");\n    log::info!(\"{}\", data);\n\n    // Get the last 10 candlesticks for BTCUSDT with a 1 hour interval\n    let data = client.send(market::klines(\"BTCUSDT\", KlineInterval::Hours1).limit(10)).await\n        .expect(\"Request failed\")\n        .into_body_str().await\n        .expect(\"Failed to read response body\");\n    log::info!(\"{}\", data);\n\n    // Get account information\n    let data = client.send(trade::account()).await\n        .expect(\"Request failed\")\n        .into_body_str().await\n        .expect(\"Failed to read response body\");\n    log::info!(\"{}\", data);\n\n    Ok(())\n}\n```\n\nExamples for other endpoints are available in the `examples` folder.\n\n**Low Level Usage Example**\n\n```rust\nuse binance_spot_connector_rust::{\n    http::{request::RequestBuilder, Method},\n    hyper::{BinanceHttpClient, Error},\n};\nuse env_logger::Builder;\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Error\u003e {\n    Builder::from_default_env()\n        .filter(None, log::LevelFilter::Info)\n        .init();\n\n    let client = BinanceHttpClient::default();\n\n    let builder = RequestBuilder::new(Method::Get, \"/api/v3/klines\")\n        .params(vec![(\"symbol\", \"BTCUSDT\"), (\"interval\", \"1m\")]);\n\n    // Get candlesticks for BTCUSDT with a 1 minute interval\n    let data = client\n        .send(builder)\n        .await\n        .expect(\"Request failed\")\n        .into_body_str()\n        .await\n        .expect(\"Failed to read response body\");\n    log::info!(\"{}\", data);\n\n    Ok(())\n}\n```\n\n## Websocket\n\n```rust\nuse binance_spot_connector_rust::{\n    market::klines::KlineInterval, market_stream::kline::KlineStream,\n    tokio_tungstenite::BinanceWebSocketClient,\n};\nuse std::time::Duration;\nuse env_logger::Builder;\nuse futures_util::StreamExt;\n\n#[tokio::main]\nasync fn main() {\n    Builder::from_default_env()\n        .filter(None, log::LevelFilter::Info)\n        .init();\n    // Establish connection\n    let (mut conn, _) = BinanceWebSocketClient::connect_async_default()\n        .await\n        .expect(\"Failed to connect\");\n    // Subscribe to streams\n    conn.subscribe(vec![\n        \u0026KlineStream::new(\"BTCUSDT\", KlineInterval::Minutes1).into()\n    ])\n    .await;\n    // Start a timer for 10 seconds\n    let timer = tokio::time::Instant::now();\n    let duration = Duration::new(10, 0);\n    // Read messages\n    while let Some(message) = conn.as_mut().next().await {\n        if timer.elapsed() \u003e= duration {\n            log::info!(\"10 seconds elapsed, exiting loop.\");\n            break; // Exit the loop after 10 seconds\n        }\n        match message {\n            Ok(message) =\u003e {\n                let binary_data = message.into_data();\n                let data = std::str::from_utf8(\u0026binary_data).expect(\"Failed to parse message\");\n                log::info!(\"{:?}\", data);\n            }\n            Err(_) =\u003e break,\n        }\n    }\n    // Disconnect\n    conn.close().await.expect(\"Failed to disconnect\");\n}\n\n```\n\nExamples for other websocket streams are available in the `examples` folder.\n\n### Heartbeat\n\nOnce connected, the websocket server sends a ping frame every 3 minutes and requires a response pong frame back within\na 10 minutes period. This package handles the pong responses automatically.\n\n### Testnet\n\n`/api/*` endpoints can be tested in [Spot Testnet](https://testnet.binance.vision/). `/sapi/*` endpoints are not supported.\n\n```rust\nlet client = BinanceHttpClient::with_url(\"https://testnet.binance.vision\");\n```\n\n### Base URL\n\nIt's recommended to pass in the `baseUrl` parameter, even in production as Binance provides alternative URLs\nin case of performance issues:\n\n- `https://api1.binance.com`\n- `https://api2.binance.com`\n- `https://api3.binance.com`\n\n### Timeout\n\nThe default timeout is 100,000 milliseconds (100 seconds).\n\n### Logging\n\nThis library implements the standard rust logging framework which works with a variety of built-in and third-party logging providers.\n\nFor more information on how to configure logging in Rust, visit [Rust Log](https://docs.rs/log/latest/log/)\n\n**Usage Example**\n\n```rust\nuse binance_spot_connector_rust::{\n    http::Credentials,\n    hyper::{BinanceHttpClient, Error},\n    wallet,\n};\nuse env_logger::Builder;\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Error\u003e {\n    Builder::from_default_env()\n        .filter(None, log::LevelFilter::Debug)\n        .init();\n\n    let credentials = Credentials::from_hmac(\"api-key\".to_owned(), \"api-secret\".to_owned());\n    let client = BinanceHttpClient::default().credentials(credentials);\n\n    // Get candlesticks for BTCUSDT with a 1 minute interval\n    let data = client\n        .send(wallet::system_status())\n        .await\n        .expect(\"Request failed\")\n        .into_body_str()\n        .await\n        .expect(\"Failed to read response body\");\n\n    Ok(())\n}\n```\n\n**Sample Output**\n\n```\n[2022-02-22T00:00:00Z DEBUG binance_spot_connector_rust::hyper::client] https://api.binance.com/sapi/v1/system/status\n[2022-02-22T00:00:00Z DEBUG binance_spot_connector_rust::hyper::client] 200 OK\n[2022-02-22T00:00:00Z INFO  binance_spot_connector_rust::hyper::client] {\"status\":0,\"msg\":\"normal\"}\n```\n\n## Test Cases\n\n```bash\ncargo test\n```\n\n## Examples\n\nAll snippets for spot endpoints and streams can be found in the `examples` folder. Example names are a concatanation of the example directory name and the example file name separated by an underscore.\n\n```bash\ncd examples \u0026\u0026 cargo run --example market_exchange_info\n```\n\n## Limitations\n\nFutures and Vanilla Options APIs are not supported:\n\n- /fapi/\\*\n- /dapi/\\*\n- /vapi/\\*\n- Associated Websocket Market and User Data Streams\n\n## Contributing\n\nContributions are welcome.\n\nIf you've found a bug within this project, please open an issue to discuss what you would like to change.\n\nIf it's an issue with the API, please open a topic at [Binance Developer Community](https://dev.binance.vision)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinance%2Fbinance-spot-connector-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinance%2Fbinance-spot-connector-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinance%2Fbinance-spot-connector-rust/lists"}