1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
//! # wf-market
//!
//! A Rust client library for the [warframe.market](https://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
//!
//! ```ignore
//! 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(
//! "your@email.com",
//! "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:
//!
//! ```ignore
//! 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:
//!
//! ```ignore
//! 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:
//!
//! ```toml
//! [dependencies]
//! wf-market = { version = "0.2", features = ["websocket"] }
//! ```
//!
//! ```ignore
//! 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 rustls
//! - `websocket`: Enable WebSocket support for real-time updates
//! - `v1-api`: Enable deprecated V1 API endpoints (statistics)
// Modules
// Re-exports for convenience
pub use ;
pub use ;
pub use ;
pub use WsError;
// Model re-exports
pub use ;
// V1 API model re-exports (deprecated, feature-gated)
pub use ;