Expand description
§wf-market
A Rust client library for the warframe.market API.
This library provides a type-safe, async client for interacting with the warframe.market trading platform, including both HTTP REST API and WebSocket real-time updates.
§Features
- Type-safe API: Compile-time guarantees prevent common mistakes
- Async/await: Built on Tokio for efficient async operations
- Session persistence: Save and restore login sessions
- Rate limiting: Built-in rate limiter to prevent API throttling
- Caching: Optional caching for slowly-changing data
- WebSocket support: Real-time updates (optional feature)
§Quick Start
ⓘ
use wf_market::{Client, Credentials, CreateOrder};
#[tokio::main]
async fn main() -> wf_market::Result<()> {
// Create a client (fetches items automatically)
let client = Client::builder().build().await?;
// Items are pre-loaded and accessible via client.items()
println!("Loaded {} items", client.items().len());
// Get orders for an item
let orders = client.get_orders("nikana_prime_set").await?;
for order in orders.iter().take(5) {
// Item info is automatically available on orders
if let Some(item) = order.get_item() {
println!("{}: {} @ {}p", order.user.ingame_name, item.name(), order.platinum);
}
}
// Login for authenticated operations
let creds = Credentials::new(
"[email protected]",
"password",
Credentials::generate_device_id(),
);
let client = client.login(creds).await?;
// Create an order
let order = client.create_order(
CreateOrder::sell("nikana_prime_set", 100, 1)
).await?;
println!("Created order: {}", order.id());
Ok(())
}§Session Persistence
Save and restore login sessions to avoid re-authenticating:
ⓘ
use wf_market::{Client, Credentials};
async fn example() -> wf_market::Result<()> {
// Initial login
let creds = Credentials::new("email", "password", Credentials::generate_device_id());
let client = Client::from_credentials(creds).await?;
// Save session
let session = client.export_session();
let json = serde_json::to_string(&session)?;
std::fs::write("session.json", &json)?;
// Later: restore session
let saved: Credentials = serde_json::from_str(&std::fs::read_to_string("session.json")?)?;
// Validate before using (recommended)
if Client::validate_credentials(&saved).await? {
let client = Client::from_credentials(saved).await?;
}
Ok(())
}§Caching
Use the ApiCache to persist items across application restarts:
ⓘ
use wf_market::{Client, ApiCache, SerializableCache};
async fn example() -> wf_market::Result<()> {
// Load cache from disk (or create new)
let mut cache = match std::fs::read_to_string("cache.json") {
Ok(json) => serde_json::from_str::<SerializableCache>(&json)?
.into_api_cache(),
Err(_) => ApiCache::new(),
};
// Build client using cache (uses cached items if < 1 day old)
let client = Client::builder()
.build_with_cache(&mut cache)
.await?;
// Items are loaded from cache or API
println!("Loaded {} items", client.items().len());
// Save cache for next time
let serializable = SerializableCache::from(&cache);
std::fs::write("cache.json", serde_json::to_string(&serializable)?)?;
Ok(())
}§WebSocket (Real-time Updates)
Enable the websocket feature for real-time order updates:
[dependencies]
wf-market = { version = "0.2", features = ["websocket"] }ⓘ
use wf_market::{Client, Credentials};
use wf_market::ws::{WsEvent, Subscription};
async fn example() -> wf_market::Result<()> {
let client = Client::from_credentials(/* ... */).await?;
let ws = client.websocket()
.on_event(|event| async move {
match event {
WsEvent::OnlineCount { authorized, .. } => {
println!("Users online: {}", authorized);
}
WsEvent::OrderCreated { order } => {
println!("New order: {}p", order.platinum);
}
_ => {}
}
})
.subscribe(Subscription::all_new_orders())
.connect()
.await?;
Ok(())
}§Feature Flags
default=["rustls-tls"]rustls-tls: Use rustls for TLS (default)native-tls: Use native TLS instead of rustlswebsocket: Enable WebSocket support for real-time updatesv1-api: Enable deprecated V1 API endpoints (statistics)
Re-exports§
pub use cache::ApiCache;pub use cache::CachedItems;pub use cache::CachedRivens;pub use cache::SerializableCache;pub use client::AuthState;pub use client::Authenticated;pub use client::Client;pub use client::ClientBuilder;pub use client::ClientConfig;pub use client::Unauthenticated;pub use error::ApiErrorDetails;pub use error::ApiErrorResponse;pub use error::Error;pub use error::Result;pub use models::Achievement;pub use models::AchievementType;pub use models::Activity;pub use models::ActivityType;pub use models::CreateOrder;pub use models::Credentials;pub use models::FullUser;pub use models::Item;pub use models::ItemIndex;pub use models::ItemSet;pub use models::ItemTranslation;pub use models::Language;pub use models::ModView;pub use models::Order;pub use models::OrderListing;pub use models::OrderType;pub use models::OwnedOrder;pub use models::OwnedOrderId;pub use models::Platform;pub use models::Rarity;pub use models::Riven;pub use models::RivenAttribute;pub use models::RivenAttributeTranslation;pub use models::RivenTranslation;pub use models::RivenType;pub use models::SculptureView;pub use models::SubscriptionTier;pub use models::Theme;pub use models::TopOrderFilters;pub use models::TopOrders;pub use models::Transaction;pub use models::UpdateOrder;pub use models::UpdateProfile;pub use models::User;pub use models::UserPrivate;pub use models::UserProfile;pub use models::UserRole;pub use models::UserStatus;pub use models::WithPassword;