1use bigdecimal::BigDecimal;
2use chrono::{DateTime, Utc};
3use derive_more::{Display, From};
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6
7use crate::indexer::types::*;
8
9#[derive(Deserialize)]
11#[serde(rename_all = "camelCase")]
12#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
13pub struct ResponseError {
14 pub errors: Vec<ErrorMsg>,
16}
17
18#[derive(Deserialize)]
20#[serde(rename_all = "camelCase")]
21#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
22pub struct ErrorMsg {
23 pub msg: String,
25 pub param: String,
27 pub location: String,
29}
30
31#[derive(Deserialize, Debug, Clone, From, Display, PartialEq, Eq, PartialOrd, Ord, Hash)]
33pub struct PnlTickId(pub String);
34
35#[derive(
37 Deserialize, Serialize, Debug, Clone, Copy, From, Display, PartialEq, Eq, PartialOrd, Ord, Hash,
38)]
39#[serde(rename_all = "lowercase")]
40pub enum PnlTickInterval {
41 Hour,
43 Day,
45}
46
47#[derive(
49 Serialize, Deserialize, Debug, Clone, From, Display, PartialEq, Eq, PartialOrd, Ord, Hash,
50)]
51pub struct TransferId(pub String);
52
53#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
55#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
56pub enum TradingRewardAggregationPeriod {
57 Daily,
59 Weekly,
61 Monthly,
63}
64
65#[derive(Serialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
67#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
68pub enum SparklineTimePeriod {
69 OneDay,
71 SevenDays,
73}
74
75#[derive(Deserialize, Debug, Clone)]
77#[serde(rename_all = "camelCase")]
78#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
79pub struct HistoricalFundingResponse {
80 pub historical_funding: Vec<HistoricalFundingResponseObject>,
82}
83
84#[derive(Deserialize, Debug, Clone)]
86#[serde(rename_all = "camelCase")]
87#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
88pub struct HistoricalFundingResponseObject {
89 pub ticker: Ticker,
91 pub effective_at: DateTime<Utc>,
93 pub effective_at_height: Height,
95 pub price: Price,
97 pub rate: BigDecimal,
99}
100
101pub type SparklineResponseObject = HashMap<Ticker, Vec<BigDecimal>>;
103
104#[derive(Deserialize, Debug, Clone)]
106#[serde(rename_all = "camelCase")]
107#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
108pub struct TimeResponse {
109 pub iso: DateTime<Utc>,
111 pub epoch: f64,
113}
114
115#[derive(Deserialize, Debug, Clone)]
117#[serde(rename_all = "camelCase")]
118#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
119pub struct ComplianceResponse {
120 pub restricted: bool,
122 pub reason: Option<String>,
124}
125
126#[derive(Deserialize, Debug, Clone)]
128#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
129pub enum ComplianceStatus {
130 Compliant,
132 FirstStrikeCloseOnly,
134 FirstStrike,
136 CloseOnly,
138 Blocked,
140}
141
142#[derive(Deserialize, Debug, Clone)]
144#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
145pub enum ComplianceReason {
146 Manual,
148 UsGeo,
150 CaGeo,
152 GbGeo,
154 SanctionedGeo,
156 ComplianceProvider,
158}
159
160#[derive(Deserialize, Debug, Clone)]
162#[serde(rename_all = "camelCase")]
163#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
164pub struct ComplianceV2Response {
165 pub status: ComplianceStatus,
167 pub reason: Option<ComplianceReason>,
169 pub updated_at: Option<DateTime<Utc>>,
171}
172
173#[derive(Deserialize, Debug, Clone)]
175#[serde(rename_all = "camelCase")]
176#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
177pub struct AddressResponse {
178 pub subaccounts: Vec<SubaccountResponseObject>,
180 pub total_trading_rewards: BigDecimal,
182}
183
184#[derive(Deserialize, Debug, Clone)]
186#[serde(rename_all = "camelCase")]
187#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
188pub struct SubaccountResponse {
189 pub subaccount: SubaccountResponseObject,
191}
192
193#[derive(Deserialize, Debug, Clone)]
195#[serde(rename_all = "camelCase")]
196#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
197pub struct ParentSubaccountResponse {
198 pub subaccount: ParentSubaccountResponseObject,
200}
201
202#[derive(Deserialize, Debug, Clone)]
204#[serde(rename_all = "camelCase")]
205#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
206pub struct AssetPositionResponse {
207 pub positions: Vec<AssetPositionResponseObject>,
209}
210
211#[derive(Deserialize, Debug, Clone)]
213#[serde(rename_all = "camelCase")]
214#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
215pub struct PerpetualPositionResponse {
216 pub positions: Vec<PerpetualPositionResponseObject>,
218}
219
220#[derive(Serialize, Default, Debug, Clone)]
222#[serde(rename_all = "camelCase")]
223#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
224pub struct PaginationRequest {
225 pub limit: Option<u32>,
227 pub offset: Option<u32>,
229}
230
231#[derive(Deserialize, Debug, Clone)]
233#[serde(rename_all = "camelCase")]
234#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
235pub struct AffiliateMetadataResponse {
236 pub referral_code: String,
238 pub is_volume_eligible: bool,
240 pub is_affiliate: bool,
242}
243
244#[derive(Deserialize, Debug, Clone)]
246#[serde(rename_all = "camelCase")]
247#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
248pub struct AffiliateAddressResponse {
249 pub address: Address,
251}
252
253#[derive(Deserialize, Debug, Clone)]
255#[serde(rename_all = "camelCase")]
256#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
257pub struct AffiliateSnapshotResponse {
258 pub affiliate_list: Vec<AffiliateSnapshotResponseObject>,
260 pub total: u32,
262 pub current_offset: u32,
264}
265
266#[derive(Deserialize, Debug, Clone)]
268#[serde(rename_all = "camelCase")]
269#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
270pub struct AffiliateSnapshotResponseObject {
271 pub affiliate_address: Address,
273 pub affiliate_referral_code: String,
275 pub affiliate_earnings: BigDecimal,
277 pub affiliate_referred_trades: u32,
279 pub affiliate_total_referred_fees: BigDecimal,
281 pub affiliate_referred_users: u32,
283 pub affiliate_referred_net_protocol_earnings: BigDecimal,
285 pub affiliate_referred_total_volume: BigDecimal,
287 pub affiliate_referred_maker_fees: BigDecimal,
289 pub affiliate_referred_taker_fees: BigDecimal,
291 pub affiliate_referred_maker_rebates: BigDecimal,
293}
294
295#[derive(Deserialize, Debug, Clone)]
297#[serde(rename_all = "camelCase")]
298#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
299pub struct AffiliateTotalVolumeResponse {
300 pub total_volume: Option<BigDecimal>,
302}
303
304#[derive(Deserialize, Debug, Clone)]
306#[serde(rename_all = "camelCase")]
307#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
308pub struct PaginationResponse {
309 pub page_size: Option<u32>,
311 pub total_results: Option<u32>,
313 pub offset: Option<u32>,
315}
316
317#[derive(Deserialize, Debug, Clone)]
319#[serde(rename_all = "camelCase")]
320#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
321pub struct TransferResponse {
322 pub transfers: Vec<TransferResponseObject>,
324 #[serde(flatten)]
326 pub pagination: PaginationResponse,
327}
328
329#[derive(Deserialize, Debug, Clone)]
331#[serde(rename_all = "camelCase")]
332#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
333pub struct ParentSubaccountTransferResponse {
334 pub transfers: Vec<ParentSubaccountTransferResponseObject>,
336}
337
338#[derive(Deserialize, Debug, Clone)]
340#[serde(rename_all = "camelCase")]
341#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
342pub struct TraderSearchResponse {
343 pub result: Option<TraderSearchResponseObject>,
345}
346
347#[derive(Deserialize, Debug, Clone)]
349#[serde(rename_all = "camelCase")]
350#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
351pub struct TraderSearchResponseObject {
352 pub address: Address,
354 pub subaccount_number: SubaccountNumber,
356 pub subaccount_id: SubaccountId,
358 pub username: String,
360}
361
362#[derive(Deserialize, Debug, Clone)]
364#[serde(rename_all = "camelCase")]
365#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
366pub struct TransferBetweenResponse {
367 pub transfers_subset: Vec<TransferResponseObject>,
369 pub total_net_transfers: BigDecimal,
371 #[serde(flatten)]
373 pub pagination: PaginationResponse,
374}
375
376#[derive(Deserialize, Debug, Clone)]
378#[serde(rename_all = "camelCase")]
379#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
380pub struct FundingPaymentResponse {
381 pub funding_payments: Vec<FundingPaymentResponseObject>,
383 #[serde(flatten)]
385 pub pagination: PaginationResponse,
386}
387
388#[derive(Deserialize, Debug, Clone)]
390#[serde(rename_all = "camelCase")]
391#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
392pub struct FundingPaymentResponseObject {
393 pub created_at: DateTime<Utc>,
395 pub created_at_height: Height,
397 pub perpetual_id: String,
399 pub ticker: Ticker,
401 pub oracle_price: BigDecimal,
403 pub size: BigDecimal,
405 pub side: FundingOrderSide,
407 pub rate: BigDecimal,
409 pub payment: BigDecimal,
411 pub subaccount_number: SubaccountNumber,
413 pub funding_index: String,
415}
416
417#[derive(Deserialize, Debug, Clone)]
419#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
420pub enum FundingOrderSide {
421 Long,
423 Short,
425}
426
427#[derive(Deserialize, Debug, Clone)]
430#[serde(rename_all = "camelCase")]
431#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
432pub struct TransferResponseObject {
433 pub id: TransferId,
435 pub sender: Account,
437 pub recipient: Account,
439 pub size: BigDecimal,
441 pub created_at: DateTime<Utc>,
443 pub created_at_height: Height,
445 pub symbol: Symbol,
447 #[serde(rename = "type")]
449 pub transfer_type: TransferType,
450 pub transaction_hash: String,
452}
453
454#[derive(Deserialize, Debug, Clone)]
456#[serde(rename_all = "camelCase")]
457#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
458pub struct ParentSubaccountTransferResponseObject {
459 pub id: TransferId,
461 pub sender: AccountWithParentSubaccountNumber,
463 pub recipient: AccountWithParentSubaccountNumber,
465 pub size: BigDecimal,
467 pub created_at: DateTime<Utc>,
469 pub created_at_height: Height,
471 pub symbol: Symbol,
473 #[serde(rename = "type")]
475 pub transfer_type: TransferType,
476 pub transaction_hash: String,
478}
479
480pub type ListOrdersResponse = Vec<OrderResponseObject>;
482
483#[derive(Deserialize, Debug, Clone)]
485#[serde(rename_all = "camelCase")]
486#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
487pub struct FillResponse {
488 pub fills: Vec<FillResponseObject>,
490}
491
492#[derive(Deserialize, Debug, Clone)]
494#[serde(rename_all = "camelCase")]
495#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
496pub struct FillResponseObject {
497 pub id: FillId,
499 pub side: OrderSide,
501 pub liquidity: Liquidity,
503 #[serde(rename = "type")]
505 pub fill_type: FillType,
506 pub market: Ticker,
508 pub market_type: MarketType,
510 pub price: Price,
512 pub size: BigDecimal,
514 pub fee: BigDecimal,
516 pub affiliate_rev_share: BigDecimal,
518 pub created_at: DateTime<Utc>,
520 pub created_at_height: Height,
522 pub order_id: Option<OrderId>,
524 pub client_metadata: Option<ClientMetadata>,
526 pub subaccount_number: SubaccountNumber,
528 pub builder_fee: Option<BigDecimal>,
530 pub builder_address: Option<Address>,
532 pub order_router_address: Option<Address>,
534 pub order_router_fee: Option<BigDecimal>,
536}
537
538#[derive(Deserialize, Debug, Clone)]
540#[serde(rename_all = "camelCase")]
541#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
542pub struct HistoricalPnlResponse {
543 pub historical_pnl: Vec<PnlTicksResponseObject>,
545}
546
547#[derive(Deserialize, Debug, Clone)]
549#[serde(rename_all = "camelCase")]
550#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
551pub struct PnlTicksResponseObject {
552 pub block_height: Height,
554 pub block_time: DateTime<Utc>,
556 pub created_at: DateTime<Utc>,
558 pub equity: BigDecimal,
560 pub total_pnl: BigDecimal,
562 pub net_transfers: BigDecimal,
564}
565
566#[derive(Deserialize, Debug, Clone)]
568#[serde(rename_all = "camelCase")]
569#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
570pub struct HistoricalBlockTradingRewardsResponse {
571 pub rewards: Vec<HistoricalBlockTradingReward>,
573}
574
575#[derive(Deserialize, Debug, Clone)]
577#[serde(rename_all = "camelCase")]
578#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
579pub struct HistoricalBlockTradingReward {
580 pub trading_reward: BigDecimal,
582 pub created_at_height: Height,
584 pub created_at: DateTime<Utc>,
586}
587
588#[derive(Deserialize, Debug, Clone)]
590#[serde(rename_all = "camelCase")]
591#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
592pub struct HistoricalTradingRewardAggregationsResponse {
593 pub rewards: Vec<HistoricalTradingRewardAggregation>,
595}
596
597#[derive(Deserialize, Debug, Clone)]
599#[serde(rename_all = "camelCase")]
600#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
601pub struct HistoricalTradingRewardAggregation {
602 pub trading_reward: BigDecimal,
604 pub started_at_height: Height,
606 pub started_at: DateTime<Utc>,
608 pub ended_at_height: Option<Height>,
610 pub ended_at: Option<DateTime<Utc>>,
612 pub period: TradingRewardAggregationPeriod,
614}
615
616#[derive(Deserialize, Debug, Clone)]
618#[serde(rename_all = "camelCase")]
619#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
620pub struct MegaVaultHistoricalPnlResponse {
621 pub megavault_pnl: Vec<PnlTicksResponseObject>,
623}
624
625#[derive(Deserialize, Debug, Clone)]
627#[serde(rename_all = "camelCase")]
628#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
629pub struct MegaVaultPositionResponse {
630 pub positions: Vec<VaultPosition>,
632}
633
634#[derive(Deserialize, Debug, Clone)]
636#[serde(rename_all = "camelCase")]
637#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
638pub struct VaultsHistoricalPnLResponse {
639 pub vaults_pnl: Vec<VaultHistoricalPnl>,
641}
642
643#[derive(Deserialize, Debug, Clone)]
645#[serde(rename_all = "camelCase")]
646#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
647pub struct VaultHistoricalPnl {
648 pub ticker: String,
650 pub historical_pnl: Vec<PnlTicksResponseObject>,
652}
653
654#[derive(Deserialize, Debug, Clone)]
656#[serde(rename_all = "camelCase")]
657#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
658pub struct VaultPosition {
659 pub ticker: String,
661 pub asset_position: Option<AssetPositionResponseObject>,
663 pub perpetual_position: Option<PerpetualPositionResponseObject>,
665 pub equity: BigDecimal,
667}