rs_limitless 0.1.1

Limitless Exchange API bindings in Rust — prediction market trading, HMAC authentication, EIP-712 signing, and WebSocket streams.
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
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
//! Request and response model types for the Limitless Exchange API.
//!
//! All REST API responses are fully typed with concrete structs matching
//! the API's JSON shape. WebSocket event types and order types are also
//! fully typed for compile-time safety.
//!
//! # Convention
//!
//! - Field names use `snake_case` in Rust and `camelCase` on the wire via
//!   `#[serde(rename = "...")]` where needed.
//! - Numeric fields that arrive as JSON strings use `serde_helpers` to
//!   deserialize transparently.

pub mod order;

use serde::{Deserialize, Serialize};
use serde_json::Value;

// ── Generic wrapper ──

/// Wraps data with a server-side timestamp for freshness tracking.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Timed<T> {
    pub time: u64,
    pub data: T,
}

// ═══════════════════════════════════════════════════════════════════════════
//  Markets
// ═══════════════════════════════════════════════════════════════════════════

/// Response from `GET /markets/active`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ActiveMarketsResponse {
    pub data: Vec<MarketSummary>,
    #[serde(rename = "totalMarketsCount")]
    pub total_markets_count: i32,
}

/// Summary view of a market in the active-markets list.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MarketSummary {
    pub id: i32,
    pub slug: String,
    pub title: String,
    #[serde(rename = "proxyTitle", default)]
    pub proxy_title: Option<String>,
    #[serde(default)]
    pub description: String,
    #[serde(rename = "collateralToken")]
    pub collateral_token: CollateralTokenInfo,
    #[serde(rename = "expirationDate")]
    pub expiration_date: String,
    #[serde(rename = "expirationTimestamp")]
    pub expiration_timestamp: i64,
    #[serde(default)]
    pub expired: Option<bool>,
    #[serde(rename = "createdAt")]
    pub created_at: String,
    #[serde(rename = "updatedAt")]
    pub updated_at: String,
    pub categories: Vec<String>,
    pub status: String,
    pub creator: MarketCreatorInfo,
    pub tags: Vec<String>,
    #[serde(rename = "tradeType")]
    pub trade_type: String,
    #[serde(rename = "marketType")]
    pub market_type: String,
    #[serde(rename = "priorityIndex")]
    pub priority_index: i32,
    pub metadata: MarketMetadataInfo,
    #[serde(default)]
    pub volume: Option<String>,
    #[serde(rename = "volumeFormatted", default)]
    pub volume_formatted: Option<String>,
    #[serde(rename = "automationType", default)]
    pub automation_type: Option<String>,
    #[serde(rename = "imageUrl", default)]
    pub image_url: Option<String>,
    #[serde(default)]
    pub trends: Option<Value>,
    #[serde(rename = "openInterest", default)]
    pub open_interest: Option<String>,
    #[serde(rename = "openInterestFormatted", default)]
    pub open_interest_formatted: Option<String>,
    #[serde(default)]
    pub liquidity: Option<String>,
    #[serde(rename = "liquidityFormatted", default)]
    pub liquidity_formatted: Option<String>,
    #[serde(rename = "positionIds", default)]
    pub position_ids: Vec<String>,
    #[serde(rename = "conditionId", default)]
    pub condition_id: Option<String>,
    #[serde(rename = "negRiskRequestId", default)]
    pub neg_risk_request_id: Option<String>,
    #[serde(default)]
    pub tokens: Option<MarketTokensInfo>,
    #[serde(default)]
    pub prices: Vec<f64>,
    #[serde(rename = "tradePrices", default)]
    pub trade_prices: Option<TradePricesInfo>,
    #[serde(rename = "isRewardable", default)]
    pub is_rewardable: Option<bool>,
    #[serde(default)]
    pub settings: Option<Value>,
    #[serde(default)]
    pub venue: Option<VenueInfo>,
    #[serde(default)]
    pub logo: Option<String>,
    #[serde(rename = "priceOracleMetadata", default)]
    pub price_oracle_data: Option<Value>,
    #[serde(rename = "orderInGroup", default)]
    pub order_in_group: Option<i32>,
    #[serde(rename = "winningOutcomeIndex", default)]
    pub winning_outcome_idx: Option<i32>,
    #[serde(rename = "outcomeTokens", default)]
    pub outcome_tokens: Vec<String>,
    #[serde(rename = "ogImageURI", default)]
    pub og_image_uri: Option<String>,
    #[serde(rename = "negRiskMarketId", default)]
    pub neg_risk_market_id: Option<String>,
    #[serde(default)]
    pub markets: Vec<MarketSummary>,
    #[serde(rename = "dailyReward", default)]
    pub daily_reward: Option<String>,
    #[serde(default)]
    pub address: Option<String>,
    #[serde(rename = "type", default)]
    pub market_type_legacy: Option<String>,
    #[serde(default)]
    pub outcomes: Vec<OutcomeInfo>,
    #[serde(rename = "resolutionDate", default)]
    pub resolution_date: Option<String>,
}

