| Crates.io | binance_connector |
| lib.rs | binance_connector |
| version | 0.1.1 |
| created_at | 2025-01-06 18:54:01.769816+00 |
| updated_at | 2025-01-07 13:16:58.201286+00 |
| description | A Rust library for interacting with the Binance API |
| homepage | |
| repository | https://github.com/EnosDomingues/binance_connector |
| max_upload_size | |
| id | 1505996 |
| size | 59,494 |
A Rust-based connector for interacting with the Binance API, designed to facilitate trading operations and data retrieval for cryptocurrency markets.
Binance Connector is a Rust library that provides a simple interface for interacting with the Binance cryptocurrency exchange's REST API. It aims to simplify the process of executing trades, querying market data, and managing accounts on Binance through a Rust application.
Note: As of the current version, this project only supports creating orders for the BTCUSDT pair on Binance Futures.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Rust (stable version, use rustup to manage your Rust version)
Cargo, Rust's package manager
Tokio runtime for asynchronous programming
A .env file in the root of your project with your Binance API credentials:
# BINANCE
# Your Binance API Key
BINANCE_API_KEY='type your api key here'
# Your Binance API Secret
BINANCE_API_SECRET='type your api secret here'
Clone the repo:
git clone https://github.com/EnosDomingues/binance_connector.git
Navigate to the project directory:
cd binance_connector
Build and run the project:
cargo build
cargo run
Cargo.tomlTo use the Binance Connector library, you'll need to add the required dependencies to your Cargo.toml file. Below is the required configuration:
[dependencies]
binance_connector = "0.1.0" # Replace with the latest version
tokio = { version = "1", features = ["full"] }
dotenv = "0.15" # For loading environment variables from .env
The following example demonstrates how to create a futures limit order on Binance using the Binance Connector library.
⚠️ Important: This example is specifically for Binance Futures. Ensure you have Futures permissions enabled for your API Key.
use binance_connector::core::create_order;
use std::error::Error as StdError;
#[tokio::main]
async fn main() -> Result<(), Box<dyn StdError>> {
// Create a new limit order to buy 0.002 BTC at a price of 80,000 USDT on Binance Futures
create_order(binance_connector::types::core::OrderDetails {
side: String::from("BUY"), // Order side: BUY or SELL
order_type: String::from("LIMIT"), // Order type: LIMIT, MARKET, etc.
quantity: 0.002, // Quantity of the asset to trade
price: Some(80000.0), // Limit price for the order
time_in_force: Some(String::from("GTX")), // Time in force: GTC, GTX, etc.
reduce_only: Some(true), // Optional: Reduce-only flag for the order
}).await?;
Ok(())
}