lightcone_sdk/shared/types.rs
1//! Shared type definitions for the Lightcone SDK.
2//!
3//! This module contains types that are used by both the REST API and WebSocket modules.
4
5use serde::{Deserialize, Serialize};
6
7// ============================================================================
8// SubmitOrderRequest (shared between program and API modules)
9// ============================================================================
10
11/// Request for submitting an order via REST API.
12///
13/// This type bridges the program module (on-chain order signing) with the API module
14/// (REST order submission). Use `FullOrder::to_submit_request()` to convert a signed
15/// order to this format.
16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct SubmitOrderRequest {
18 /// Order creator's pubkey (Base58)
19 pub maker: String,
20 /// User's nonce for uniqueness
21 pub nonce: u64,
22 /// Market address (Base58)
23 pub market_pubkey: String,
24 /// Token being bought/sold (Base58)
25 pub base_token: String,
26 /// Token used for payment (Base58)
27 pub quote_token: String,
28 /// Order side (0=BID, 1=ASK)
29 pub side: u32,
30 /// Amount maker gives
31 pub maker_amount: u64,
32 /// Amount maker wants to receive
33 pub taker_amount: u64,
34 /// Unix timestamp, 0=no expiration
35 #[serde(default)]
36 pub expiration: i64,
37 /// Ed25519 signature (hex, 128 chars)
38 pub signature: String,
39 /// Target orderbook
40 pub orderbook_id: String,
41}
42
43// ============================================================================
44// Resolution Enum (shared between API and WebSocket)
45// ============================================================================
46
47/// Price history candle resolution.
48///
49/// Used by both REST API and WebSocket for price history queries.
50#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
51pub enum Resolution {
52 /// 1 minute candles
53 #[default]
54 #[serde(rename = "1m")]
55 OneMinute,
56 /// 5 minute candles
57 #[serde(rename = "5m")]
58 FiveMinutes,
59 /// 15 minute candles
60 #[serde(rename = "15m")]
61 FifteenMinutes,
62 /// 1 hour candles
63 #[serde(rename = "1h")]
64 OneHour,
65 /// 4 hour candles
66 #[serde(rename = "4h")]
67 FourHours,
68 /// 1 day candles
69 #[serde(rename = "1d")]
70 OneDay,
71}
72
73impl Resolution {
74 /// Get the string representation.
75 pub fn as_str(&self) -> &'static str {
76 match self {
77 Self::OneMinute => "1m",
78 Self::FiveMinutes => "5m",
79 Self::FifteenMinutes => "15m",
80 Self::OneHour => "1h",
81 Self::FourHours => "4h",
82 Self::OneDay => "1d",
83 }
84 }
85}
86
87impl std::fmt::Display for Resolution {
88 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
89 write!(f, "{}", self.as_str())
90 }
91}