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, PartialEq)]
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(
51 Debug, Clone, Copy, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize,
52)]
53pub enum Resolution {
54 /// 1 minute candles
55 #[default]
56 #[serde(rename = "1m")]
57 OneMinute,
58 /// 5 minute candles
59 #[serde(rename = "5m")]
60 FiveMinutes,
61 /// 15 minute candles
62 #[serde(rename = "15m")]
63 FifteenMinutes,
64 /// 1 hour candles
65 #[serde(rename = "1h")]
66 OneHour,
67 /// 4 hour candles
68 #[serde(rename = "4h")]
69 FourHours,
70 /// 1 day candles
71 #[serde(rename = "1d")]
72 OneDay,
73}
74
75impl Resolution {
76 /// Get the string representation.
77 pub fn as_str(&self) -> &'static str {
78 match self {
79 Self::OneMinute => "1m",
80 Self::FiveMinutes => "5m",
81 Self::FifteenMinutes => "15m",
82 Self::OneHour => "1h",
83 Self::FourHours => "4h",
84 Self::OneDay => "1d",
85 }
86 }
87}
88
89impl std::fmt::Display for Resolution {
90 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
91 write!(f, "{}", self.as_str())
92 }
93}