lightcone 0.7.1

Rust SDK for the Lightcone Protocol — unified native + WASM client
Documentation
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
//! Types for platform / market / orderbook / category / deposit-token metrics.
//!
//! Mirrors the `dto::metrics` types on the backend. `Decimal` fields deserialize
//! from JSON strings via `rust_decimal`'s `serde-str` feature; `PubkeyStr` and
//! `OrderBookId` newtypes are serialization-transparent.

use crate::shared::{OrderBookId, PubkeyStr};
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};

// ─── Orderbook tickers (batch) ───────────────────────────────────────────────

/// One entry in `GET /api/metrics/orderbooks/tickers`. Same shape (BBO +
/// midpoint) as the WS `Ticker` stream, delivered in batch over REST.
/// Price fields are `None` when the orderbook has no liquidity yet.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct OrderbookTickerEntry {
    pub orderbook_id: OrderBookId,
    pub market_pubkey: PubkeyStr,
    #[serde(default)]
    pub outcome_index: Option<i16>,
    #[serde(default)]
    pub outcome_name: Option<String>,
    #[serde(default)]
    pub outcome_name_long: Option<String>,
    pub base_deposit_asset: PubkeyStr,
    pub quote_deposit_asset: PubkeyStr,
    #[serde(default)]
    pub best_bid: Option<Decimal>,
    #[serde(default)]
    pub best_ask: Option<Decimal>,
    #[serde(default)]
    pub midpoint: Option<Decimal>,
    #[serde(default)]
    pub computed_at: Option<DateTime<Utc>>,
}

/// `GET /api/metrics/orderbooks/tickers` response.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct OrderbookTickersResponse {
    pub tickers: Vec<OrderbookTickerEntry>,
}

// ─── Platform ────────────────────────────────────────────────────────────────

/// `GET /api/metrics/platform` response.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PlatformMetrics {
    pub volume_24h_usd: Decimal,
    pub volume_7d_usd: Decimal,
    pub volume_30d_usd: Decimal,
    pub volume_total_usd: Decimal,
    pub taker_bid_volume_24h_usd: Decimal,
    pub taker_bid_volume_7d_usd: Decimal,
    pub taker_bid_volume_30d_usd: Decimal,
    pub taker_bid_volume_total_usd: Decimal,
    pub taker_ask_volume_24h_usd: Decimal,
    pub taker_ask_volume_7d_usd: Decimal,
    pub taker_ask_volume_30d_usd: Decimal,
    pub taker_ask_volume_total_usd: Decimal,
    pub taker_bid_ask_imbalance_24h_pct: Decimal,
    pub taker_bid_ask_imbalance_7d_pct: Decimal,
    pub taker_bid_ask_imbalance_30d_pct: Decimal,
    pub taker_bid_ask_imbalance_total_pct: Decimal,
    pub unique_traders_24h: i32,
    pub unique_traders_7d: i32,
    pub unique_traders_30d: i32,
    pub active_markets: i64,
    pub active_orderbooks: i64,
    pub deposit_token_volumes: Vec<DepositTokenVolumeMetrics>,
    #[serde(default)]
    pub updated_at: Option<DateTime<Utc>>,
}

// ─── Market (listing + detail) ───────────────────────────────────────────────

/// Entry in `GET /api/metrics/markets`.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct MarketVolumeMetrics {
    pub market_pubkey: PubkeyStr,
    #[serde(default)]
    pub slug: Option<String>,
    #[serde(default)]
    pub market_name: Option<String>,
    #[serde(default)]
    pub category: Option<String>,
    pub volume_24h_usd: Decimal,
    pub volume_7d_usd: Decimal,
    pub volume_30d_usd: Decimal,
    pub volume_total_usd: Decimal,
    pub taker_bid_volume_24h_usd: Decimal,
    pub taker_bid_volume_7d_usd: Decimal,
    pub taker_bid_volume_30d_usd: Decimal,
    pub taker_bid_volume_total_usd: Decimal,
    pub taker_ask_volume_24h_usd: Decimal,
    pub taker_ask_volume_7d_usd: Decimal,
    pub taker_ask_volume_30d_usd: Decimal,
    pub taker_ask_volume_total_usd: Decimal,
    pub taker_bid_ask_imbalance_24h_pct: Decimal,
    pub taker_bid_ask_imbalance_7d_pct: Decimal,
    pub taker_bid_ask_imbalance_30d_pct: Decimal,
    pub taker_bid_ask_imbalance_total_pct: Decimal,
    pub unique_traders_24h: i32,
    pub unique_traders_7d: i32,
    pub unique_traders_30d: i32,
    pub category_volume_share_24h_pct: Decimal,
    pub platform_volume_share_24h_pct: Decimal,
}

