Skip to main content

rust_okx/api/public_data/
responses.rs

1use serde::Deserialize;
2
3use crate::{
4    NumberString,
5    model::{InstType, RestRow},
6};
7
8/// Option summary row.
9pub type OptionSummary = RestRow;
10
11/// Estimated delivery or exercise price row.
12pub type EstimatedPrice = RestRow;
13
14/// Discount-rate and interest-free quota row.
15pub type DiscountRateInterestFreeQuota = RestRow;
16
17/// Interest-rate loan quota row.
18pub type InterestRateLoanQuota = RestRow;
19
20/// VIP interest-rate loan quota row.
21pub type VipInterestRateLoanQuota = RestRow;
22
23/// Instrument tick-band row.
24pub type InstrumentTickBand = RestRow;
25
26/// Public option-trade row.
27pub type PublicOptionTrade = RestRow;
28
29/// Market-data history row.
30pub type MarketDataHistory = RestRow;
31
32/// A tradable instrument.
33///
34/// Only commonly used fields are modeled; the struct is `#[non_exhaustive]` and
35/// unknown JSON fields are ignored, so OKX additions are non-breaking.
36#[derive(Debug, Clone, Deserialize)]
37#[serde(rename_all = "camelCase")]
38#[non_exhaustive]
39pub struct Instrument {
40    /// Instrument type.
41    pub inst_type: InstType,
42    /// Instrument ID, e.g. `BTC-USDT`.
43    pub inst_id: String,
44    /// Underlying, e.g. `BTC-USD` (derivatives only).
45    #[serde(default)]
46    pub uly: String,
47    /// Instrument family, e.g. `BTC-USD` (derivatives only).
48    #[serde(default)]
49    pub inst_family: String,
50    /// Base currency, e.g. `BTC` (spot/margin only).
51    #[serde(default)]
52    pub base_ccy: String,
53    /// Quote currency, e.g. `USDT` (spot/margin only).
54    #[serde(default)]
55    pub quote_ccy: String,
56    /// Settlement currency (derivatives only).
57    #[serde(default)]
58    pub settle_ccy: String,
59    /// Lot size (order size increment).
60    #[serde(default)]
61    pub lot_sz: NumberString,
62    /// Tick size (price increment).
63    #[serde(default)]
64    pub tick_sz: NumberString,
65    /// Minimum order size.
66    #[serde(default)]
67    pub min_sz: NumberString,
68    /// Instrument lifecycle state, e.g. `live`, `suspend`.
69    #[serde(default)]
70    pub state: String,
71}
72
73/// OKX system time.
74#[derive(Debug, Clone, Deserialize)]
75#[serde(rename_all = "camelCase")]
76#[non_exhaustive]
77pub struct SystemTime {
78    /// Current OKX system timestamp in Unix milliseconds.
79    pub ts: NumberString,
80}
81
82/// Open interest for an instrument.
83#[derive(Debug, Clone, Deserialize)]
84#[serde(rename_all = "camelCase")]
85#[non_exhaustive]
86pub struct OpenInterest {
87    /// Instrument type.
88    pub inst_type: InstType,
89    /// Instrument ID.
90    pub inst_id: String,
91    /// Open interest in contracts.
92    #[serde(default)]
93    pub oi: NumberString,
94    /// Open interest in coin/currency units.
95    #[serde(default)]
96    pub oi_ccy: NumberString,
97    /// Timestamp (Unix milliseconds).
98    #[serde(default)]
99    pub ts: NumberString,
100}
101
102/// Current funding-rate information.
103#[derive(Debug, Clone, Deserialize)]
104#[serde(rename_all = "camelCase")]
105#[non_exhaustive]
106pub struct FundingRate {
107    /// Instrument type.
108    #[serde(default)]
109    pub inst_type: String,
110    /// Instrument ID.
111    pub inst_id: String,
112    /// Current funding rate.
113    #[serde(default)]
114    pub funding_rate: NumberString,
115    /// Next estimated funding rate.
116    #[serde(default)]
117    pub next_funding_rate: NumberString,
118    /// Funding time (Unix milliseconds).
119    #[serde(default)]
120    pub funding_time: NumberString,
121    /// Next funding time (Unix milliseconds).
122    #[serde(default)]
123    pub next_funding_time: NumberString,
124}
125
126/// Historical funding-rate row.
127#[derive(Debug, Clone, Deserialize)]
128#[serde(rename_all = "camelCase")]
129#[non_exhaustive]
130pub struct FundingRateHistory {
131    /// Instrument ID.
132    pub inst_id: String,
133    /// Funding rate.
134    #[serde(default)]
135    pub funding_rate: NumberString,
136    /// Realized funding rate.
137    #[serde(default)]
138    pub realized_rate: NumberString,
139    /// Funding time (Unix milliseconds).
140    #[serde(default)]
141    pub funding_time: NumberString,
142    /// Funding method.
143    #[serde(default)]
144    pub method: String,
145}
146
147/// Price-limit information for an instrument.
148#[derive(Debug, Clone, Deserialize)]
149#[serde(rename_all = "camelCase")]
150#[non_exhaustive]
151pub struct PriceLimit {
152    /// Instrument ID.
153    pub inst_id: String,
154    /// Highest buy price.
155    #[serde(default)]
156    pub buy_lmt: NumberString,
157    /// Lowest sell price.
158    #[serde(default)]
159    pub sell_lmt: NumberString,
160    /// Timestamp (Unix milliseconds).
161    #[serde(default)]
162    pub ts: NumberString,
163}
164
165/// Mark-price information.
166#[derive(Debug, Clone, Deserialize)]
167#[serde(rename_all = "camelCase")]
168#[non_exhaustive]
169pub struct MarkPrice {
170    /// Instrument type.
171    pub inst_type: InstType,
172    /// Instrument ID.
173    pub inst_id: String,
174    /// Mark price.
175    #[serde(default)]
176    pub mark_px: NumberString,
177    /// Timestamp (Unix milliseconds).
178    #[serde(default)]
179    pub ts: NumberString,
180}
181
182/// Delivery/exercise history row.
183#[derive(Debug, Clone, Deserialize)]
184#[serde(rename_all = "camelCase")]
185#[non_exhaustive]
186pub struct DeliveryExercise {
187    /// Instrument type.
188    #[serde(default)]
189    pub inst_type: String,
190    /// Instrument ID.
191    #[serde(default)]
192    pub inst_id: String,
193    /// Delivery/exercise price.
194    #[serde(default)]
195    pub px: NumberString,
196    /// Delivery/exercise type.
197    #[serde(rename = "type", default)]
198    pub exercise_type: String,
199    /// Timestamp (Unix milliseconds).
200    #[serde(default)]
201    pub ts: NumberString,
202}
203
204/// Public position-tier information.
205#[derive(Debug, Clone, Deserialize)]
206#[serde(rename_all = "camelCase")]
207#[non_exhaustive]
208pub struct PositionTier {
209    /// Instrument type.
210    pub inst_type: InstType,
211    /// Trade mode.
212    #[serde(default)]
213    pub td_mode: String,
214    /// Instrument ID.
215    #[serde(default)]
216    pub inst_id: String,
217    /// Tier.
218    #[serde(default)]
219    pub tier: String,
220    /// Minimum size.
221    #[serde(default)]
222    pub min_sz: NumberString,
223    /// Maximum size.
224    #[serde(default)]
225    pub max_sz: NumberString,
226    /// Initial margin rate.
227    #[serde(default)]
228    pub imr: NumberString,
229    /// Maintenance margin rate.
230    #[serde(default)]
231    pub mmr: NumberString,
232}
233
234/// Insurance-fund snapshot.
235#[derive(Debug, Clone, Deserialize)]
236#[serde(rename_all = "camelCase")]
237#[non_exhaustive]
238pub struct InsuranceFund {
239    /// Instrument type.
240    #[serde(default)]
241    pub inst_type: String,
242    /// Fund type.
243    #[serde(rename = "type", default)]
244    pub fund_type: String,
245    /// Currency.
246    #[serde(default)]
247    pub ccy: String,
248    /// Balance amount.
249    #[serde(default)]
250    pub amt: NumberString,
251    /// Timestamp (Unix milliseconds).
252    #[serde(default)]
253    pub ts: NumberString,
254}
255
256/// Contract/coin conversion result.
257#[derive(Debug, Clone, Deserialize)]
258#[serde(rename_all = "camelCase")]
259#[non_exhaustive]
260pub struct ConvertContractCoin {
261    /// Instrument ID.
262    #[serde(default)]
263    pub inst_id: String,
264    /// Converted size.
265    #[serde(default)]
266    pub sz: NumberString,
267    /// Conversion price.
268    #[serde(default)]
269    pub px: NumberString,
270    /// Conversion unit.
271    #[serde(default)]
272    pub unit: String,
273}