Webull Rust API
An unofficial Rust library for the Webull API, providing full functionality for trading, market data, and streaming. Because this library uses the webull app API's, Official API key access is not required.
This library is a Rust port of the excellent webull Python library by @tedchou12. The Python library served as the foundation for understanding Webull's API structure and authentication mechanisms.
⚠️ Important Disclaimer
This is an unofficial library that is not affiliated with or endorsed by Webull.
Webull may change their API endpoints, authentication methods, or data structures at any time without notice, which could cause this library to stop working partially or completely. Users of this library should:
- Be prepared for potential breaking changes
- Test thoroughly in paper trading before using with real money
- Implement proper error handling for API failures
- Consider this library experimental and use at your own risk
The maintainers of this library cannot guarantee its continued functionality and are not responsible for any losses incurred from its use.
Features
- ✅ Full authentication support (including MFA)
- ✅ Real trading and paper trading
- ✅ Market data and quotes
- ✅ Order placement and management
- ✅ Real-time streaming via MQTT
- ✅ News and fundamentals
Installation
Add this to your Cargo.toml:
[]
= "1.0.0"
Quick Start
Unified Client Interface
The library provides a unified WebullClient enum that can work with both live and paper trading:
use ;
async
Direct Client Usage
You can also use the specific client implementations directly:
use ;
// For live trading
let mut live_client = new?;
live_client.login.await?;
live_client.get_trade_token.await?; // Your 6-digit trading PIN - Required for placing orders!
// For paper trading
let mut paper_client = new?;
paper_client.login.await?;
// No trade token needed for paper trading
Architecture
The library is organized into three main client types:
WebullClient- A unified enum that provides a common interface for both live and paper tradingLiveWebullClient- Direct implementation for live trading operationsPaperWebullClient- Implementation for paper (simulated) trading
The unified WebullClient enum automatically delegates method calls to the appropriate underlying implementation, making it easy to switch between live and paper trading modes.
Streaming Example
use ;
// Create streaming connection
let config = StreamConfig ;
let mut stream = new;
// Set callbacks
stream.set_price_callback;
// Connect using access token and device ID from login
stream.connect.await?;
// Subscribe to ticker updates
stream.subscribe_ticker.await?;
Environment Variables
Create a .env file:
WEBULL_USERNAME=your_email@example.com
WEBULL_PASSWORD=your_password
WEBULL_TRADING_PIN=123456 # Your 6-digit trading PIN
Examples
See the examples/ directory for more complete examples:
basic_usage.rs- Login, get account info, positions, and quotestrading_test.rs- Interactive trading test with both live and paper supportpaper_trading.rs- Paper trading specific functionalityplace_order.rs- Place and cancel orders with live tradingstreaming.rs- Real-time data streamingset_device_id.rs- Device ID management utilitytest_bars.rs- Historical data retrieval example
Run examples with:
# Interactive trading test (supports both live and paper)
# Paper trading only
Important: Live Trading Requirements
Trade Token
Live trading requires obtaining a trade token before placing any orders. This is a security measure that requires your 6-digit trading PIN (NOT your login password).
// For live trading, get trade token after login
if !client.is_paper
// Now you can place orders
let order_id = client.place_order.await?;
Paper trading does NOT require a trade token - you can place orders immediately after login.
Working with Orders
Getting Current Orders
// Get open orders
let orders = client.get_orders.await?;
for order in orders
Canceling Orders
// Get and cancel all open orders
let orders = client.get_orders.await?;
for order in orders
API Coverage
Account Management
- Login/Logout
- MFA support
- Get account details
- Get positions
- Get orders history
- Get account activities
Trading
- Place orders (stocks)
- Cancel orders
- Modify orders
- Place option orders
- OTOCO orders
Market Data
- Get quotes
- Get bars/candles
- Get Level 2 data
- Search tickers
Streaming
- Real-time quotes
- Order updates
- Trade executions
- Level 2 updates
Analysis
- Get news
- Get analyst ratings
- Screener
- Rankings
Error Handling
The library uses a custom WebullError type for comprehensive error handling:
match client.login.await
License
MIT
Acknowledgements
- @tedchou12 - Creator of the original webull Python library which this Rust implementation is based on. The Python library's clean design and comprehensive API coverage made this port possible.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.