A comprehensive, high-performance Julia SDK for Binance Spot Trading APIs.
Binance.jl provides complete access to Binance's trading infrastructure:
- REST API for account management and trading operations
- WebSocket streams for real-time market data (JSON and high-performance SBE binary)
- WebSocket API for interactive real-time trading
- OrderBookManager for local order book with sub-millisecond access
- Recent Updates
- Features
- Installation
- Quick Start
- Documentation
- Examples
- Architecture
- Contributing
- License
- Price Range Execution Rules - New REST, WebSocket API, and stream endpoints
get_execution_rules/get_reference_price/get_reference_price_calculationsubscribe_reference_pricefor real-time reference price streams
serverShutdownWebSocket event with automatic reconnection warningexpiryReasonfield inExecutionReportuser data stream events- SBE schema 3:3 and FIX SBE schema 1:1 support
- stunnel SNI/TLS hardening for FIX connections
- SBE decoder resilience - Unknown SBE template IDs now log a warning instead of crashing the stream connection
Complete version history: CHANGELOG.md
| Feature | Description |
|---|---|
| REST API | All Spot Account and Trading endpoints |
| WebSocket Streams | Real-time market data (ticker, kline, depth, trades) |
| SBE Streams | High-performance binary market data (60-70% less bandwidth) |
| WebSocket API | Interactive real-time trading with heartbeat |
| OrderBookManager | Local order book with < 1ms latency access |
| Convert API | Limit orders and quotes for token conversion |
| Authentication | Ed25519, RSA, and HMAC-SHA256 signature support |
| Rate Limiting | Automatic compliance with Binance limits |
| Error Handling | Comprehensive error types and recovery |
- General: Ping, Server Time, Exchange Info
- Market Data: Order Book, Trades (Recent/Historical/Aggregate), Klines, Tickers, Prices
- Spot Trading: Orders (Place/Cancel/Status), OCO Orders, Account Info, Order History, Rate Limits
- Strategy Helpers: Real-time trade strategy helpers with colored order book display
- Real-time Data: Tickers, Klines, Depth, Aggregate Trades
- All Market Symbols: Support for individual and combined streams
- Connection Management: Auto-reconnect with heartbeat, ping/pong handling
- Binary Encoding: 60-70% less bandwidth than JSON
- Complete Decoder: All 4 message types (Trade, BestBidAsk, Depth, DepthSnapshot)
- Low Latency: 30-50% lower latency vs JSON streams
- Convenience Functions: Subscribe/unsubscribe for all stream types
- Auto-Reconnect: Automatic reconnection with detailed error diagnostics
- Local Order Book: Continuously-synchronized with automatic WebSocket + REST sync
- Near-Zero Latency: < 1ms access (vs 20-100ms for REST/WebSocket)
- Deep Market: Up to 5000 price levels
- Built-in Analytics: VWAP calculation and depth imbalance analysis
- Auto-Recovery: Automatic reconnection and resynchronization
- Session Management: Logon, Status, Logout
- Trading Operations: Place/Cancel/Modify orders with full validation
- Order Lists: OCO/OTO/OTOCO support
- Account Queries: Balances, Orders, Execution Reports, Commission Rates
- Smart Order Routing: SOR orders for optimized execution
- User Data Streams: Real-time account updates
- Margin Account and Trading
- Futures API support
- Sub-account Management
- Advanced SAPI Endpoints (Savings, Mining, BLVT, BSwap, Fiat)
- Enhanced WebSocket User Data Event parsing
- Performance optimizations and benchmarks
using Pkg
Pkg.add("https://github.com/rzhli/Binance.jl.git")Create config.toml from the example:
cp config_example.toml config.tomlEdit with your credentials:
[api]
api_key = "YOUR_API_KEY"
secret_key = "YOUR_SECRET_KEY"
# For WebSocket API and SBE streams
signature_method = "ED25519"
private_key_path = "key/ed25519-private.pem"
private_key_pass = "YOUR_PASSWORD"
[connection]
testnet = false
proxy = "" # Optional: "http://127.0.0.1:7890"See config_example.toml for all options.
using Binance
# Create clients
rest_client = RESTClient()
stream_client = MarketDataStreamClient()
ws_client = WebSocketClient()
# Get market data
server_time = get_server_time(rest_client)
account = get_account_info(rest_client)
# Place order (use String or DecimalPrice for exact precision)
order = place_order(rest_client, "BTCUSDT", "BUY", "LIMIT";
quantity="0.001", price="60000.0", timeInForce="GTC")📖 More examples: examples/examples.jl
| Module | Description | Documentation |
|---|---|---|
| OrderBookManager | Local order book with < 1ms latency | docs/OrderBookManager.md |
| SBE Streams | High-performance binary market data | docs/SBE.md |
Decimal Precision:
# Use String or DecimalPrice for exact values (avoids floating-point errors)
quantity = "0.001"
price = DecimalPrice("60000.00")REST API:
rest_client = RESTClient()
server_time = get_server_time(rest_client)
account = get_account_info(rest_client)
order = place_order(rest_client, "BTCUSDT", "BUY", "LIMIT";
quantity="0.001", price="60000.0", timeInForce="GTC")WebSocket Market Streams:
stream_client = MarketDataStreamClient()
subscribe_ticker(stream_client, "BTCUSDT", data -> println(data))
subscribe_kline(stream_client, "BTCUSDT", "1h", data -> println(data))WebSocket API (Interactive Trading):
ws_client = WebSocketClient()
connect!(ws_client)
session_logon(ws_client)
place_order(ws_client, "BTCUSDT", "BUY", "LIMIT";
quantity="0.001", price="60000.0")SBE Streams (High Performance):
sbe_client = SBEStreamClient()
connect_sbe!(sbe_client)
sbe_subscribe_trade(sbe_client, "BTCUSDT", event -> println(event))
sbe_close_all(sbe_client)| File | Description |
|---|---|
examples/orderbook_basic.jl |
OrderBookManager basic usage |
examples/orderbook_advanced.jl |
Advanced OrderBookManager with analytics |
examples/sbe_stream_example.jl |
SBE binary streams usage |
examples/examples.jl |
General REST API, WebSocket streams examples |
Binance.jl/
├── src/
│ │
│ │ # Core Module
│ ├── Binance.jl # Main module with exports
│ │
│ │ # Configuration & Authentication
│ ├── Config.jl # Configuration management (TOML parsing)
│ ├── Signature.jl # Authentication (Ed25519, RSA, HMAC)
│ │
│ │ # REST API
│ ├── RESTAPI.jl # REST endpoints implementation
│ ├── Account.jl # Account-related utilities
│ ├── RateLimiter.jl # API rate limiting logic
│ │
│ │ # WebSocket Streams (JSON)
│ ├── MarketDataStreams.jl # WebSocket market data streams
│ ├── WebSocketAPI.jl # Interactive WebSocket API
│ ├── OrderBookManager.jl # Local order book management
│ │
│ │ # SBE Streams (Binary)
│ ├── SBEMarketDataStreams.jl # SBE market data streams
│ ├── SBEDecoder.jl # SBE binary message decoder
│ │
│ │ # Data Types & Utilities
│ ├── Types.jl # Data models and structs
│ ├── Events.jl # WebSocket event types
│ ├── Filters.jl # Order validation filters
│ └── Errors.jl # Custom error types
│
├── BinanceFIX/ # FIX Protocol SDK (sub-package)
│ ├── Project.toml
│ ├── src/
│ │ ├── BinanceFIX.jl # Main FIX module
│ │ ├── FIXAPI.jl # FIX session and order entry
│ │ ├── FIXConstants.jl # FIX field tags and constants
│ │ └── FIXSBEDecoder.jl # FIX SBE binary decoder
│ ├── test/ # FIX test suite
│ └── examples/ # FIX usage examples
│
├── docs/
│ ├── OrderBookManager.md # OrderBookManager documentation
│ └── SBE.md # SBE streams documentation
│
├── examples/
│ ├── orderbook_basic.jl # OrderBookManager basic usage
│ ├── orderbook_advanced.jl # OrderBookManager advanced features
│ ├── sbe_stream_example.jl # SBE streams usage example
│ └── examples.jl # General usage examples
│
├── config_example.toml # Configuration template
├── CHANGELOG.md # Version history
└── README.md # This file
- Enable 2FA on your Binance account
- Use IP whitelisting when possible
- Never commit
config.tomlor private keys to version control - Use testnet for development and testing
- Limit API permissions to only what you need
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-feature) - Add tests for new functionality
- Update documentation as needed
- Submit a pull request with clear description
This project is released under the MIT License. See LICENSE file for details.
This software is for educational and informational purposes only. Use at your own risk. Always test with small amounts and understand the risks involved in cryptocurrency trading.
- Issues: GitHub Issues
- Documentation: See docs/ directory