/// `GET /api/metrics/markets` envelope.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct MarketsMetrics {
    pub markets: Vec<MarketVolumeMetrics>,
    pub total: usize,
}

impl Default for MarketsMetrics {
    fn default() -> Self {
        Self {
            markets: Vec::new(),
            total: 0,
        }
    }
}

/// Per-outcome breakdown inside `MarketDetailMetrics`.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct OutcomeVolumeMetrics {
    pub outcome_index: Option<i16>,
    #[serde(default)]
    pub outcome_name: Option<String>,
    #[serde(default)]
    pub outcome_name_long: Option<String>,
    pub volume_24h_usd: Decimal,
    pub volume_7d_usd: Decimal,
    pub volume_30d_usd: Decimal,
    pub volume_total_usd: Decimal,
    pub taker_bid_volume_24h_usd: Decimal,
    pub taker_bid_volume_7d_usd: Decimal,
    pub taker_bid_volume_30d_usd: Decimal,
    pub taker_bid_volume_total_usd: Decimal,
    pub taker_ask_volume_24h_usd: Decimal,
    pub taker_ask_volume_7d_usd: Decimal,
    pub taker_ask_volume_30d_usd: Decimal,
    pub taker_ask_volume_total_usd: Decimal,
    pub taker_bid_ask_imbalance_24h_pct: Decimal,
    pub taker_bid_ask_imbalance_7d_pct: Decimal,
    pub taker_bid_ask_imbalance_30d_pct: Decimal,
    pub taker_bid_ask_imbalance_total_pct: Decimal,
    pub unique_traders_24h: i32,
    pub unique_traders_7d: i32,
    pub unique_traders_30d: i32,
    pub volume_share_24h_pct: Decimal,
}

/// Per-orderbook breakdown inside `MarketDetailMetrics`.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct MarketOrderbookVolumeMetrics {
    pub orderbook_id: OrderBookId,
    pub outcome_index: Option<i16>,
    #[serde(default)]
    pub outcome_name: Option<String>,
    #[serde(default)]
    pub outcome_name_long: Option<String>,
    pub base_deposit_asset: PubkeyStr,
    #[serde(default)]
    pub base_deposit_symbol: Option<String>,
    pub quote_deposit_asset: PubkeyStr,
    #[serde(default)]
    pub quote_deposit_symbol: Option<String>,
    pub volume_24h_usd: Decimal,
    pub volume_7d_usd: Decimal,
    pub volume_30d_usd: Decimal,
    pub volume_total_usd: Decimal,
    pub volume_24h_base: Decimal,
    pub volume_7d_base: Decimal,
    pub volume_30d_base: Decimal,
    pub volume_total_base: Decimal,
    pub volume_24h_quote: Decimal,
    pub volume_7d_quote: Decimal,
    pub volume_30d_quote: Decimal,
    pub volume_total_quote: Decimal,
    pub taker_bid_volume_24h_usd: Decimal,
    pub taker_bid_volume_7d_usd: Decimal,
    pub taker_bid_volume_30d_usd: Decimal,
    pub taker_bid_volume_total_usd: Decimal,
    pub taker_bid_volume_24h_base: Decimal,
    pub taker_bid_volume_7d_base: Decimal,
    pub taker_bid_volume_30d_base: Decimal,
    pub taker_bid_volume_total_base: Decimal,
    pub taker_bid_volume_24h_quote: Decimal,
    pub taker_bid_volume_7d_quote: Decimal,
    pub taker_bid_volume_30d_quote: Decimal,
    pub taker_bid_volume_total_quote: Decimal,
    pub taker_ask_volume_24h_usd: Decimal,
    pub taker_ask_volume_7d_usd: Decimal,
    pub taker_ask_volume_30d_usd: Decimal,
    pub taker_ask_volume_total_usd: Decimal,
    pub taker_ask_volume_24h_base: Decimal,
    pub taker_ask_volume_7d_base: Decimal,
    pub taker_ask_volume_30d_base: Decimal,
    pub taker_ask_volume_total_base: Decimal,
    pub taker_ask_volume_24h_quote: Decimal,
    pub taker_ask_volume_7d_quote: Decimal,
    pub taker_ask_volume_30d_quote: Decimal,
    pub taker_ask_volume_total_quote: Decimal,
    pub taker_bid_ask_imbalance_24h_pct: Decimal,
    pub taker_bid_ask_imbalance_7d_pct: Decimal,
    pub taker_bid_ask_imbalance_30d_pct: Decimal,
    pub taker_bid_ask_imbalance_total_pct: Decimal,
    pub volume_share_24h_pct: Decimal,
}

