| Crates.io | orderly-connector-rs |
| lib.rs | orderly-connector-rs |
| version | 0.4.15 |
| created_at | 2025-04-04 09:21:08.386197+00 |
| updated_at | 2025-06-12 06:28:16.560369+00 |
| description | A Rust client library for interacting with the Orderly Network API |
| homepage | https://ranger.finance |
| repository | https://github.com/ranger-finance/orderly-connector-rs |
| max_upload_size | |
| id | 1619711 |
| size | 629,270 |
Rust SDK for interacting with the Orderly Network API (v1/v2). For more information about Orderly Network, visit Orderly Documentation. This is based on the python connector orderly-evm-connector-python.
rest::Client)
websocket::WebsocketPublicClient: Subscribe to public data streams (tickers, orderbooks, klines, etc.) for a specific account ID.websocket::WebsocketPrivateClient: Subscribe to private data streams (execution reports, balance updates, position updates) using API key authentication.types: Request/response structures and enums.auth: Authentication helpers (signing).error: Custom error types.Add the following to your Cargo.toml:
[dependencies]
orderly-connector-rs = "0.2.4" # or the latest version
Or install using cargo:
cargo add orderly-connector-rs
use orderly_connector_rs::rest::Client;
use orderly_connector_rs::types::OrderType;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a client with your API credentials
let client = Client::new(
"https://testnet-api-evm.orderly.org", // API base URL
Some("your_orderly_key"), // Optional: API key
Some("your_orderly_secret"), // Optional: API secret
Some("your_account_id"), // Optional: Account ID
)?;
// Get system status
let status = client.get_system_status().await?;
println!("System status: {:?}", status);
// Get exchange info
let info = client.get_exchange_info(None).await?;
println!("Exchange info: {:?}", info);
Ok(())
}
use orderly_connector_rs::websocket::{WebsocketPublicClient, WebsocketClientConfig};
use orderly_connector_rs::types::OrderType;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create WebSocket configuration
let config = WebsocketClientConfig {
base_url: "wss://testnet-ws-evm.orderly.org".to_string(),
orderly_key: Some("your_orderly_key".to_string()),
orderly_secret: Some("your_orderly_secret".to_string()),
orderly_account_id: Some("your_account_id".to_string()),
wss_id: None,
};
// Create public WebSocket client
let mut public_client = WebsocketPublicClient::new(config.clone())?;
// Connect to WebSocket
public_client.connect().await?;
// Subscribe to orderbook updates
public_client.subscribe_orderbook("PERP_ETH_USDC").await?;
// Handle incoming messages
while let Some(msg) = public_client.next().await {
match msg {
Ok(message) => println!("Received: {:?}", message),
Err(e) => eprintln!("Error: {:?}", e),
}
}
Ok(())
}
For detailed API documentation, visit docs.rs/orderly-connector-rs.
The REST client provides methods for interacting with the Orderly Network API:
get_system_status(): Get the current system statusget_exchange_info(symbol: Option<String>): Get exchange informationget_market_trades(symbol: String, limit: Option<u32>): Get recent market tradesget_klines(symbol: String, interval: String, start_time: Option<u64>, end_time: Option<u64>, limit: Option<u32>): Get kline/candlestick dataget_account_info(): Get account informationget_positions(symbol: Option<String>): Get current positionscreate_order(request: CreateOrderRequest): Create a new orderget_orders(params: GetOrdersParams): Get order historycancel_order(symbol: String, order_id: Option<String>, client_order_id: Option<String>): Cancel an orderThe SDK includes preliminary support for interacting with Orderly Network's Solana Vault program.
ErBmAD61mGFKvrFNaTJuxoPwqrS8GgtwtqJTJVjFWx9QFunctionality to prepare Solana transactions (like deposits) for signing is under development. See the implementation plan for details.
The WebSocket client provides real-time data streaming:
subscribe_ticker(symbol: String): Subscribe to ticker updatessubscribe_orderbook(symbol: String): Subscribe to orderbook updatessubscribe_trades(symbol: String): Subscribe to trade updatessubscribe_klines(symbol: String, interval: String): Subscribe to kline updatessubscribe_execution(): Subscribe to execution reportssubscribe_position(): Subscribe to position updatessubscribe_balance(): Subscribe to balance updatesThe library uses a custom error type OrderlyError for error handling. All operations return a Result<T, OrderlyError> where T is the success type.
Example error handling:
match client.get_system_status().await {
Ok(status) => println!("System status: {:?}", status),
Err(OrderlyError::ClientError { status, code, message, .. }) => {
eprintln!("Client error: {} (code: {})", message, code);
},
Err(e) => eprintln!("Error: {:?}", e),
}
The library supports configuration through environment variables:
ORDERLY_API_BASE_URL=https://testnet-api-evm.orderly.org
ORDERLY_KEY=your_orderly_key
ORDERLY_SECRET=your_orderly_secret
ORDERLY_ACCOUNT_ID=your_account_id
The WebsocketClientConfig struct allows you to configure:
base_url: WebSocket server URLorderly_key: API key for authenticationorderly_secret: API secret for authenticationorderly_account_id: Account ID for private streamswss_id: Optional WebSocket session IDSee the examples directory for more complete examples:
rest_client.rs: REST API usage exampleswebsocket_client.rs: WebSocket streaming examplesorder_management.rs: Order creation and management examplesContributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE-MIT file for details.