| Crates.io | webull-rs |
| lib.rs | webull-rs |
| version | 0.1.1 |
| created_at | 2025-04-22 04:37:33.891986+00 |
| updated_at | 2025-04-22 09:30:40.033737+00 |
| description | A Rust client for the Webull trading API |
| homepage | https://github.com/wszzsw/webull-rs |
| repository | https://github.com/wszzsw/webull-rs |
| max_upload_size | |
| id | 1643623 |
| size | 295,031 |
A Rust client for the Webull trading API.
webull-rs is a Rust crate that provides a robust, type-safe, and idiomatic interface to the Webull trading API. It enables developers to build trading applications, algorithms, and bots in Rust.
Add this to your Cargo.toml:
[dependencies]
webull-rs = "0.1.0"
tokio = { version = "1", features = ["full"] }
use webull_rs::{WebullClient, OrderSide, OrderType, TimeInForce, OrderRequest};
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a client
let client = WebullClient::builder()
.with_api_key("your-api-key")
.with_api_secret("your-api-secret")
.with_timeout(Duration::from_secs(30))
.build()?;
// Login to Webull
client.login("username", "password").await?;
// Get account information
let accounts = client.accounts().get_accounts().await?;
println!("Found {} accounts", accounts.len());
// Get real-time quote
let quote = client.market_data().get_quote("AAPL").await?;
println!("AAPL current price: ${}", quote.last_price);
// Place an order
let order_request = OrderRequest::market()
.symbol("AAPL")
.side(OrderSide::Buy)
.quantity(1.0)
.time_in_force(TimeInForce::Day);
let order = client.orders().place_order(order_request).await?;
println!("Order placed: {}", order.id);
// Logout
client.logout().await?;
Ok(())
}
The crate includes several examples to help you get started:
To run an example:
cargo run --example account
The crate is organized into several modules:
client: The main WebullClient and builderauth: Authentication and token managementendpoints: API endpoints for different domainsmodels: Data models for API requests and responsesstreaming: WebSocket client for streaming datautils: Utility functions and helpersuse webull_rs::{WebullClient, WebullError};
use webull_rs::utils::credentials::EncryptedCredentialStore;
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a credential store
let credential_store = EncryptedCredentialStore::new(
"credentials.json".to_string(),
"token.json".to_string(),
"my-secret-key".to_string(),
);
// Create a client with the credential store
let client = WebullClient::builder()
.with_api_key("your-api-key")
.with_api_secret("your-api-secret")
.with_credential_store(credential_store)
.build()?;
// Login to Webull
client.login("username", "password").await?;
// Credentials are now securely stored
// ...
Ok(())
}
use webull_rs::{WebullClient, WebullError};
use webull_rs::streaming::events::EventType;
use webull_rs::streaming::subscription::SubscriptionRequest;
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a client
let client = WebullClient::builder()
.with_api_key("your-api-key")
.with_api_secret("your-api-secret")
.build()?;
// Login to Webull
client.login("username", "password").await?;
// Create a WebSocket client
let mut ws_client = client.streaming();
// Connect to the WebSocket server
ws_client.connect().await?;
// Subscribe to quote updates for AAPL
let subscription = SubscriptionRequest::new()
.add_symbol("AAPL")
.add_event_type(EventType::QuoteUpdate);
ws_client.subscribe(subscription).await?;
// Listen for events
while let Some(event) = ws_client.next_event().await {
println!("Received event: {:?}", event);
}
// Disconnect
ws_client.disconnect().await?;
Ok(())
}
For detailed documentation, see docs.rs/webull-rs.
For a comprehensive getting started guide, see GETTING_STARTED.md.
Contributions are welcome! Please see CONTRIBUTING.md for details.
Please see SECURITY.md for security policies and best practices.
See CHANGELOG.md for a list of changes in each release.
This project is licensed under the MIT License - see the LICENSE file for details.