// NOTE: MarketSummary and MarketDetail share the same shape from the API.
// We alias them for semantic clarity.
pub type MarketDetail = MarketSummary;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CollateralTokenInfo {
    pub address: String,
    pub decimals: i32,
    pub symbol: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MarketCreatorInfo {
    pub name: String,
    #[serde(rename = "imageURI", default)]
    pub image_uri: Option<String>,
    #[serde(default)]
    pub link: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MarketMetadataInfo {
    pub fee: bool,
    #[serde(rename = "isBannered", default)]
    pub is_bannered: Option<bool>,
    #[serde(rename = "isPolyArbitrage", default)]
    pub is_poly_arbitrage: Option<bool>,
    #[serde(rename = "shouldMarketMake", default)]
    pub should_market_make: Option<bool>,
    #[serde(rename = "openPrice", default)]
    pub open_price: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MarketTokensInfo {
    pub yes: String,
    pub no: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TradePricesInfo {
    pub buy: PriceSideInfo,
    pub sell: PriceSideInfo,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PriceSideInfo {
    pub market: [f64; 2],
    pub limit: [f64; 2],
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VenueInfo {
    pub exchange: String,
    #[serde(default)]
    pub adapter: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OutcomeInfo {
    pub id: i32,
    pub title: String,
    #[serde(rename = "tokenId")]
    pub token_id: String,
    #[serde(default)]
    pub price: Option<f64>,
}

/// Response from `GET /markets/categories/count`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CategoryCountResponse {
    pub data: Value,
}

/// Active market slug entry from `GET /markets/active/slugs`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ActiveSlug {
    pub slug: String,
    #[serde(default)]
    pub ticker: Option<String>,
    #[serde(default)]
    pub strike_price: Option<String>,
    #[serde(default)]
    pub deadline: Option<String>,
}

/// Response from `GET /markets/{addr}/oracle-candles`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OracleCandlesResponse {
    pub data: Vec<OracleCandle>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OracleCandle {
    pub timestamp: i64,
    pub open: f64,
    pub high: f64,
    pub low: f64,
    pub close: f64,
}

/// Response from `GET /markets/{slug}/get-feed-events`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FeedEventsResponse {
    pub events: Vec<FeedEvent>,
    #[serde(default)]
    pub total: Option<i64>,
    #[serde(default)]
    pub page: Option<i64>,
    #[serde(default)]
    pub limit: Option<i64>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FeedEvent {
    #[serde(rename = "type")]
    pub event_type: String,
    #[serde(default)]
    pub data: Option<Value>,
    #[serde(default)]
    pub timestamp: Option<String>,
}

/// Response from `GET /markets/search`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchResponse {
    pub data: Vec<MarketSummary>,
    #[serde(default)]
    pub total: Option<i64>,
}

// ═══════════════════════════════════════════════════════════════════════════
//  Trading
// ═══════════════════════════════════════════════════════════════════════════

/// Response from `POST /orders`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateOrderResponse {
    pub order: CreatedOrderInfo,
    #[serde(rename = "makerMatches", default)]
    pub maker_matches: Vec<MakerMatchInfo>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreatedOrderInfo {
    pub id: String,
    #[serde(rename = "createdAt", default)]
    pub created_at: Option<String>,
    #[serde(rename = "makerAmount")]
    pub maker_amount: Value,
    #[serde(rename = "takerAmount")]
    pub taker_amount: Value,
    #[serde(default)]
    pub expiration: Option<String>,
    #[serde(rename = "signatureType")]
    pub signature_type: i32,
    pub salt: Value,
    pub maker: String,
    pub signer: String,
    pub taker: String,
    #[serde(rename = "tokenId")]
    pub token_id: String,
    pub side: Value,
    #[serde(rename = "feeRateBps")]
    pub fee_rate_bps: i32,
    pub nonce: i32,
    pub signature: String,
    #[serde(rename = "orderType")]
    pub order_type: String,
    #[serde(default)]
    pub price: Option<f64>,
    #[serde(rename = "marketId")]
    pub market_id: i32,
    #[serde(default)]
    pub status: Option<String>,
    #[serde(rename = "filledSize", default)]
    pub filled_size: Option<Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MakerMatchInfo {
    pub id: String,
    #[serde(rename = "createdAt", default)]
    pub created_at: Option<String>,
    #[serde(rename = "matchedSize")]
    pub matched_size: Value,
    #[serde(rename = "orderId")]
    pub order_id: String,
}

/// Response from `POST /orders/status/batch`.
pub type OrderStatusBatchResponse = Value;

/// Response from `POST /orders/cancel` and `DELETE /orders/:id`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CancelOrderResponse {
    #[serde(default)]
    pub message: Option<String>,
    #[serde(default)]
    pub id: Option<String>,
}

/// Response from `POST /orders/cancel-batch`.
pub type CancelBatchResponse = Value;

/// Response from `DELETE /orders/all/:slug`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CancelAllResponse {
    #[serde(default)]
    pub message: Option<String>,
}

/// Response from `GET /markets/:slug/orderbook`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OrderbookResponse {
    pub bids: Vec<OrderbookEntry>,
    pub asks: Vec<OrderbookEntry>,
    #[serde(rename = "tokenId")]
    pub token_id: String,
    #[serde(rename = "adjustedMidpoint")]
    pub adjusted_midpoint: f64,
    #[serde(rename = "maxSpread")]
    pub max_spread: String,
    #[serde(rename = "minSize")]
    pub min_size: String,
    #[serde(rename = "lastTradePrice")]
    pub last_trade_price: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OrderbookEntry {
    pub price: f64,
    pub size: f64,
    pub side: String,
}

/// Historical price data point from `GET /markets/:slug/historical-price`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HistoricalPriceData {
    pub timestamp: i64,
    pub price: f64,
}

/// Response from `GET /markets/:slug/locked-balance`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LockedBalanceResponse {
    #[serde(rename = "lockedBalance")]
    pub locked_balance: String,
    #[serde(rename = "lockedBalanceFormatted", default)]
    pub locked_balance_formatted: Option<String>,
}

/// Response from `GET /markets/:slug/user-orders`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UserOrdersResponse {
    pub data: Vec<UserOrderInfo>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UserOrderInfo {
    pub id: String,
    #[serde(rename = "createdAt")]
    pub created_at: String,
    #[serde(rename = "makerAmount")]
    pub maker_amount: Value,
    #[serde(rename = "takerAmount")]
    pub taker_amount: Value,
    #[serde(default)]
    pub expiration: Option<String>,
    #[serde(rename = "signatureType")]
    pub signature_type: i32,
    pub salt: Value,
    pub maker: String,
    pub signer: String,
    pub taker: String,
    #[serde(rename = "tokenId")]
    pub token_id: String,
    pub side: Value,
    #[serde(rename = "feeRateBps")]
    pub fee_rate_bps: i32,
    pub nonce: i32,
    pub signature: String,
    #[serde(rename = "orderType")]
    pub order_type: String,
    #[serde(default)]
    pub price: Option<f64>,
    #[serde(rename = "marketId")]
    pub market_id: i32,
    #[serde(default)]
    pub status: Option<String>,
    #[serde(rename = "filledSize", default)]
    pub filled_size: Option<Value>,
}

/// Response from `GET /markets/:slug/events`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MarketEventsResponse {
    pub events: Vec<Value>,
    #[serde(default)]
    pub total: Option<i64>,
    #[serde(default)]
    pub page: Option<i64>,
    #[serde(default)]
    pub limit: Option<i64>,
}

