use bigdecimal::BigDecimal;
use chrono::{DateTime, Utc};
use derive_more::{Display, From};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::indexer::types::*;
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct ResponseError {
pub errors: Vec<ErrorMsg>,
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct ErrorMsg {
pub msg: String,
pub param: String,
pub location: String,
}
#[derive(Deserialize, Debug, Clone, From, Display, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PnlTickId(pub String);
#[derive(
Deserialize, Serialize, Debug, Clone, Copy, From, Display, PartialEq, Eq, PartialOrd, Ord, Hash,
)]
#[serde(rename_all = "lowercase")]
pub enum PnlTickInterval {
Hour,
Day,
}
#[derive(
Serialize, Deserialize, Debug, Clone, From, Display, PartialEq, Eq, PartialOrd, Ord, Hash,
)]
pub struct TransferId(pub String);
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum TradingRewardAggregationPeriod {
Daily,
Weekly,
Monthly,
}
#[derive(Serialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum SparklineTimePeriod {
OneDay,
SevenDays,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct HistoricalFundingResponse {
pub historical_funding: Vec<HistoricalFundingResponseObject>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct HistoricalFundingResponseObject {
pub ticker: Ticker,
pub effective_at: DateTime<Utc>,
pub effective_at_height: Height,
pub price: Price,
pub rate: BigDecimal,
}
pub type SparklineResponseObject = HashMap<Ticker, Vec<BigDecimal>>;
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct TimeResponse {
pub iso: DateTime<Utc>,
pub epoch: f64,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct ComplianceResponse {
pub restricted: bool,
pub reason: Option<String>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ComplianceStatus {
Compliant,
FirstStrikeCloseOnly,
FirstStrike,
CloseOnly,
Blocked,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ComplianceReason {
Manual,
UsGeo,
CaGeo,
GbGeo,
SanctionedGeo,
ComplianceProvider,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct ComplianceV2Response {
pub status: ComplianceStatus,
pub reason: Option<ComplianceReason>,
pub updated_at: Option<DateTime<Utc>>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct AddressResponse {
pub subaccounts: Vec<SubaccountResponseObject>,
pub total_trading_rewards: BigDecimal,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct SubaccountResponse {
pub subaccount: SubaccountResponseObject,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct ParentSubaccountResponse {
pub subaccount: ParentSubaccountResponseObject,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct AssetPositionResponse {
pub positions: Vec<AssetPositionResponseObject>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct PerpetualPositionResponse {
pub positions: Vec<PerpetualPositionResponseObject>,
}
#[derive(Serialize, Default, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct PaginationRequest {
pub limit: Option<u32>,
pub offset: Option<u32>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct AffiliateMetadataResponse {
pub referral_code: String,
pub is_volume_eligible: bool,
pub is_affiliate: bool,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct AffiliateAddressResponse {
pub address: Address,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct AffiliateSnapshotResponse {
pub affiliate_list: Vec<AffiliateSnapshotResponseObject>,
pub total: u32,
pub current_offset: u32,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct AffiliateSnapshotResponseObject {
pub affiliate_address: Address,
pub affiliate_referral_code: String,
pub affiliate_earnings: BigDecimal,
pub affiliate_referred_trades: u32,
pub affiliate_total_referred_fees: BigDecimal,
pub affiliate_referred_users: u32,
pub affiliate_referred_net_protocol_earnings: BigDecimal,
pub affiliate_referred_total_volume: BigDecimal,
pub affiliate_referred_maker_fees: BigDecimal,
pub affiliate_referred_taker_fees: BigDecimal,
pub affiliate_referred_maker_rebates: BigDecimal,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct AffiliateTotalVolumeResponse {
pub total_volume: Option<BigDecimal>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct PaginationResponse {
pub page_size: Option<u32>,
pub total_results: Option<u32>,
pub offset: Option<u32>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct TransferResponse {
pub transfers: Vec<TransferResponseObject>,
#[serde(flatten)]
pub pagination: PaginationResponse,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct ParentSubaccountTransferResponse {
pub transfers: Vec<ParentSubaccountTransferResponseObject>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct TraderSearchResponse {
pub result: Option<TraderSearchResponseObject>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct TraderSearchResponseObject {
pub address: Address,
pub subaccount_number: SubaccountNumber,
pub subaccount_id: SubaccountId,
pub username: String,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct TransferBetweenResponse {
pub transfers_subset: Vec<TransferResponseObject>,
pub total_net_transfers: BigDecimal,
#[serde(flatten)]
pub pagination: PaginationResponse,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct FundingPaymentResponse {
pub funding_payments: Vec<FundingPaymentResponseObject>,
#[serde(flatten)]
pub pagination: PaginationResponse,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct FundingPaymentResponseObject {
pub created_at: DateTime<Utc>,
pub created_at_height: Height,
pub perpetual_id: String,
pub ticker: Ticker,
pub oracle_price: BigDecimal,
pub size: BigDecimal,
pub side: FundingOrderSide,
pub rate: BigDecimal,
pub payment: BigDecimal,
pub subaccount_number: SubaccountNumber,
pub funding_index: String,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum FundingOrderSide {
Long,
Short,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct TransferResponseObject {
pub id: TransferId,
pub sender: Account,
pub recipient: Account,
pub size: BigDecimal,
pub created_at: DateTime<Utc>,
pub created_at_height: Height,
pub symbol: Symbol,
#[serde(rename = "type")]
pub transfer_type: TransferType,
pub transaction_hash: String,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct ParentSubaccountTransferResponseObject {
pub id: TransferId,
pub sender: AccountWithParentSubaccountNumber,
pub recipient: AccountWithParentSubaccountNumber,
pub size: BigDecimal,
pub created_at: DateTime<Utc>,
pub created_at_height: Height,
pub symbol: Symbol,
#[serde(rename = "type")]
pub transfer_type: TransferType,
pub transaction_hash: String,
}
pub type ListOrdersResponse = Vec<OrderResponseObject>;
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct FillResponse {
pub fills: Vec<FillResponseObject>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct FillResponseObject {
pub id: FillId,
pub side: OrderSide,
pub liquidity: Liquidity,
#[serde(rename = "type")]
pub fill_type: FillType,
pub market: Ticker,
pub market_type: MarketType,
pub price: Price,
pub size: BigDecimal,
pub fee: BigDecimal,
pub affiliate_rev_share: BigDecimal,
pub created_at: DateTime<Utc>,
pub created_at_height: Height,
pub order_id: Option<OrderId>,
pub client_metadata: Option<ClientMetadata>,
pub subaccount_number: SubaccountNumber,
pub builder_fee: Option<BigDecimal>,
pub builder_address: Option<Address>,
pub order_router_address: Option<Address>,
pub order_router_fee: Option<BigDecimal>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct HistoricalPnlResponse {
pub historical_pnl: Vec<PnlTicksResponseObject>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct PnlTicksResponseObject {
pub block_height: Height,
pub block_time: DateTime<Utc>,
pub created_at: DateTime<Utc>,
pub equity: BigDecimal,
pub total_pnl: BigDecimal,
pub net_transfers: BigDecimal,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct HistoricalBlockTradingRewardsResponse {
pub rewards: Vec<HistoricalBlockTradingReward>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct HistoricalBlockTradingReward {
pub trading_reward: BigDecimal,
pub created_at_height: Height,
pub created_at: DateTime<Utc>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct HistoricalTradingRewardAggregationsResponse {
pub rewards: Vec<HistoricalTradingRewardAggregation>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct HistoricalTradingRewardAggregation {
pub trading_reward: BigDecimal,
pub started_at_height: Height,
pub started_at: DateTime<Utc>,
pub ended_at_height: Option<Height>,
pub ended_at: Option<DateTime<Utc>>,
pub period: TradingRewardAggregationPeriod,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct MegaVaultHistoricalPnlResponse {
pub megavault_pnl: Vec<PnlTicksResponseObject>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct MegaVaultPositionResponse {
pub positions: Vec<VaultPosition>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct VaultsHistoricalPnLResponse {
pub vaults_pnl: Vec<VaultHistoricalPnl>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct VaultHistoricalPnl {
pub ticker: String,
pub historical_pnl: Vec<PnlTicksResponseObject>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(any(test, feature = "strict-serde"), serde(deny_unknown_fields))]
pub struct VaultPosition {
pub ticker: String,
pub asset_position: Option<AssetPositionResponseObject>,
pub perpetual_position: Option<PerpetualPositionResponseObject>,
pub equity: BigDecimal,
}