| Crates.io | bpx-api-client |
| lib.rs | bpx-api-client |
| version | 0.7.1 |
| created_at | 2024-01-23 05:20:34.145671+00 |
| updated_at | 2025-08-07 10:32:24.112721+00 |
| description | Backpack Exchange API client |
| homepage | |
| repository | https://github.com/backpack-exchange/bpx-api-client |
| max_upload_size | |
| id | 1110279 |
| size | 90,535 |
This crate provides both REST and WebSocket APIs for interacting with the Backpack Exchange:
ws feature).The official API documentation is available at https://docs.backpack.exchange/.
Add this crate to your Cargo.toml:
[dependencies]
bpx_api_client = "x.y.z" # Replace with the latest version
To enable WebSocket support:
[dependencies]
bpx_api_client = { version = "x.y.z", features = ["ws"] }
REST API example:
use bpx_api_client::{BpxClient, BACKPACK_API_BASE_URL};
use std::env;
#[tokio::main]
async fn main() {
let base_url = env::var("BASE_URL").unwrap_or_else(|_| BACKPACK_API_BASE_URL.to_string());
let secret = env::var("SECRET").expect("Missing SECRET environment variable");
let client = BpxClient::init(base_url, secret, None)
.expect("Failed to initialize Backpack API client");
match client.get_open_orders(Some("SOL_USDC")).await {
Ok(orders) => println!("Open Orders: {:?}", orders),
Err(err) => tracing::error!("Error: {:?}", err),
}
}
WebSocket API example:
use anyhow::Result;
use bpx_api_client::{BpxClient, BACKPACK_API_BASE_URL, BACKPACK_WS_URL};
use bpx_api_types::rfq::RequestForQuote;
use std::env;
use tokio::sync::mpsc;
#[tokio::main]
async fn main() -> Result<()> {
let base_url = env::var("BASE_URL").unwrap_or_else(|_| BACKPACK_API_BASE_URL.to_string());
let ws_url = env::var("WS_URL").unwrap_or_else(|_| BACKPACK_WS_URL.to_string());
let secret = env::var("SECRET").expect("Missing SECRET environment variable");
let client = BpxClient::init_with_ws(base_url, ws_url, &secret, None)?;
let (tx, mut rx) = mpsc::channel::<RequestForQuote>(100);
tokio::spawn(async move {
while let Some(rfq) = rx.recv().await {
println!("Received RFQ: {:?}", rfq);
}
});
client.subscribe_to_rfqs(tx).await;
Ok(())
}
This project uses Just to manage various build and development tasks.
To see the available commands, run:
just