use alloy_primitives::{Address, U256};
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct TradingPair {
pub id: String,
pub base_asset: String,
pub quote_asset: String,
pub symbol: String,
pub is_active: bool,
pub min_position_size: Decimal,
pub max_position_size: Decimal,
pub price_precision: u8,
pub quantity_precision: u8,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Price {
pub symbol: String,
pub mark_price: Decimal,
pub index_price: Decimal,
pub high_24h: Decimal,
pub low_24h: Decimal,
pub volume_24h: Decimal,
pub timestamp: DateTime<Utc>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TradingHours {
pub symbol: String,
pub is_open: bool,
pub next_open: Option<DateTime<Utc>>,
pub next_close: Option<DateTime<Utc>>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum PositionSide {
Long,
Short,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum OrderType {
Market,
Limit,
StopMarket,
StopLimit,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum OrderStatus {
Pending,
PartiallyFilled,
Filled,
Cancelled,
Rejected,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Position {
pub id: String,
pub symbol: String,
pub side: PositionSide,
pub size: Decimal,
pub entry_price: Decimal,
pub mark_price: Decimal,
pub unrealized_pnl: Decimal,
pub realized_pnl: Decimal,
pub margin: Decimal,
pub leverage: Decimal,
pub liquidation_price: Option<Decimal>,
pub take_profit: Option<Decimal>,
pub stop_loss: Option<Decimal>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Order {
pub id: String,
pub symbol: String,
pub order_type: OrderType,
pub side: PositionSide,
pub size: Decimal,
pub price: Option<Decimal>,
pub stop_price: Option<Decimal>,
pub status: OrderStatus,
pub filled_size: Decimal,
pub avg_fill_price: Option<Decimal>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Balance {
pub asset: String,
pub available: Decimal,
pub locked: Decimal,
pub total: Decimal,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct OpenInterestInfo {
pub symbol: String,
pub total_open_interest: Decimal,
pub long_open_interest: Decimal,
pub short_open_interest: Decimal,
pub max_open_interest: Decimal,
pub utilization_percent: Decimal,
pub is_capped: bool,
}
#[derive(Debug, Clone)]
pub struct OpenInterestCapResult {
pub would_exceed_cap: bool,
pub current_utilization: Decimal,
pub projected_utilization: Decimal,
pub available_capacity: Decimal,
pub max_recommended_size: Decimal,
}
pub type TxHash = alloy_primitives::TxHash;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct OpenPositionParams {
pub symbol: String,
pub side: PositionSide,
pub size: Decimal,
pub leverage: Decimal,
pub take_profit: Option<Decimal>,
pub stop_loss: Option<Decimal>,
pub slippage_tolerance: Decimal,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AdvancedOrderParams {
pub symbol: String,
pub side: PositionSide,
pub size: Decimal,
pub leverage: Decimal,
pub order_type: OrderExecutionType,
pub price: Option<Decimal>,
pub take_profit: Option<Decimal>,
pub stop_loss: Option<Decimal>,
pub slippage_tolerance: Decimal,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum OrderExecutionType {
Market,
Limit,
Stop,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct LimitOrderParams {
pub symbol: String,
pub side: PositionSide,
pub size: Decimal,
pub leverage: Decimal,
pub limit_price: Decimal,
pub take_profit: Option<Decimal>,
pub stop_loss: Option<Decimal>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct StopOrderParams {
pub symbol: String,
pub side: PositionSide,
pub size: Decimal,
pub leverage: Decimal,
pub stop_price: Decimal,
pub take_profit: Option<Decimal>,
pub stop_loss: Option<Decimal>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CancelOrderParams {
pub order_id: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct UpdateLimitOrderParams {
pub order_id: String,
pub limit_price: Option<Decimal>,
pub take_profit: Option<Decimal>,
pub stop_loss: Option<Decimal>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ClosePositionParams {
pub position_id: String,
pub size: Option<Decimal>,
pub slippage_tolerance: Decimal,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct UpdateTPSLParams {
pub position_id: String,
pub take_profit: Option<Decimal>,
pub stop_loss: Option<Decimal>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum OpenOrderType {
Market,
Limit,
Stop,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Trade {
pub collateral: U256,
pub open_price: u128,
pub tp: u128,
pub sl: u128,
pub trader: Address,
pub leverage: u32,
pub pair_index: u16,
pub index: u8,
pub buy: bool,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct OpenLimitOrder {
pub collateral: U256,
pub target_price: u128,
pub tp: u128,
pub sl: u128,
pub trader: Address,
pub leverage: u32,
pub created_at: u32,
pub last_updated: u32,
pub pair_index: u16,
pub order_type: u8,
pub index: u8,
pub buy: bool,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct UnsignedTransaction {
pub to: Address,
pub data: Vec<u8>,
pub value: U256,
pub gas_limit: Option<U256>,
pub gas_price: Option<U256>,
pub chain_id: u64,
pub nonce: Option<u64>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct UnsignedTransactionParams {
pub from: Address,
pub include_gas_estimates: bool,
pub include_nonce: bool,
}