hyperliquid_rs/types/
trade.rs

1use serde::{Deserialize, Serialize};
2
3use crate::types::order::{OrderStatusResponse, OrderType};
4use serde_repr::{Deserialize_repr, Serialize_repr};
5
6#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
7#[serde(rename_all = "camelCase")]
8pub enum Side {
9    Buy,
10    Sell,
11}
12
13#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
14#[serde(rename_all = "camelCase")]
15pub enum ContractType {
16    Perpetual,
17}
18
19#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr)]
20#[repr(i32)]
21pub enum PositionSide {
22    Long = 1,
23    Short = -1,
24}
25
26#[derive(Debug, Clone, Serialize)]
27pub struct OpenPositionRequest {
28    pub coin: String,
29    pub is_buy: bool,
30    pub sz: String,
31    pub limit_px: String,
32    pub order_type: OrderType,
33}
34
35#[derive(Debug, Clone, Deserialize)]
36pub struct MarginSummary {
37    pub account_value: String,
38    pub total_margin_used: String,
39    pub total_ntl_pos: String,
40    pub total_raw_usd: String,
41}
42
43#[derive(Debug, Clone, Deserialize)]
44pub struct CrossMarginSummary {
45    pub account_value: f64,
46    pub total_margin_used: f64,
47    pub total_ntl_pos: f64,
48    pub total_raw_usd: f64,
49}
50
51#[derive(Debug, Clone, Deserialize)]
52pub struct AssetPosition {
53    pub coin: String,
54    pub position: Position,
55}
56
57#[derive(Debug, Clone, Deserialize)]
58pub struct Position {
59    pub coin: String,
60    pub szi: String,
61    pub entry_px: String,
62    pub position_value: String,
63    pub unrealized_pnl: String,
64    pub return_on_equity: String,
65    pub liquidation_px: Option<String>,
66    pub margin_used: String,
67}
68
69#[derive(Debug, Clone, Deserialize)]
70pub struct TradeResult {
71    pub type_field: String,
72    pub data: TradeData,
73}
74
75#[derive(Debug, Clone, Deserialize)]
76pub struct TradeData {
77    pub statuses: Vec<OrderStatusResponse>,
78}