// ═══════════════════════════════════════════════════════════════════════════
//  Portfolio
// ═══════════════════════════════════════════════════════════════════════════

/// Response from `GET /profiles/:account`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProfileResponse {
    pub id: i32,
    pub account: String,
    #[serde(default)]
    pub rank: Option<RankInfo>,
    #[serde(rename = "createdAt", default)]
    pub created_at: Option<String>,
    #[serde(default)]
    pub username: Option<String>,
    #[serde(rename = "displayName", default)]
    pub display_name: Option<String>,
    #[serde(rename = "pfpUrl", default)]
    pub pfp_url: Option<String>,
    #[serde(default)]
    pub bio: Option<String>,
    #[serde(rename = "socialUrl", default)]
    pub social_url: Option<String>,
    #[serde(rename = "tradeWalletOption", default)]
    pub trade_wallet_option: Option<String>,
    #[serde(rename = "embeddedAccount", default)]
    pub embedded_account: Option<String>,
    #[serde(default)]
    pub points: Option<f64>,
    #[serde(rename = "accumulativePoints", default)]
    pub accumulative_points: Option<f64>,
    #[serde(rename = "enrolledInPointsProgram", default)]
    pub enrolled_in_points_program: Option<bool>,
    #[serde(rename = "leaderboardPosition", default)]
    pub leaderboard_position: Option<i32>,
    #[serde(rename = "referralData", default)]
    pub referral_data: Vec<ReferralDataInfo>,
    #[serde(rename = "referredUsersCount", default)]
    pub referred_users_count: Option<i32>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RankInfo {
    pub id: i32,
    pub name: String,
    #[serde(rename = "feeRateBps")]
    pub fee_rate_bps: i32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReferralDataInfo {
    #[serde(rename = "createdAt")]
    pub created_at: String,
    pub id: i32,
    #[serde(rename = "referredProfileId")]
    pub referred_profile_id: i32,
    #[serde(rename = "pfpUrl", default)]
    pub pfp_url: Option<String>,
    #[serde(rename = "displayName")]
    pub display_name: String,
}

/// AMM trade entry from `GET /portfolio/trades`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TradeEntry {
    #[serde(rename = "transactionHash", default)]
    pub transaction_hash: Option<String>,
    #[serde(rename = "blockTimestamp")]
    pub block_timestamp: i64,
    #[serde(rename = "collateralAmount", default)]
    pub collateral_amount: Option<String>,
    #[serde(default)]
    pub market: Option<TradeMarketInfo>,
    #[serde(rename = "outcomeIndex", default)]
    pub outcome_index: Option<i32>,
    #[serde(rename = "outcomeTokenAmount", default)]
    pub outcome_token_amount: Option<String>,
    #[serde(default)]
    pub strategy: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TradeMarketInfo {
    pub id: String,
    pub slug: String,
    pub title: String,
    pub closed: bool,
}

/// Response from `GET /portfolio/positions`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PositionsResponse {
    #[serde(default)]
    pub amm: Vec<AmmPositionEntry>,
    #[serde(default)]
    pub clob: Vec<ClobPositionEntry>,
    #[serde(default)]
    pub group: Vec<Value>,
    #[serde(default)]
    pub points: Option<String>,
    #[serde(rename = "accumulativePoints", default)]
    pub accumulative_points: Option<String>,
    #[serde(default)]
    pub rewards: Option<Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AmmPositionEntry {
    pub market: PositionMarketInfo,
    pub account: String,
    #[serde(rename = "outcomeIndex")]
    pub outcome_index: i32,
    #[serde(rename = "collateralAmount")]
    pub collateral_amount: String,
    #[serde(rename = "outcomeTokenAmount")]
    pub outcome_token_amount: String,
    #[serde(rename = "averageFillPrice")]
    pub average_fill_price: String,
    #[serde(rename = "totalBuysCost")]
    pub total_buys_cost: String,
    #[serde(rename = "totalSellsCost")]
    pub total_sells_cost: String,
    #[serde(rename = "realizedPnl")]
    pub realized_pnl: String,
    #[serde(rename = "unrealizedPnl")]
    pub unrealized_pnl: String,
    #[serde(rename = "latestTrade", default)]
    pub latest_trade: Option<Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClobPositionEntry {
    pub market: PositionMarketInfo,
    #[serde(rename = "makerAddress")]
    pub maker_address: String,
    pub positions: ClobPositionSides,
    #[serde(rename = "tokensBalance")]
    pub tokens_balance: PositionTokenBalance,
    #[serde(rename = "latestTrade")]
    pub latest_trade: PositionLatestTrade,
    #[serde(default)]
    pub orders: Option<Value>,
    #[serde(default)]
    pub rewards: Option<Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PositionMarketInfo {
    pub id: Value,
    pub slug: String,
    pub title: String,
    #[serde(default)]
    pub status: Option<String>,
    pub closed: bool,
    pub deadline: String,
    #[serde(rename = "conditionId", default)]
    pub condition_id: Option<String>,
    #[serde(rename = "winningOutcomeIndex", default)]
    pub winning_outcome_index: Option<i32>,
    #[serde(default)]
    pub group: Option<Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClobPositionSides {
    pub yes: PositionSideInfo,
    pub no: PositionSideInfo,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PositionSideInfo {
    pub cost: String,
    #[serde(rename = "fillPrice")]
    pub fill_price: String,
    #[serde(rename = "marketValue")]
    pub market_value: String,
    #[serde(rename = "realisedPnl")]
    pub realised_pnl: String,
    #[serde(rename = "unrealizedPnl")]
    pub unrealized_pnl: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PositionTokenBalance {
    pub yes: String,
    pub no: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PositionLatestTrade {
    #[serde(rename = "latestYesPrice", default)]
    pub latest_yes_price: Option<f64>,
    #[serde(rename = "latestNoPrice", default)]
    pub latest_no_price: Option<f64>,
    #[serde(rename = "outcomeTokenPrice", default)]
    pub outcome_token_price: Option<f64>,
}

/// Response from `GET /portfolio/pnl-chart`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PnlChartResponse {
    #[serde(default)]
    pub data: Vec<PnlChartPoint>,
    #[serde(rename = "totalValue", default)]
    pub total_value: Option<f64>,
    #[serde(rename = "totalUnrealizedPnl", default)]
    pub total_unrealized_pnl: Option<f64>,
    #[serde(rename = "totalRealizedPnl", default)]
    pub total_realized_pnl: Option<f64>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PnlChartPoint {
    pub timestamp: i64,
    pub value: f64,
}

/// Response from `GET /portfolio/points`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PointsResponse {
    #[serde(default)]
    pub points: Option<f64>,
    #[serde(rename = "accumulativePoints", default)]
    pub accumulative_points: Option<f64>,
    #[serde(default)]
    pub breakdown: Vec<Value>,
}

/// Response from `GET /portfolio/history`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HistoryResponse {
    pub data: Vec<HistoryEntry>,
    #[serde(rename = "nextCursor")]
    pub next_cursor: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HistoryEntry {
    #[serde(rename = "blockTimestamp")]
    pub block_timestamp: i64,
    #[serde(rename = "collateralAmount", default)]
    pub collateral_amount: Option<String>,
    #[serde(default)]
    pub market: Option<HistoryMarketInfo>,
    #[serde(rename = "outcomeIndex", default)]
    pub outcome_index: Option<i32>,
    #[serde(rename = "outcomeTokenAmount", default)]
    pub outcome_token_amount: Option<String>,
    #[serde(rename = "outcomeTokenAmounts", default)]
    pub outcome_token_amounts: Option<Vec<String>>,
    #[serde(rename = "outcomeTokenPrice", default)]
    pub outcome_token_price: Option<Value>,
    #[serde(default)]
    pub strategy: Option<String>,
    #[serde(rename = "transactionHash", default)]
    pub transaction_hash: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HistoryMarketInfo {
    pub closed: bool,
    #[serde(default)]
    pub collateral: Option<Value>,
    #[serde(default)]
    pub group: Option<Value>,
    #[serde(rename = "conditionId", default)]
    pub condition_id: Option<String>,
    #[serde(default)]
    pub funding: Option<String>,
    pub id: String,
    pub slug: String,
    pub title: String,
    #[serde(rename = "expirationDate", default)]
    pub expiration_date: Option<String>,
}

/// Response from `GET /portfolio/trading/allowance`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AllowanceResponse {
    #[serde(default)]
    pub allowance: Option<String>,
    #[serde(rename = "allowanceFormatted", default)]
    pub allowance_formatted: Option<String>,
    #[serde(rename = "approvedSpender", default)]
    pub approved_spender: Option<String>,
    #[serde(rename = "approvedAmount", default)]
    pub approved_amount: Option<String>,
}

// ═══════════════════════════════════════════════════════════════════════════
//  Navigation
// ═══════════════════════════════════════════════════════════════════════════

/// Navigation tree node from `GET /navigation`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NavigationNode {
    pub id: String,
    pub name: String,
    pub slug: String,
    pub path: String,
    #[serde(default)]
    pub icon: Option<String>,
    #[serde(default)]
    pub children: Vec<NavigationNode>,
}

/// Market page from `GET /market-pages/by-path`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MarketPage {
    pub id: String,
    pub name: String,
    pub slug: String,
    #[serde(rename = "fullPath")]
    pub full_path: String,
    #[serde(default)]
    pub description: Option<String>,
    #[serde(rename = "baseFilter")]
    pub base_filter: Value,
    #[serde(rename = "filterGroups")]
    pub filter_groups: Vec<FilterGroupInfo>,
    pub metadata: Value,
    pub breadcrumb: Vec<BreadcrumbItem>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FilterGroupInfo {
    #[serde(default)]
    pub name: Option<String>,
    #[serde(default)]
    pub slug: Option<String>,
    #[serde(rename = "allowMultiple", default)]
    pub allow_multiple: Option<bool>,
    #[serde(default)]
    pub presentation: Option<String>,
    #[serde(default)]
    pub options: Vec<FilterGroupOption>,
    #[serde(default)]
    pub source: Option<Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FilterGroupOption {
    pub label: String,
    pub value: String,
    #[serde(default)]
    pub metadata: Option<Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BreadcrumbItem {
    pub name: String,
    pub slug: String,
    pub path: String,
}

/// Response from `GET /market-pages/:id/markets`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PageMarketsResponse {
    pub data: Vec<MarketSummary>,
    #[serde(default)]
    pub pagination: Option<OffsetPagination>,
    #[serde(default)]
    pub cursor: Option<CursorPagination>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OffsetPagination {
    pub page: i32,
    pub limit: i32,
    pub total: i32,
    #[serde(rename = "totalPages")]
    pub total_pages: i32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CursorPagination {
    #[serde(rename = "nextCursor", default)]
    pub next_cursor: Option<String>,
}

/// Property key from `GET /property-keys` and `GET /property-keys/:id`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PropertyKey {
    pub id: String,
    pub name: String,
    pub slug: String,
    #[serde(rename = "type")]
    pub property_type: String,
    pub metadata: Value,
    #[serde(rename = "isSystem")]
    pub is_system: bool,
    #[serde(default)]
    pub options: Vec<PropertyOption>,
    #[serde(rename = "createdAt")]
    pub created_at: String,
    #[serde(rename = "updatedAt")]
    pub updated_at: String,
}

/// Property option from `GET /property-keys/:id/options`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PropertyOption {
    pub id: String,
    #[serde(rename = "propertyKeyId")]
    pub property_key_id: String,
    pub value: String,
    pub label: String,
    #[serde(rename = "sortOrder")]
    pub sort_order: i32,
    #[serde(rename = "parentOptionId", default)]
    pub parent_option_id: Option<String>,
    pub metadata: Value,
    #[serde(rename = "createdAt")]
    pub created_at: String,
    #[serde(rename = "updatedAt")]
    pub updated_at: String,
}

// ═══════════════════════════════════════════════════════════════════════════
//  WebSocket events — OME, settlement, and position types
// ═══════════════════════════════════════════════════════════════════════════
//
// NOTE: General-purpose WS event types (OrderbookUpdate, TradeEvent,
// MarketCreatedEvent, NewPriceData, etc.) now live in `ws::channel`.
// The types below are the detailed OME/settlement/position events that
// are unique to this implementation.

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OmeEvent {
    pub source: String,
    #[serde(rename = "type")]
    pub event_type: String,
    #[serde(rename = "eventId")]
    pub event_id: u64,
    #[serde(rename = "orderId")]
    pub order_id: String,
    #[serde(rename = "clientOrderId")]
    pub client_order_id: Option<String>,
    #[serde(rename = "userId")]
    pub user_id: u64,
    #[serde(rename = "marketId")]
    pub market_id: String,
    pub token: String,
    pub side: String,
    pub price: String,
    #[serde(rename = "remainingSize")]
    pub remaining_size: String,
    pub timestamp: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SettlementEvent {
    pub source: String,
    #[serde(rename = "type")]
    pub event_type: String,
    #[serde(rename = "eventId")]
    pub event_id: String,
    #[serde(rename = "orderId")]
    pub order_id: Option<String>,
    #[serde(rename = "clientOrderId")]
    pub client_order_id: Option<String>,
    #[serde(rename = "userId")]
    pub user_id: u64,
    #[serde(rename = "takerOrderId")]
    pub taker_order_id: Option<String>,
    #[serde(rename = "takerAccount")]
    pub taker_account: Option<String>,
    #[serde(rename = "makerMatches")]
    pub maker_matches: Option<Vec<MakerMatch>>,
    #[serde(rename = "marketSlug")]
    pub market_slug: Option<String>,
    #[serde(rename = "txHash")]
    pub tx_hash: Option<String>,
    pub timestamp: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MakerMatch {
    pub account: String,
    #[serde(rename = "orderId")]
    pub order_id: String,
    #[serde(rename = "matchedSize")]
    pub matched_size: String,
    pub price: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum PositionUpdate {
    #[serde(rename = "AMM")]
    Amm(AmmPositionData),
    #[serde(rename = "CLOB")]
    Clob(ClobPositionData),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AmmPositionData {
    pub account: String,
    #[serde(rename = "marketAddress")]
    pub market_address: String,
    pub positions: Vec<AmmPosition>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AmmPosition {
    #[serde(rename = "tokenId")]
    pub token_id: String,
    pub balance: String,
    #[serde(rename = "outcomeIndex")]
    pub outcome_index: u8,
    #[serde(rename = "collateralOutOnSell")]
    pub collateral_out_on_sell: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClobPositionData {
    pub account: String,
    #[serde(rename = "marketSlug")]
    pub market_slug: String,
    pub positions: Vec<ClobPosition>,
    #[serde(rename = "tokenIds")]
    pub token_ids: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClobPosition {
    #[serde(rename = "tokenId")]
    pub token_id: String,
    #[serde(rename = "ctfBalance")]
    pub ctf_balance: String,
    #[serde(rename = "averageFillPrice")]
    pub average_fill_price: String,
    #[serde(rename = "costBasis")]
    pub cost_basis: String,
    #[serde(rename = "marketValue")]
    pub market_value: String,
    #[serde(rename = "marketId")]
    pub market_id: u64,
}