wf-market
A Rust client library for the warframe.market API.
Features
- Type-safe API - Compile-time guarantees prevent common mistakes like updating orders you don't own
- Async/await - Built on Tokio for efficient async operations
- Session persistence - Save and restore login sessions with serde-compatible credentials
- Rate limiting - Built-in rate limiter to prevent API throttling
- Caching - Optional caching for slowly-changing data (items, rivens)
- WebSocket support - Real-time order updates (optional feature)
Installation
Add to your Cargo.toml:
[]
= "0.2"
# With WebSocket support
= { = "0.2", = ["websocket"] }
Quick Start
use ;
async
Authentication
Login with Credentials
use ;
let creds = new;
let client = from_credentials.await?;
Session Persistence
Save and restore sessions to avoid re-authenticating:
use ;
// After login, export the session
let session = client.export_session;
let json = to_string?;
write?;
// Later: restore session
let saved: Credentials = from_str?;
// Validate before using (recommended)
if validate_credentials.await?
Working with Orders
Fetching Orders
// Get orders with user info
let orders = client.get_orders.await?;
// Get just order data (lighter response)
let listings = client.get_listings.await?;
// Get top buy/sell prices
let top = client.get_top_orders.await?;
println!;
println!;
Managing Your Orders
use ;
// Get your orders
let my_orders = client.my_orders.await?;
// Create a sell order
let order = client.create_order.await?;
// Update order price
client.update_order.await?;
// Delete order
client.delete_order.await?;
// Close order (record a sale)
let transaction = client.close_order.await?;
Type-Safe Order IDs
The OwnedOrderId type ensures you can only update/delete orders you own:
// This compiles - my_orders() returns OwnedOrder with OwnedOrderId
let orders = client.my_orders.await?;
client.delete_order.await?;
// This won't compile - get_orders() returns OrderListing with String id
let orders = client.get_orders.await?;
// client.delete_order(&orders[0].order.id); // Error!
Caching
Use ApiCache for endpoints that rarely change:
use ApiCache;
use Duration;
let mut cache = new;
// First call fetches from API
let items = client.get_items.await?;
// Subsequent calls use cache (instant)
let items = client.get_items.await?;
// With TTL - refresh if older than 24 hours
let items = client.get_items_with_ttl.await?;
// Cache is serializable for persistence
let serializable = cache.to_serializable;
let json = to_string?;
WebSocket (Real-time Updates)
Enable the websocket feature for real-time order updates:
[]
= { = "0.2", = ["websocket"] }
use ;
let ws = client.websocket
.on_event
.subscribe
.auto_reconnect
.connect
.await?;
// Subscribe to specific items
ws.subscribe.await?;
// Set your status
ws.set_status.await?;
Item Types
Mods
for item in &items
// Create mod order with rank
let order = sell
.with_mod_rank;
Ayatan Sculptures
for item in &items
Configuration
use ;
let config = ClientConfig ;
let client = builder
.config
.build?;
Feature Flags
| Feature | Default | Description |
|---|---|---|
rustls-tls |
Yes | Use rustls for TLS |
native-tls |
No | Use native TLS instead of rustls |
websocket |
No | Enable WebSocket support for real-time updates |
Examples
Run the examples with:
# Basic usage (no auth required)
# Authenticated examples (set WFM_EMAIL and WFM_PASSWORD)
Minimum Supported Rust Version
This crate requires Rust 1.85 or later (2024 edition).
License
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.