/// `GET /api/metrics/markets/{market_pubkey}` response.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct MarketDetailMetrics {
    pub market_pubkey: PubkeyStr,
    #[serde(default)]
    pub slug: Option<String>,
    #[serde(default)]
    pub market_name: Option<String>,
    #[serde(default)]
    pub category: Option<String>,
    pub volume_24h_usd: Decimal,
    pub volume_7d_usd: Decimal,
    pub volume_30d_usd: Decimal,
    pub volume_total_usd: Decimal,
    pub taker_bid_volume_24h_usd: Decimal,
    pub taker_bid_volume_7d_usd: Decimal,
    pub taker_bid_volume_30d_usd: Decimal,
    pub taker_bid_volume_total_usd: Decimal,
    pub taker_ask_volume_24h_usd: Decimal,
    pub taker_ask_volume_7d_usd: Decimal,
    pub taker_ask_volume_30d_usd: Decimal,
    pub taker_ask_volume_total_usd: Decimal,
    pub taker_bid_ask_imbalance_24h_pct: Decimal,
    pub taker_bid_ask_imbalance_7d_pct: Decimal,
    pub taker_bid_ask_imbalance_30d_pct: Decimal,
    pub taker_bid_ask_imbalance_total_pct: Decimal,
    pub unique_traders_24h: i32,
    pub unique_traders_7d: i32,
    pub unique_traders_30d: i32,
    pub category_volume_share_24h_pct: Decimal,
    pub platform_volume_share_24h_pct: Decimal,
    pub outcome_volumes: Vec<OutcomeVolumeMetrics>,
    pub orderbook_volumes: Vec<MarketOrderbookVolumeMetrics>,
    pub deposit_token_volumes: Vec<DepositTokenVolumeMetrics>,
}

// ─── Orderbook ───────────────────────────────────────────────────────────────

