dydx-v3-rust 0.2.3

Rust SDK for dYdX v3 API
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
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ApiKeyCredentialsResponseObject {
    pub key: String,
    pub secret: String,
    pub passphrase: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ApiKeyCredentialsResponse {
    pub api_key: ApiKeyCredentialsResponseObject,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ApiKeysResponse {
    pub api_keys: Vec<ApiKeyResponseObject>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ApiKeyResponseObject {
    pub key: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ApiKeyCredentials<'a> {
    pub key: &'a str,
    pub secret: &'a str,
    pub passphrase: &'a str,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct KeyPairWithYCoordinate<'a> {
    pub public_key: &'a str,
    pub public_key_y_coordinate: &'a str,
    pub private_key: &'a str,
}

#[non_exhaustive]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OrderSide;

impl OrderSide {
    pub const BUY: &'static str = "BUY";
    pub const SELL: &'static str = "SELL";
}

#[non_exhaustive]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OrderType;

impl OrderType {
    pub const MARKET: &'static str = "MARKET";
    pub const LIMIT: &'static str = "LIMIT";
    pub const STOP_LIMIT: &'static str = "STOP_LIMIT";
    pub const TRAILING_STOP: &'static str = "TRAILING_STOP";
    pub const TAKE_PROFIT: &'static str = "TAKE_PROFIT";
}

#[non_exhaustive]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimeInForce;
impl TimeInForce {
    pub const GTT: &'static str = "GTT";
    pub const FOK: &'static str = "FOK";
    pub const IOC: &'static str = "IOC";
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MarketStatsResponse {
    pub markets: HashMap<String, MarketStats>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MarketStats {
    pub market: String,
    pub open: String,
    pub high: String,
    pub low: String,
    pub close: String,
    pub base_volume: String,
    pub quote_volume: String,
    #[serde(rename = "type")]
    pub type_field: String,
}

#[derive(Default, Debug, Serialize, Deserialize)]
pub struct MarketStatisticDay;
impl MarketStatisticDay {
    pub const ONE: &'static str = "1";
    pub const SEVEN: &'static str = "7";
    pub const THIRTY: &'static str = "30";
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct HistoricalFundingResponse {
    pub historical_funding: Vec<HistoricalFunding>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct HistoricalFunding {
    pub market: String,
    pub rate: String,
    pub price: String,
    pub effective_at: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ConfigResponse {
    pub collateral_asset_id: String,
    pub collateral_token_address: String,
    pub default_maker_fee: String,
    pub default_taker_fee: String,
    pub exchange_address: String,
    pub max_expected_batch_length_minutes: String,
    pub max_fast_withdrawal_amount: String,
    pub cancel_order_rate_limiting: CancelOrderRateLimiting,
    pub place_order_rate_limiting: PlaceOrderRateLimiting,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CancelOrderRateLimiting {
    pub max_points_multi: u32,
    pub max_points_single: u32,
    pub window_sec_multi: u32,
    pub window_sec_single: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PlaceOrderRateLimiting {
    pub max_points: u32,
    pub window_sec: u32,
    pub target_notional: u32,
    pub min_limit_consumption: u32,
    pub min_market_consumption: u32,
    pub min_triggerable_consumption: u32,
    pub max_order_consumption: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LeaderboardPnlResponse {
    pub top_pnls: Vec<PNLForPeriod>,
    pub num_participants: u32,
    pub started_at: Option<String>,
    pub ends_at: Option<String>,
    pub updated_at: String,
    pub season_number: Option<u16>,
    pub prize_pool: Option<u32>,
    pub num_hedgies_winners: Option<u16>,
    pub num_prize_winners: Option<u16>,
    pub ratio_promoted: Option<f32>,
    pub ratio_demoted: Option<f32>,
    pub minimum_equity: Option<u16>,
    pub minimum_dydx_tokens: Option<u16>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PNLForPeriod {
    pub username: Option<String>,
    pub ethereum_address: Option<String>,
    pub public_id: String,
    pub absolute_pnl: String,
    pub percent_pnl: String,
    pub absolute_rank: u32,
    pub percent_rank: u32,
    pub season_expected_outcome: Option<String>,
    pub hedgie_won: Option<u16>,
    pub prize_won: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UserExistsResponse {
    pub exists: bool,
    pub is_proxy_signer: bool,
    pub contract_address: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UsernameExistsResponse {
    pub exists: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GetTimeResponse {
    pub iso: String,
    pub epoch: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CurrentlyRevealedHedgies {
    pub daily: HedgiePeriodResponseObject,
    pub weekly: HedgiePeriodResponseObject,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct HedgiePeriodResponse {
    pub historical_token_ids: Vec<HedgiePeriodResponseObject>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct HedgiePeriodResponseObject {
    pub block_number: String,
    pub token_ids: Vec<String>,
    pub competition_period: u16,
}

#[derive(Default, Debug, Serialize, Deserialize)]
#[non_exhaustive]
pub struct NftRevealType;
impl NftRevealType {
    pub const DAY: &'static str = "daily";
    pub const WEEK: &'static str = "weekly";
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InsuranceFundBalanceResponse {
    pub balance: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProfilePublicResponse {
    pub username: Option<String>,
    pub ethereum_address: String,
    #[serde(rename = "DYDXHoldings")]
    pub dydx_holdings: String,
    #[serde(rename = "stakedDYDXHoldings")]
    pub staked_dydx_holdings: String,
    pub hedgies_held: Vec<u16>,
    pub twitter_handle: String,
    pub trading_leagues: TradingLeagues,
    pub trading_pnls: TradingPnls,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProfilePrivateResponse {
    pub username: Option<String>,
    pub public_id: String,
    pub ethereum_address: String,
    #[serde(rename = "DYDXHoldings")]
    pub dydx_holdings: String,
    #[serde(rename = "stakedDYDXHoldings")]
    pub staked_dydx_holdings: String,
    pub hedgies_held: Vec<u16>,
    pub twitter_handle: String,
    pub affiliate_link: Option<String>,
    pub trading_leagues: TradingLeagues,
    pub trading_pnls: TradingPnls,
    pub trading_rewards: TradingRewards,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TradingLeagues {
    pub current_league: Option<String>,
    pub current_league_ranking: Option<u32>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TradingPnls {
    pub absolute_pnl30_d: Option<String>,
    pub percent_pnl30_d: Option<String>,
    pub volume30_d: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TradingRewards {
    pub cur_epoch: u16,
    pub cur_epoch_estimated_rewards: String,
    pub prev_epoch_estimated_rewards: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MarketsResponse {
    pub markets: HashMap<String, MarketData>,
}

#[derive(Default, Debug, Serialize, Deserialize)]
pub struct CandleResolution;
impl CandleResolution {
    pub const ONE_DAY: &'static str = "1DAY";
    pub const FOUR_HOURS: &'static str = "4HOURS";
    pub const ONE_HOUR: &'static str = "1HOUR";
    pub const THIRTY_MINS: &'static str = "30MINS";
    pub const FIFTEEN_MINS: &'static str = "15MINS";
    pub const FIVE_MINS: &'static str = "5MINS";
    pub const ONE_MIN: &'static str = "1MIN";
}

#[derive(Default, Debug, Serialize, Deserialize)]
#[non_exhaustive]
pub struct DydxMarket;

impl DydxMarket {
    pub const BTC_USD: &'static str = "BTC-USD";
    pub const SUSHI_USD: &'static str = "SUSHI-USD";
    pub const AVAX_USD: &'static str = "AVAX-USD";
    pub const INCH_USD: &'static str = "1INCH-USD";
    pub const ETH_USD: &'static str = "ETH-USD";
    pub const XMR_USD: &'static str = "XMR-USD";
    pub const COMP_USD: &'static str = "COMP-USD";
    pub const ALGO_USD: &'static str = "ALGO-USD";
    pub const BCH_USD: &'static str = "BCH-USD";
    pub const CRV_USD: &'static str = "CRV-USD";
    pub const ETC_USD: &'static str = "ETC-USD";
    pub const UNI_USD: &'static str = "UNI-USD";
    pub const MKR_USD: &'static str = "MKR-USD";
    pub const LTC_USD: &'static str = "LTC-USD";
    pub const EOS_USD: &'static str = "EOS-USD";
    pub const DOGE_USD: &'static str = "DOGE-USD";
    pub const ATOM_USD: &'static str = "ATOM-USD";
    pub const ZRX_USD: &'static str = "ZRX-USD";
    pub const SOL_USD: &'static str = "SOL-USD";
    pub const UMA_USD: &'static str = "UMA-USD";
    pub const AAVE_USD: &'static str = "AAVE-USD";
    pub const ADA_USD: &'static str = "ADA-USD";
    pub const SNX_USD: &'static str = "SNX-USD";
    pub const FIL_USD: &'static str = "FIL-USD";
    pub const ZEC_USD: &'static str = "ZEC-USD";
    pub const YFI_USD: &'static str = "YFI-USD";
    pub const XLM_USD: &'static str = "XLM-USD";
    pub const LINK_USD: &'static str = "LINK-USD";
    pub const DOT_USD: &'static str = "DOT-USD";
    pub const MATIC_USD: &'static str = "MATIC-USD";
    pub const ENJ_USD: &'static str = "ENJ-USD";
    pub const NEAR_USD: &'static str = "NEAR-USD";
    pub const LUNA_USD: &'static str = "LUNA-USD";
    pub const CELO_USD: &'static str = "CELO-USD";
    pub const XTZ_USD: &'static str = "XTZ-USD";
    pub const RUNE_USD: &'static str = "RUNE-USD";
    pub const TRX_USD: &'static str = "TRX-USD";
    pub const ICP_USD: &'static str = "ICP-USD";
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MarketData {
    pub market: String,
    pub status: String,
    pub base_asset: String,
    pub quote_asset: String,
    pub step_size: String,
    pub tick_size: String,
    pub index_price: String,
    pub oracle_price: String,
    #[serde(rename = "priceChange24H")]
    pub price_change24h: String,
    pub next_funding_rate: String,
    pub next_funding_at: String,
    pub min_order_size: String,
    #[serde(rename = "type")]
    pub type_field: String,
    pub initial_margin_fraction: String,
    pub maintenance_margin_fraction: String,
    #[serde(rename = "volume24H")]
    pub volume24h: String,
    #[serde(rename = "trades24H")]
    pub trades24h: String,
    pub open_interest: String,
    pub incremental_initial_margin_fraction: String,
    pub incremental_position_size: String,
    pub max_position_size: String,
    pub baseline_position_size: String,
    pub asset_resolution: String,
    pub synthetic_asset_id: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OrderbookResponse {
    pub asks: Vec<OrderbookResponseOrder>,
    pub bids: Vec<OrderbookResponseOrder>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OrderbookResponseOrder {
    pub size: String,
    pub price: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Trade {
    pub side: String,
    pub size: String,
    pub price: String,
    pub created_at: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TradesResponse {
    pub trades: Vec<Trade>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Candle {
    pub started_at: String,
    pub updated_at: String,
    pub market: String,
    // pub resolution: CandleResolution;
    pub resolution: String,
    pub low: String,
    pub high: String,
    pub open: String,
    pub close: String,
    pub base_token_volume: String,
    pub trades: String,
    pub usd_volume: String,
    pub starting_open_interest: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CandlesResponse {
    pub candles: Vec<Candle>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AccountResponse {
    pub account: AccountObject,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AccountsResponse {
    pub accounts: Vec<AccountObject>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AccountObject {
    pub stark_key: String,
    pub position_id: String,
    pub equity: String,
    pub free_collateral: String,
    pub pending_deposits: String,
    pub pending_withdrawals: String,
    pub open_positions: HashMap<String, PositionResponseObject>,
    pub account_number: String,
    pub id: String,
    pub quote_balance: String,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RecoveryResponse {
    pub stark_key: String,
    pub position_id: String,
    pub quote_balance: String,
    pub positions: Vec<PositionResponseObject>,
    pub equity: String,
    pub free_collateral: String,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PositionsResponse {
    pub positions: Vec<PositionResponseObject>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PositionResponseObject {
    // pub market: Market;
    pub market: String,
    // pub status: PositionStatus,
    pub status: String,
    pub side: String,
    pub size: String,
    pub max_size: String,
    pub entry_price: String,
    pub exit_price: Option<String>,
    pub unrealized_pnl: String,
    pub realized_pnl: Option<String>,
    pub created_at: String,
    pub closed_at: Option<String>,
    pub sum_open: Option<String>,
    pub sum_close: Option<String>,
    pub net_funding: Option<String>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ApiOrder<'a> {
    pub market: &'a str,
    pub side: &'a str,
    #[serde(rename = "type")]
    pub type_field: &'a str,
    pub time_in_force: &'a str,
    pub post_only: bool,
    pub size: &'a str,
    pub price: &'a str,
    pub limit_fee: &'a str,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cancel_id: Option<&'a str>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub trigger_price: Option<&'a str>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub trailing_percent: Option<&'a str>,
    pub expiration: &'a str,
    pub client_id: &'a str,
    pub signature: &'a str,
}

#[derive(Debug, Clone, Serialize)]
pub struct ApiOrderParams<'a> {
    pub position_id: &'a str,
    pub market: &'a str,
    pub side: &'a str,
    #[serde(rename = "type")]
    pub type_field: &'a str,
    pub size: &'a str,
    pub price: &'a str,
    pub time_in_force: &'a str,
    pub post_only: bool,
    pub limit_fee: &'a str,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub client_id: Option<&'a str>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cancel_id: Option<&'a str>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub trigger_price: Option<&'a str>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub trailing_percent: Option<&'a str>,
    pub expiration: i64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OrderResponse {
    pub order: OrderResponseObject,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OrdersResponse {
    pub orders: Vec<OrderResponseObject>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActiveOrdersResponse {
    pub orders: Vec<ActiveOrderResponseObject>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActiveOrderResponseObject {
    pub id: String,
    pub account_id: String,
    pub market: String,
    pub side: String,
    pub price: String,
    pub remaining_size: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FillsResponse {
    pub fills: Vec<FillResponseObject>,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FundingResponse {
    pub funding_payments: Vec<FundingResponseObject>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct HistoricalPnlResponse {
    pub historical_pnl: Vec<HistoricalPnlResponseObject>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct HistoricalPnlResponseObject {
    pub equity: String,
    pub total_pnl: String,
    pub created_at: String,
    pub net_transfers: String,
    pub account_id: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FundingResponseObject {
    pub market: String,
    pub payment: String,
    pub rate: String,
    pub position_size: String,
    pub price: String,
    pub effective_at: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TradingRewardsResponse {
    pub epoch: u16,
    pub epoch_start: String,
    pub epoch_end: String,
    pub fees: Fees,
    pub open_interest: OpenInterest,
    pub weight: Weight,
    #[serde(rename = "stakedDYDX")]
    pub staked_dydx: StakedDYDX,
    pub total_rewards: String,
    pub estimated_rewards: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Weight {
    pub weight: String,
    pub total_weight: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Fees {
    pub fees_paid: String,
    pub total_fees_paid: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OpenInterest {
    pub average_open_interest: String,
    pub total_average_open_interest: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LiquidityProviderRewardsResponse {
    pub epoch: u16,
    pub epoch_start: String,
    pub epoch_end: String,
    pub markets: HashMap<String, LiquidityRewards>,
    #[serde(rename = "stakedDYDX")]
    pub staked_dydx: LiqStakedDYDX,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LiquidityRewards {
    pub market: String,
    pub depth_spread_score: String,
    pub uptime: String,
    pub max_uptime: String,
    pub score: String,
    pub total_score: String,
    pub maker_volume: String,
    pub total_maker_volume: String,
    pub total_rewards: String,
    pub estimated_rewards: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LiqStakedDYDX {
    #[serde(rename = "averageStakedDYDX")]
    pub average_staked_dydx: String,
    #[serde(rename = "totalAverageStakedDYDX")]
    pub total_average_staked_dydx: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StakedDYDX {
    #[serde(rename = "averageStakedDYDX")]
    pub average_staked_dydx: String,
    #[serde(rename = "averageStakedDYDXWithFloor")]
    pub average_staked_dydxwith_floor: String,
    #[serde(rename = "totalAverageStakedDYDX")]
    pub total_average_staked_dydx: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RetroactiveMiningRewardsResponse {
    pub epoch: u16,
    pub epoch_start: String,
    pub epoch_end: String,
    pub retroactive_mining: RetroactiveMiningRewardsResponseObject,
    pub estimated_rewards: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RetroactiveMiningRewardsResponseObject {
    pub allocation: String,
    pub target_volume: String,
    pub volume: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PublicRetroactiveMiningRewardsResponse {
    pub allocation: String,
    pub target_volume: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FillResponseObject {
    pub id: String,
    pub side: String,
    pub liquidity: String,
    #[serde(rename = "type")]
    pub type_field: String,
    pub market: String,
    pub order_id: String,
    pub price: String,
    pub size: String,
    pub fee: String,
    pub created_at: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RegistrationResponse {
    pub signature: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AccountPnlsResponse {
    pub absolute_pnl: String,
    pub percent_pnl: String,
    pub absolute_rank: Option<u16>,
    pub percent_rank: Option<u16>,
    pub started_at: Option<String>,
    pub ends_at: Option<String>,
    pub updated_at: String,
    pub period: String,
    pub season_expected_outcome: Option<String>,
    pub season_number: Option<String>,
    pub hedgie_won: Option<String>,
    pub prize_won: Option<String>,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct HistoricalLeaderboardPnlsResponse {
    pub leaderboard_pnls: Vec<AccountPnlsResponse>,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct HistoricalLeaderboardPnlsResponseObject {}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OrderResponseObject {
    pub id: String,
    pub client_id: String,
    pub account_id: String,
    pub market: String,
    pub side: String,
    pub price: String,
    pub trigger_price: Option<String>,
    pub trailing_percent: Option<String>,
    pub size: String,
    pub remaining_size: String,
    #[serde(rename = "type")]
    pub type_field: String,
    pub created_at: String,
    pub unfillable_at: Option<String>,
    pub expires_at: Option<String>,
    pub status: String,
    pub time_in_force: String,
    pub post_only: bool,
    pub cancel_reason: Option<String>,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CancelOrderResponse {
    pub cancel_order: OrderResponseObject,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CancelOrdersResponse {
    pub cancel_orders: Vec<OrderResponseObject>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UserResponseObject {
    pub public_id: String,
    pub ethereum_address: String,
    pub is_registered: bool,
    pub email: Option<String>,
    pub username: Option<String>,
    pub user_data: Value,
    pub maker_fee_rate: Option<String>,
    pub taker_fee_rate: Option<String>,
    pub maker_volume30_d: Option<String>,
    pub taker_volume30_d: Option<String>,
    pub fees30_d: Option<String>,
    pub referred_by_affiliate_link: Option<String>,
    pub is_sharing_username: Option<bool>,
    pub is_sharing_address: Option<bool>,
    pub dydx_token_balance: String,
    pub staked_dydx_token_balance: String,
    pub active_staked_dydx_token_balance: String,
    pub is_email_verified: bool,
    pub country: Option<String>,
    pub hedgies_held: Vec<usize>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UserResponse {
    pub user: UserResponseObject,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UserParams<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub email: Option<&'a str>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub country: Option<&'a str>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_sharing_address: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_sharing_username: Option<bool>,
    pub user_data: &'a str,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub username: Option<&'a str>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateUserParams<'a> {
    pub stark_key: &'a str,
    pub stark_key_y_coordinate: &'a str,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub referred_by_affiliate_link: Option<&'a str>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub country: Option<&'a str>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TransferResponseObject {
    pub id: String,
    #[serde(rename = "type")]
    pub type_field: String,
    pub debit_asset: String,
    pub credit_asset: String,
    pub debit_amount: String,
    pub credit_amount: String,
    pub transaction_hash: Option<String>,
    pub status: String,
    pub created_at: String,
    pub confirmed_at: Option<String>,
    pub client_id: String,
    pub from_address: Option<String>,
    pub to_address: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransferResponse {
    pub transfer: TransferResponseObject,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransfersResponse {
    pub transfers: Vec<TransferResponseObject>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WithdrawalResponse {
    pub withdrawal: TransferResponseObject,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateAccountParams<'a> {
    pub stark_key: &'a str,
    pub stark_key_y_coordinate: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TransferParams<'a> {
    pub amount: &'a str,
    pub position_id: &'a str,
    pub receiver_account_id: &'a str,
    pub receiver_public_key: &'a str,
    pub receiver_position_id: &'a str,
    pub expiration: i64,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ApiTransfer<'a> {
    pub amount: &'a str,
    pub receiver_account_id: &'a str,
    pub expiration: &'a str,
    pub client_id: &'a str,
    pub signature: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ApiWithdrawParams<'a> {
    pub position_id: &'a str,
    pub amount: &'a str,
    pub asset: &'a str,
    pub expiration: i64,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ApiWithdraw<'a> {
    pub amount: &'a str,
    pub asset: &'a str,
    pub expiration: &'a str,
    pub client_id: &'a str,
    pub signature: &'a str,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ApiFastWithdrawalParams<'a> {
    pub position_id: &'a str,
    pub credit_asset: &'a str,
    pub credit_amount: &'a str,
    pub debit_amount: &'a str,
    pub to_address: &'a str,
    pub lp_position_id: &'a str,
    pub lp_stark_key: &'a str,
    pub expiration: i64,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ApiFastWithdrawal<'a> {
    pub credit_asset: &'a str,
    pub credit_amount: &'a str,
    pub debit_amount: &'a str,
    pub to_address: &'a str,
    pub lp_position_id: &'a str,
    pub expiration: &'a str,
    pub client_id: &'a str,
    pub signature: &'a str,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateUserResponse {
    pub api_key: ApiKeyCredentialsResponseObject,
    pub user: UserResponseObject,
    pub account: AccountObject,
}