Bitfinex API Library & CLI Tool (Rust)

A fully asynchronous Rust library and CLI for accessing the Bitfinex V2 API.
- Async-first: Non-blocking, efficient API calls.
- CLI included: Query Bitfinex from your terminal.
- Lightweight: Minimal dependencies.
- Auto-retry: Handles "Nonce: small" errors automatically.
Quick Start
Use in Rust Project
Add to Your Rust Project:
cargo add bfx
Example usage
use bfx::client::Client;
async fn async_main() {
let client = Client::new("".to_string(), "".to_string());
let ticker = client.request_trading_ticker("tBTCUSD").await.unwrap();
println!("{}", serde_json::to_string_pretty(&ticker));
}
fn main() {
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on(async_main());
}
CLI Installation
With script (Mac/Linux):
curl -sSL https://raw.githubusercontent.com/BreezeWhite/bfx-rs/main/install.sh | bash
With script (Windows):
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
iwr -useb https://raw.githubusercontent.com/BreezeWhite/bfx-rs/main/install_win.ps1 | iex
Wth Cargo:
cargo install bfx --features cli
CLI Usage
A convenient CLI tool for Bitfinex
Version: 0.1.0
Author: BreezeWhite, <miyashita2010@tuta.io>
Usage: bfx <COMMAND>
Commands:
trading Trading/exchange related utilities
funding Funding-related utilities
public Public endpoints that does not related to trading nor funding
auth User-related utilities
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
More Examples
Initialize .env file
Initialize the .bfx_cli.env file to store API key and API secret for later use.
use bfx::client::Client;
use bfx::utils::resolve_env_path_or_create;
fn main() {
let env_path = resolve_env_path_or_create();
dotenv::from_path(env_path).expect("Failed to load .env file");
let api_key = std::env::var("API_KEY").unwrap();
let api_secret = std::env::var("API_SECRET").unwrap();
let client = Client::new(api_key, api_secret);
}
For CLI, bfx will automatically detect if there is a need to ask the
user to input API key and secret when calling to authenticated endpoints.
When call to public endpoints, there is no need to have a .env file.