Skip to main content

polyester/models/
market.rs

1//! Market-data SDK models (Go `models/market.go` / `models/common.go` parity).
2
3use crate::types::{Price, Quantity};
4use serde_json::Value;
5
6/// Options for [`crate::services::MarketDataService::get_candles_with`].
7#[derive(Debug, Clone, Default)]
8pub struct GetCandlesOpts {
9    pub symbol: Option<String>,
10    pub symbol_id: Option<u32>,
11    /// Candle interval alias (`"1m"`, `"MIN_1"`, …). Default `"1m"` when empty.
12    pub timeframe: String,
13    pub limit: Option<u32>,
14    /// Inclusive lower bound (unix seconds UTC).
15    pub start: Option<i64>,
16    /// Inclusive upper bound (unix seconds UTC).
17    pub end: Option<i64>,
18    pub include_incomplete: bool,
19    pub page_token: Option<String>,
20}
21
22/// Options for [`crate::services::MarketDataService::get_trades_with`].
23#[derive(Debug, Clone, Default)]
24pub struct GetTradesOpts {
25    pub symbol: Option<String>,
26    pub symbol_id: Option<u32>,
27    pub limit: Option<u32>,
28    /// Inclusive lower bound (unix seconds UTC).
29    pub start: Option<i64>,
30    /// Inclusive upper bound (unix seconds UTC).
31    pub end: Option<i64>,
32    pub page_token: Option<String>,
33}
34
35/// Spot pair catalog payload (Go `SpotConfig` raw-map escape hatch).
36#[derive(Debug, Clone, PartialEq)]
37pub struct SpotConfig {
38    pub raw: Value,
39}
40
41#[derive(Debug, Clone, PartialEq, Eq)]
42pub struct Candle {
43    pub ts_sec: i64,
44    pub open: String,
45    pub high: String,
46    pub low: String,
47    pub close: String,
48    pub volume: String,
49    pub symbol_id: u32,
50    pub timeframe: String,
51}
52
53#[derive(Debug, Clone, PartialEq, Eq)]
54pub struct CandlesResult {
55    pub symbol_id: u32,
56    pub timeframe: String,
57    pub candles: Vec<Candle>,
58    pub next_page_token: String,
59}
60
61#[derive(Debug, Clone, PartialEq, Eq)]
62pub struct MarketTrade {
63    pub symbol_id: u32,
64    pub match_id: String,
65    pub price: Option<Price>,
66    pub qty: Option<Quantity>,
67    pub ts_ns: String,
68    pub side: String,
69}
70
71#[derive(Debug, Clone, PartialEq, Eq)]
72pub struct MarketTradesResult {
73    pub trades: Vec<MarketTrade>,
74    pub next_page_token: String,
75}
76
77#[derive(Debug, Clone, PartialEq, Eq)]
78pub struct MarketOverviewEntry {
79    pub symbol_id: u32,
80    pub symbol: String,
81    pub last_price: Option<Price>,
82}
83
84#[derive(Debug, Clone, PartialEq, Eq)]
85pub struct MarketOverviewList {
86    pub markets: Vec<MarketOverviewEntry>,
87    pub next_page_token: String,
88}
89
90#[derive(Debug, Clone, PartialEq, Eq)]
91pub struct OrderbookLevel {
92    pub price: Option<Price>,
93    pub qty: Option<Quantity>,
94}
95
96#[derive(Debug, Clone, PartialEq, Eq)]
97pub struct OrderbookData {
98    pub symbol: String,
99    pub depth: u32,
100    pub book_seq: String,
101    pub bids: Vec<OrderbookLevel>,
102    pub asks: Vec<OrderbookLevel>,
103}