/// `GET /api/metrics/orderbooks/{orderbook_id}` response.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct OrderbookVolumeMetrics {
    pub orderbook_id: OrderBookId,
    pub market_pubkey: PubkeyStr,
    pub outcome_index: Option<i16>,
    #[serde(default)]
    pub outcome_name: Option<String>,
    #[serde(default)]
    pub outcome_name_long: Option<String>,
    pub base_deposit_asset: PubkeyStr,
    #[serde(default)]
    pub base_deposit_symbol: Option<String>,
    pub quote_deposit_asset: PubkeyStr,
    #[serde(default)]
    pub quote_deposit_symbol: Option<String>,
    pub volume_24h_usd: Decimal,
    pub volume_7d_usd: Decimal,
    pub volume_30d_usd: Decimal,
    pub volume_total_usd: Decimal,
    pub volume_24h_base: Decimal,
    pub volume_7d_base: Decimal,
    pub volume_30d_base: Decimal,
    pub volume_total_base: Decimal,
    pub volume_24h_quote: Decimal,
    pub volume_7d_quote: Decimal,
    pub volume_30d_quote: Decimal,
    pub volume_total_quote: Decimal,
    pub taker_bid_volume_24h_usd: Decimal,
    pub taker_bid_volume_7d_usd: Decimal,
    pub taker_bid_volume_30d_usd: Decimal,
    pub taker_bid_volume_total_usd: Decimal,
    pub taker_bid_volume_24h_base: Decimal,
    pub taker_bid_volume_7d_base: Decimal,
    pub taker_bid_volume_30d_base: Decimal,
    pub taker_bid_volume_total_base: Decimal,
    pub taker_bid_volume_24h_quote: Decimal,
    pub taker_bid_volume_7d_quote: Decimal,
    pub taker_bid_volume_30d_quote: Decimal,
    pub taker_bid_volume_total_quote: Decimal,
    pub taker_ask_volume_24h_usd: Decimal,
    pub taker_ask_volume_7d_usd: Decimal,
    pub taker_ask_volume_30d_usd: Decimal,
    pub taker_ask_volume_total_usd: Decimal,
    pub taker_ask_volume_24h_base: Decimal,
    pub taker_ask_volume_7d_base: Decimal,
    pub taker_ask_volume_30d_base: Decimal,
    pub taker_ask_volume_total_base: Decimal,
    pub taker_ask_volume_24h_quote: Decimal,
    pub taker_ask_volume_7d_quote: Decimal,
    pub taker_ask_volume_30d_quote: Decimal,
    pub taker_ask_volume_total_quote: Decimal,
    pub taker_bid_ask_imbalance_24h_pct: Decimal,
    pub taker_bid_ask_imbalance_7d_pct: Decimal,
    pub taker_bid_ask_imbalance_30d_pct: Decimal,
    pub taker_bid_ask_imbalance_total_pct: Decimal,
    pub unique_traders_24h: i32,
    pub unique_traders_7d: i32,
    pub unique_traders_30d: i32,
    pub market_volume_share_24h_pct: Decimal,
}

// ─── Category ────────────────────────────────────────────────────────────────

/// Entry in `GET /api/metrics/categories` and the single response from
/// `GET /api/metrics/categories/{category}`.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct CategoryVolumeMetrics {
    pub category: String,
    pub volume_24h_usd: Decimal,
    pub volume_7d_usd: Decimal,
    pub volume_30d_usd: Decimal,
    pub volume_total_usd: Decimal,
    pub taker_bid_volume_24h_usd: Decimal,
    pub taker_bid_volume_7d_usd: Decimal,
    pub taker_bid_volume_30d_usd: Decimal,
    pub taker_bid_volume_total_usd: Decimal,
    pub taker_ask_volume_24h_usd: Decimal,
    pub taker_ask_volume_7d_usd: Decimal,
    pub taker_ask_volume_30d_usd: Decimal,
    pub taker_ask_volume_total_usd: Decimal,
    pub taker_bid_ask_imbalance_24h_pct: Decimal,
    pub taker_bid_ask_imbalance_7d_pct: Decimal,
    pub taker_bid_ask_imbalance_30d_pct: Decimal,
    pub taker_bid_ask_imbalance_total_pct: Decimal,
    pub unique_traders_24h: i32,
    pub unique_traders_7d: i32,
    pub unique_traders_30d: i32,
    pub platform_volume_share_24h_pct: Decimal,
    pub deposit_token_volumes: Vec<DepositTokenVolumeMetrics>,
}

/// `GET /api/metrics/categories` envelope.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct CategoriesMetrics {
    pub categories: Vec<CategoryVolumeMetrics>,
}

// ─── Deposit tokens ──────────────────────────────────────────────────────────

