ax-exchange-sdk 13.35.0

ArchitectX SDK
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
use crate::{
    protocol::{
        common::{Fill, Timestamp},
        marketdata_publisher::{Ticker, Trade},
        pagination::{TimeseriesPage, TimeseriesPagination},
    },
    types::{ApiKeyType, BboCandle, Candle, Instrument, Token},
    Side,
};
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use serde_with::{formats::CommaSeparator, serde_as, StringWithSeparator};
use std::collections::HashMap;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct ChangePasswordRequest {
    pub username: String,
    pub password: String,
    /// Optional 2FA code, if 2FA is enabled/required for the user.
    pub totp: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct ChangePasswordResponse {
    pub message: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct ResetPasswordRequest {
    pub username: String,
    pub new_password: String,
    pub password_reset_code: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct ResetPasswordResponse {}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct CreateApiKeyRequest {
    pub username: String,
    pub password: String,
    /// Optional 2FA code, if 2FA is enabled/required for the user.
    pub totp: Option<String>,
    #[serde(default)]
    pub key_type: Option<ApiKeyType>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct CreateApiKeyResponse {
    pub api_key: String,
    pub api_secret: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct ApiKeyInfo {
    pub api_key: String,
    pub key_type: ApiKeyType,
    pub created_at: chrono::DateTime<chrono::Utc>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetApiKeysResponse {
    pub api_keys: Vec<ApiKeyInfo>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
pub struct RevokeApiKeyRequest {
    pub api_key: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct RevokeApiKeyResponse {
    pub message: String,
}

/// Exchange credentials for a bearer token.
///
/// Must provide exactly one of:
///
/// - `username` + `password`
/// - `api_key` + `secret`
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct AuthenticateRequest {
    #[serde(flatten)]
    pub auth: AuthenticationMethod,
    pub expiration_seconds: i32,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde(untagged)]
pub enum AuthenticationMethod {
    UsernamePassword {
        username: String,
        password: String,
        /// Optional 2FA code, if 2FA is enabled/required for the user.
        totp: Option<String>,
    },
    ApiKeySecret {
        api_key: String,
        api_secret: String,
    },
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct AuthenticateResponse {
    pub token: Token,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct LoginRequest {
    #[serde(flatten)]
    pub auth: AuthenticationMethod,
    pub expiration_seconds: i32,
    /// Redirect URL to redirect to after successful login.
    pub redirect_url: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct WhoAmIResponse {
    pub id: String,
    pub username: String,
    pub created_at: DateTime<Utc>,
    pub enabled_2fa: bool,
    pub is_onboarded: bool,
    pub is_close_only: bool,
    pub is_frozen: bool,
    pub is_admin: bool,
    pub maker_fee: Decimal,
    pub taker_fee: Decimal,
    pub require_2fa: bool,
    pub fiat_deposit_code: String,
    #[serde(default)]
    pub accounts: Vec<WhoAmIAccount>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct WhoAmIAccount {
    pub id: String,
    pub name: String,
    pub ep3_username: String,
    pub ep3_account: String,
    pub is_close_only: bool,
    pub is_frozen: bool,
    pub maker_fee: Decimal,
    pub taker_fee: Decimal,
    pub can_list: bool,
    pub can_read: bool,
    pub can_set_limits: bool,
    pub can_reduce_or_close: bool,
    pub can_trade: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetCustomerResponse {
    pub business_name: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
pub struct GetInstrumentRequest {
    pub symbol: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde(transparent)]
pub struct GetInstrumentResponse(pub Instrument);

impl GetInstrumentResponse {
    pub fn into_inner(self) -> Instrument {
        self.0
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetInstrumentsResponse {
    pub instruments: Vec<GetInstrumentResponse>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
pub struct GetTickerRequest {
    pub symbol: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetTickerResponse {
    pub ticker: Ticker,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetTickersResponse {
    pub tickers: Vec<Ticker>,
}

#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
pub struct GetTransactionsRequest {
    #[serde_as(as = "StringWithSeparator::<CommaSeparator, String>")]
    pub transaction_types: Vec<String>,
}

/// Query parameters for `GET /transactions` (session-authenticated user), including optional
/// time range, sort direction, cursor, and page size.
#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
pub struct GetTransactionsQueryParams {
    #[serde(flatten)]
    pub request: GetTransactionsRequest,
    #[serde(flatten)]
    pub timeseries: TimeseriesPagination,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct Transaction {
    pub user_id: String,
    pub event_id: String,
    pub symbol: String,
    pub timestamp: DateTime<Utc>,
    pub amount: Decimal,
    pub transaction_type: String,
    pub reference_id: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetTransactionsResponse {
    pub transactions: Vec<Transaction>,
    #[serde(flatten)]
    pub page: TimeseriesPage,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct FundingTransaction {
    pub user_id: String,
    pub currency: String,
    pub timestamp: DateTime<Utc>,
    pub transaction_type: String,
    pub amount: Decimal,
    pub event_id: String,
    pub sequence_number: i32,
    pub reference_id: Option<String>,
    pub symbol: String,
    pub funding_rate: Decimal,
    pub funding_amount: Decimal,
    pub benchmark_price: Decimal,
    pub settlement_price: Decimal,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetFundingTransactionsResponse {
    pub funding_transactions: Vec<FundingTransaction>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct Setup2faResponse {
    pub validate_token: String,
    /// The `uri` field contains a provisioning URI following the
    /// Google Authenticator format:
    ///
    /// `otpauth://totp/ADX:username?secret=BASE32SECRET&issuer=ADX&algorithm=SHA1&digits=6&period=30`
    ///
    /// This URI encodes all TOTP parameters and is typically displayed
    /// as a QR code for client apps to scan.
    pub uri: String,
    pub secret: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct Confirm2faRequest {
    pub validate_token: String,
    pub code: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct Confirm2faResponse {
    pub success: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct Disable2faResponse {
    pub message: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct SandboxDepositRequest {
    pub symbol: String,
    pub amount: Decimal,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct SandboxWithdrawalRequest {
    pub symbol: String,
    pub amount: Decimal,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetPositionsResponse {
    pub positions: Vec<Position>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct Position {
    pub user_id: String,
    pub symbol: String,
    pub signed_quantity: i64,
    pub signed_notional: Decimal,
    pub timestamp: DateTime<Utc>,
    pub realized_pnl: Decimal,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
pub struct GetFillsRequest {
    #[serde(flatten)]
    pub timeseries: TimeseriesPagination,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetFillsResponse {
    pub fills: Vec<Fill>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct AdminTrade {
    pub trade_id: String,
    pub timestamp: DateTime<Utc>,
    pub symbol: String,
    pub price: Decimal,
    pub quantity: u64,
    pub maker_user_id: String,
    pub taker_user_id: String,
    pub taker_side: Side,
    pub maker_fee: Decimal,
    pub taker_fee: Decimal,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetAdminTradesResponse {
    pub trades: Vec<AdminTrade>,
    #[serde(flatten)]
    pub page: TimeseriesPage,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetBalancesResponse {
    pub balances: Vec<Balance>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub usd_borrow: Option<Decimal>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct Balance {
    pub symbol: String,
    pub amount: Decimal,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct SymbolRiskSnapshot {
    pub signed_quantity: i64,
    pub signed_notional: Decimal,
    pub average_price: Option<Decimal>,
    pub initial_margin_required_position: Decimal,
    pub initial_margin_required_open_orders: Decimal,
    pub initial_margin_required_total: Decimal,
    pub maintenance_margin_required: Decimal,
    pub unrealized_pnl: Decimal,
    pub liquidation_price: Option<Decimal>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct UserRiskSnapshot {
    pub user_id: String,
    pub timestamp_ns: DateTime<Utc>,
    pub per_symbol: HashMap<String, SymbolRiskSnapshot>,
    pub initial_margin_required_for_positions: Decimal,
    pub initial_margin_required_for_open_orders: Decimal,
    pub initial_margin_required_total: Decimal,
    pub maintenance_margin_required: Decimal,
    pub unrealized_pnl: Decimal,
    pub equity: Decimal,
    pub initial_margin_available: Decimal,
    pub maintenance_margin_available: Decimal,
    pub balance_usd: Decimal,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetRiskSnapshotResponse {
    pub risk_snapshot: UserRiskSnapshot,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_get_user_token_request_serde() {
        let json = r#"
        {
            "username": "testuser",
            "password": "password",
            "expiration_seconds": 3600
        }
        "#;
        let req: AuthenticateRequest = serde_json::from_str(json).unwrap();
        assert_eq!(
            req,
            AuthenticateRequest {
                auth: AuthenticationMethod::UsernamePassword {
                    username: "testuser".to_string(),
                    password: "password".to_string(),
                    totp: None,
                },
                expiration_seconds: 3600,
            }
        );

        let json = r#"
        {
            "api_key": "testapikey",
            "api_secret": "testsecret",
            "expiration_seconds": 3600
        }
        "#;
        let req: AuthenticateRequest = serde_json::from_str(json).unwrap();
        assert_eq!(
            req,
            AuthenticateRequest {
                auth: AuthenticationMethod::ApiKeySecret {
                    api_key: "testapikey".to_string(),
                    api_secret: "testsecret".to_string(),
                },
                expiration_seconds: 3600,
            }
        );
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
pub struct GetTradesRequest {
    pub symbol: String,
    /// The maximum number of trades to return, up to 100 trades. Defaults to 10.
    pub limit: Option<u32>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetTradesResponse {
    pub trades: Vec<Trade>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
pub struct GetCandlesRequest {
    pub symbol: String,
    pub start_timestamp_ns: u64,
    pub end_timestamp_ns: u64,
    pub candle_width: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetCandlesResponse {
    pub candles: Vec<Candle>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
pub struct GetCandleRequest {
    pub symbol: String,
    pub candle_width: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetCandleResponse {
    pub candle: Candle,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
pub struct GetBboCandlesRequest {
    pub symbol: String,
    pub start_timestamp_ns: u64,
    pub end_timestamp_ns: u64,
    pub candle_width: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetBboCandlesResponse {
    pub candles: Vec<BboCandle>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
pub struct GetBboCandleRequest {
    pub symbol: String,
    pub candle_width: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetBboCandleResponse {
    pub candle: BboCandle,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
pub struct GetFundingRatesRequest {
    pub symbol: String,
    pub start_timestamp_ns: u64,
    pub end_timestamp_ns: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetFundingRatesResponse {
    pub funding_rates: Vec<FundingRate>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct FundingRate {
    pub symbol: String,
    pub timestamp_ns: u64,
    pub funding_rate: Decimal,
    pub funding_amount: Decimal,
    pub benchmark_price: Decimal,
    pub settlement_price: Decimal,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
pub struct GetAccountEquityHistoryRequest {
    pub start_timestamp_ns: u64,
    pub end_timestamp_ns: u64,
    /// Desired duration between returned points.
    pub resolution_seconds: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct AccountEquityPoint {
    #[serde(rename = "t")]
    pub timestamp_ns: u64,
    #[serde(rename = "v")]
    pub equity: Decimal,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetAccountEquityHistoryResponse {
    pub data_points: Vec<AccountEquityPoint>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct SignupRequest {
    pub username: String,
    pub password: String,
    pub invite_code: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct SignupResponse {
    pub user_id: String,
}

/// Default orderbook depth level when not specified (Level 2: aggregated quantities)
pub const DEFAULT_BOOK_LEVEL: u8 = 2;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
pub struct GetBookRequest {
    pub symbol: String,
    /// Orderbook depth level (2 or 3). Defaults to 2 if not specified.
    /// - 2: Returns aggregated quantity per price level
    /// - 3: Returns individual order quantities per price level
    pub level: Option<u8>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetBookResponse {
    pub book: GetBookResponseBook,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetBookResponseBook {
    #[serde(rename = "s")]
    pub symbol: String,
    #[serde(rename = "b")]
    pub bids: Vec<GetBookResponseBookLevel>,
    #[serde(rename = "a")]
    pub offers: Vec<GetBookResponseBookLevel>,
    #[serde(flatten)]
    pub timestamp: Timestamp,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetBookResponseBookLevel {
    #[serde(rename = "p")]
    pub price: Decimal,
    #[serde(rename = "q")]
    pub total_quantity: u64,
    #[serde(rename = "o")]
    pub orders: Option<Vec<u64>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct PreviewAggressiveLimitOrderRequest {
    pub symbol: String,
    pub quantity: u64,
    pub side: Side,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct PreviewAggressiveLimitOrderResponse {
    pub limit_price: Option<Decimal>,
    pub vwap: Option<Decimal>,
    pub filled_quantity: u64,
    pub remaining_quantity: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
pub struct GetIndexPricesRequest {
    pub symbol: String,
    #[serde(flatten)]
    pub timeseries: TimeseriesPagination,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetIndexPricesResponse {
    pub index_prices: Vec<IndexPrice>,
    #[serde(flatten)]
    pub page: TimeseriesPage,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct IndexPrice {
    pub symbol: String,
    pub timestamp: DateTime<Utc>,
    pub price: Decimal,
}