/// Entry in `GET /api/metrics/deposit-tokens`, also nested in platform/market/category
/// responses.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct DepositTokenVolumeMetrics {
    pub deposit_asset: PubkeyStr,
    #[serde(default)]
    pub symbol: Option<String>,
    pub volume_24h_usd: Decimal,
    pub volume_7d_usd: Decimal,
    pub volume_30d_usd: Decimal,
    pub volume_total_usd: Decimal,
    pub taker_bid_volume_24h_usd: Decimal,
    pub taker_bid_volume_7d_usd: Decimal,
    pub taker_bid_volume_30d_usd: Decimal,
    pub taker_bid_volume_total_usd: Decimal,
    pub taker_ask_volume_24h_usd: Decimal,
    pub taker_ask_volume_7d_usd: Decimal,
    pub taker_ask_volume_30d_usd: Decimal,
    pub taker_ask_volume_total_usd: Decimal,
    pub taker_bid_ask_imbalance_24h_pct: Decimal,
    pub taker_bid_ask_imbalance_7d_pct: Decimal,
    pub taker_bid_ask_imbalance_30d_pct: Decimal,
    pub taker_bid_ask_imbalance_total_pct: Decimal,
    pub volume_share_24h_pct: Decimal,
}

/// `GET /api/metrics/deposit-tokens` envelope.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct DepositTokensMetrics {
    pub deposit_tokens: Vec<DepositTokenVolumeMetrics>,
}

// ─── Leaderboard ─────────────────────────────────────────────────────────────

/// Entry in `GET /api/metrics/leaderboard/markets`.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct LeaderboardEntry {
    pub rank: i32,
    pub market_pubkey: PubkeyStr,
    #[serde(default)]
    pub slug: Option<String>,
    #[serde(default)]
    pub market_name: Option<String>,
    #[serde(default)]
    pub category: Option<String>,
    pub volume_24h_usd: Decimal,
    pub category_volume_share_24h_pct: Decimal,
    pub platform_volume_share_24h_pct: Decimal,
}

/// `GET /api/metrics/leaderboard/markets` envelope.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Leaderboard {
    pub entries: Vec<LeaderboardEntry>,
    pub period: String,
}

// ─── History ─────────────────────────────────────────────────────────────────

/// Bucket in `GET /api/metrics/history/{scope}/{scope_key}`.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct HistoryPoint {
    /// Bucket start, Unix epoch milliseconds.
    pub bucket_start: i64,
    pub volume_usd: Decimal,
}

/// `GET /api/metrics/history/{scope}/{scope_key}` response.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct MetricsHistory {
    pub scope: String,
    pub scope_key: String,
    pub resolution: String,
    pub points: Vec<HistoryPoint>,
}

// ─── Queries (SDK-side; not wire-returned from the backend) ──────────────────

/// Query parameters for `GET /api/metrics/markets` (reserved for future filters).
#[derive(Debug, Clone, Default, Serialize, PartialEq)]
pub struct MarketsMetricsQuery {}

/// Query parameters for `GET /api/metrics/markets/{market_pubkey}` (reserved for future filters).
#[derive(Debug, Clone, Default, Serialize, PartialEq)]
pub struct MarketMetricsQuery {}

/// Query parameters for `GET /api/metrics/orderbooks/{orderbook_id}` (reserved for future filters).
#[derive(Debug, Clone, Default, Serialize, PartialEq)]
pub struct OrderbookMetricsQuery {}

/// Query parameters for `GET /api/metrics/categories/{category}` (reserved for future filters).
#[derive(Debug, Clone, Default, Serialize, PartialEq)]
pub struct CategoryMetricsQuery {}

/// Query parameters for `GET /api/metrics/history/{scope}/{scope_key}`.
#[derive(Debug, Clone, Serialize, PartialEq)]
pub struct MetricsHistoryQuery {
    pub resolution: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub from: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub to: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<usize>,
}

impl Default for MetricsHistoryQuery {
    fn default() -> Self {
        Self {
            resolution: "1h".to_string(),
            from: None,
            to: None,
            limit: None,
        }
    }
}

/// Per-wallet trading + referral aggregates. Response shape of
/// `metrics().user`, `metrics().user_with_cookies`, and `metrics().user_by_wallet`.
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
pub struct UserMetrics {
    pub wallet_address: PubkeyStr,
    pub total_outcomes_traded: i64,
    pub total_volume_usd: Decimal,
    pub total_referrals_used: i64,
}