Skip to main content

ccdata_api/schemas/data_api/
options.rs

1use std::fmt::Display;
2use serde::{Serialize, Deserialize};
3use crate::schemas::data_api::InstrumentStatus;
4
5
6#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
7/// The exchange to obtain data from.
8pub enum OptionsMarket {
9    BINANCE,
10    BULLISH,
11    BYBIT,
12    #[default]
13    DERIBIT,
14    OKEX,
15}
16
17impl Display for OptionsMarket {
18    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19        match self {
20            Self::BINANCE => write!(f, "binance"),
21            Self::BULLISH => write!(f, "bullish"),
22            Self::BYBIT => write!(f, "bybit"),
23            Self::DERIBIT => write!(f, "deribit"),
24            Self::OKEX => write!(f, "okex"),
25        }        
26    }
27}
28
29
30#[derive(Clone, Debug, Serialize, Deserialize)]
31pub struct OptionsInstrumentMapping {
32    #[serde(rename = "MAPPED_INSTRUMENT")]
33    pub mapped_instrument: String,
34    #[serde(rename = "INDEX_UNDERLYING")]
35    pub index_underlying: String,
36    #[serde(rename = "INDEX_UNDERLYING_ID")]
37    pub index_underlying_id: i32,
38    #[serde(rename = "QUOTE_CURRENCY")]
39    pub quote_currency: String,
40    #[serde(rename = "QUOTE_CURRENCY_ID")]
41    pub quote_currency_id: i32,
42    #[serde(rename = "SETTLEMENT_CURRENCY")]
43    pub settlement_currency: String,
44    #[serde(rename = "SETTLEMENT_CURRENCY_ID")]
45    pub settlement_currency_id: i32,
46    #[serde(rename = "CONTRACT_CURRENCY")]
47    pub contract_currency: String,
48    #[serde(rename = "CONTRACT_CURRENCY_ID")]
49    pub contract_currency_id: i32,
50    #[serde(rename = "STRIKE_CURRENCY")]
51    pub strike_currency: String,
52    #[serde(rename = "STRIKE_CURRENCY_ID")]
53    pub strike_currency_id: i32,
54    #[serde(rename = "OPTION_STYLE")]
55    pub option_style: String,
56    #[serde(rename = "TRANSFORM_FUNCTION")]
57    pub tranform_function: String,
58    #[serde(rename = "CREATED_ON")]
59    pub created_on: i64,
60}
61
62
63// Options: Historical OHLCV+
64
65
66///Options: Historical OHLCV+
67#[derive(Clone, Debug, Serialize, Deserialize)]
68pub struct OptionsOHLCV {
69    #[serde(rename = "UNIT")]
70    /// The level of granularity (e.g. MINUTE / HOUR / DAY).
71    pub unit: String,
72    #[serde(rename = "TIMESTAMP")]
73    /// The timestamp, in seconds, of the histo period. This refers to the first timestamp of the unit under consideration,
74    /// not the last (e.g. for daily data the timestamp will refer to 00:00 GMT/UTC).
75    pub timestamp: i64,
76    #[serde(rename = "TYPE")]
77    /// Type of the message.
78    pub type_: String,
79    #[serde(rename = "MARKET")]
80    /// The market / exchange under consideration (e.g. bitmex, deribit, ftx, etc).
81    pub market: String,
82    #[serde(rename = "INSTRUMENT")]
83    /// The unmapped instrument ID.
84    pub instrument: String,
85    #[serde(rename = "MAPPED_INSTRUMENT")]
86    /// The mapped instrument ID, derived from our mapping rules.
87    pub mapped_instrument: String,
88    #[serde(rename = "INDEX_UNDERLYING")]
89    /// The mapped index underlying asset.
90    pub index_underlying: String,
91    #[serde(rename = "QUOTE_CURRENCY")]
92    /// The mapped to asset quote / counter symbol / coin (e.g. USD). Only available on instruments that have mapping.
93    pub quote_currency: String,
94    #[serde(rename = "SETTLEMENT_CURRENCY")]
95    /// The currency that the contract is settled in (e.g. USD). Only available on instruments that have mapping.
96    pub settlement_currency: String,
97    #[serde(rename = "CONTRACT_CURRENCY")]
98    /// The currency that the contract size is denominated in (e.g. USD). Only available on instruments that have mapping.
99    pub contract_currency: String,
100    #[serde(rename = "STRIKE_CURRENCY")]
101    /// The strike currency of the contract underlying index.
102    pub strike_currency: String,
103    #[serde(rename = "INDEX_UNDERLYING_ID")]
104    /// Represents the internal CoinDesk ID for the index underlying asset (e.g., 1). This ID is unique and immutable,
105    /// ensuring consistent identification. Applicable only to instruments with a mapping.
106    pub index_underlying_id: i32,
107    #[serde(rename = "QUOTE_CURRENCY_ID")]
108    /// Represents the internal CoinDesk ID for the asset quote / counter symbol / coin (e.g. 5). This ID is unique and immutable,
109    /// ensuring consistent identification. Applicable only to instruments with a mapping.
110    pub quote_currency_id: i32,
111    #[serde(rename = "SETTLEMENT_CURRENCY_ID")]
112    /// Represents the internal CoinDesk ID for the currency that the contract is settled in (e.g. 5). This ID is unique and immutable,
113    /// ensuring consistent identification. Applicable only to instruments with a mapping.
114    pub settlement_currency_id: i32,
115    #[serde(rename = "CONTRACT_CURRENCY_ID")]
116    /// Represents the internal CoinDesk ID for the currency that the contract size is denominated in (e.g. 5). This ID is unique and immutable,
117    /// ensuring consistent identification. Applicable only to instruments with a mapping.
118    pub contract_currency_id: i32,
119    #[serde(rename = "STRIKE_CURRENCY_ID")]
120    /// Represents the internal CoinDesk ID for the strike currency of the contract underlying index. This ID is unique and immutable,
121    /// ensuring consistent identification. Applicable only to instruments with a mapping.
122    pub strike_currency_id: i32,
123    #[serde(rename = "TRANSFORM_FUNCTION")]
124    /// The transform function. This is the function we apply when we do mapping to change values into easier human readable
125    /// ones and to make sure the mapped direction BASE - QUOTE is constant accross all instruments.
126    pub transform_function: String,
127    #[serde(rename = "OPEN")]
128    /// The open price for the historical period, based on the closest trade before the period start.
129    pub open: f64,
130    #[serde(rename = "HIGH")]
131    /// The highest trade price of the historical period. If there were no trades in the period, the open price will be taken as the highest.
132    pub high: f64,
133    #[serde(rename = "LOW")]
134    /// The lowest trade price of the historical period. If there were no trades in the period, the open price will be taken as the lowest.
135    pub low: f64,
136    #[serde(rename = "CLOSE")]
137    /// The price of the last trade of the historical period. If there were no trades in the period, the open price will be taken as the close.
138    pub close: f64,
139    #[serde(rename = "NUMBER_OF_CONTRACTS")]
140    /// The sum of all the trade number of contracts for the time period. If there were no trades in the time period, 0 will be given.
141    pub number_of_contracts: i64,
142    #[serde(rename = "TOTAL_TRADES")]
143    /// The total number of trades that occurred in the time period. If there were no trades in the time period, 0 will be given.
144    pub total_trades: i64,
145    #[serde(rename = "TOTAL_TRADES_BUY")]
146    /// The total number of BUY trades that occurred in the in time period.
147    pub total_trades_buy: i64,
148    #[serde(rename = "TOTAL_TRADES_SELL")]
149    /// The total number of SELL trades that occurred in the time period.
150    pub total_trades_sell: i64,
151    #[serde(rename = "TOTAL_TRADES_UNKNOWN")]
152    /// The total number of UNKNOWN trades that occurred in the time period.
153    pub total_trades_unknown: i64,
154    #[serde(rename = "VOLUME")]
155    /// The sum of all the trade volumes in the from asset (base symbol / coin) for the time period. If there were no trades in the time period, 0 will be given.
156    pub volume: f64,
157    #[serde(rename = "QUOTE_VOLUME")]
158    /// The sum of all the trade volumes in the To asset (quote/counter symbol/coin) for the time period. If there were no trades in the time period, 0 will be given.
159    pub quote_volume: f64,
160    #[serde(rename = "VOLUME_BUY")]
161    /// The sum of all the BUY trade volumes in the from asset (base symbol / coin) for the time period.
162    pub volume_buy: f64,
163    #[serde(rename = "QUOTE_VOLUME_BUY")]
164    /// The sum of all the BUY trade volumes in the To asset (quote/counter symbol/coin) for the time period.
165    pub quote_volume_buy: f64,
166    #[serde(rename = "VOLUME_SELL")]
167    /// The sum of all the SELL trade volumes in the from asset (base symbol / coin) for the time period.
168    pub volume_sell: f64,
169    #[serde(rename = "QUOTE_VOLUME_SELL")]
170    /// The sum of all the SELL trade volumes in the To asset (quote/counter symbol/coin) for the time period.
171    pub quote_volume_sell: f64,
172    #[serde(rename = "VOLUME_UNKNOWN")]
173    /// The sum of all the UNKNOWN trade volumes in the from asset (base symbol / coin) for the time period.
174    pub volume_unknown: f64,
175    #[serde(rename = "QUOTE_VOLUME_UNKNOWN")]
176    /// The sum of all the UNKNOWN trade volumes in the To asset (quote/counter symbol/coin) for the time period.
177    pub quote_volume_unknown: f64,
178    #[serde(rename = "NOTIONAL_VOLUME")]
179    /// The sum of all the notional trade volumes in the from asset (base symbol / coin) for the time period.
180    /// If there were no trades in the time period, 0 will be given.
181    pub notional_volume: f64,
182    #[serde(rename = "NOTIONAL_QUOTE_VOLUME")]
183    /// The sum of all the notional trade volumes in the To asset (quote/counter symbol/coin) for the time period.
184    /// If there were no trades in the time period, 0 will be given.
185    pub notional_quote_volume: f64,
186    #[serde(rename = "NOTIONAL_VOLUME_BUY")]
187    /// The sum of all the BUY notional trade volumes in the from asset (base symbol / coin) for the time period.
188    pub notional_volume_buy: f64,
189    #[serde(rename = "NOTIONAL_QUOTE_VOLUME_BUY")]
190    /// The sum of all the BUY notional trade volumes in the To asset (quote/counter symbol/coin) for the time period.
191    pub notional_quote_volume_buy: f64,
192    #[serde(rename = "NOTIONAL_VOLUME_SELL")]
193    /// The sum of all the SELL notional trade volumes in the from asset (base symbol / coin) for the time period.
194    pub notional_volume_sell: f64,
195    #[serde(rename = "NOTIONAL_QUOTE_VOLUME_SELL")]
196    /// The sum of all the SELL notional trade volumes in the To asset (quote/counter symbol/coin) for the time period.
197    pub notional_quote_volume_sell: f64,
198    #[serde(rename = "NOTIONAL_VOLUME_UNKNOWN")]
199    /// The sum of all the UNKNOWN notional trade volumes in the from asset (base symbol / coin) for the time period.
200    pub notional_volume_unknown: f64,
201    #[serde(rename = "NOTIONAL_QUOTE_VOLUME_UNKNOWN")]
202    /// The sum of all the UNKNOWN notional trade volumes in the To asset (quote/counter symbol/coin) for the time period.
203    pub notional_quote_volume_unknown: f64,
204}
205
206
207// Options: Instrument Metadata
208
209
210#[derive(Clone, Debug, Serialize, Deserialize)]
211pub struct OptionsInstrumentMetadata {
212    #[serde(rename = "METADATA_VERSION")]
213    /// The version of metadata, used for version conversions/migrates.
214    pub metadata_version: i32,
215    #[serde(rename = "INSTRUMENT_STATUS")]
216    /// The status of the instrument, we only poll / stream / connect to the ACTIVE ones,
217    /// for the RETIRED / IGNORED / EXPIRED / READY_FOR_DECOMMISSIONING means we no longer query/stream data.
218    pub instrument_status: String,
219    #[serde(rename = "FIRST_SEEN_ON_POLLING_TS")]
220    /// This is the first time instrument was seen on instrumentListSourceType POLLING.
221    pub firt_seen_on_polling_ts: i64,
222    #[serde(rename = "LAST_SEEN_ON_POLLING_TS")]
223    /// This is the last time instrument was seen on instrumentListSourceType POLLING.
224    pub last_seen_on_polling_ts: i64,
225    #[serde(rename = "INSTRUMENT")]
226    /// The instrument ID as it is on the exchange with small modifications - we do not allow the following characters inside isntrument ids: ,/&?
227    pub instrument: String,
228    #[serde(rename = "INSTRUMENT_MAPPING")]
229    /// The current mapping information for this instrument
230    pub instrument_mapping: OptionsInstrumentMapping,
231    #[serde(rename = "INSTRUMENT_EXTERNAL_DATA")]
232    /// The full data we get from the polling endpoint for this specific instrument.
233    /// This is a JSON stringified object with different properties per exchange.
234    pub instrument_external_data: String,
235    #[serde(rename = "INSTRUMENT_AVAILABLE_ON_INSTRUMENTS_ENDPOINT")]
236    /// This flags the exchange instrument is currently available on instruments endpoint.
237    pub instrument_available_on_instruments_endpoint: bool,
238    #[serde(rename = "INDEX_ID")]
239    /// The id of the index the contract is based on.
240    pub index_id: String,
241    #[serde(rename = "INDEX_UNDERLYING")]
242    /// The underlying instrument of the index.
243    pub index_underlying: String,
244    #[serde(rename = "QUOTE_CURRENCY")]
245    /// The instrument that the contract is priced in.
246    pub quote_currency: String,
247    #[serde(rename = "SETTLEMENT_CURRENCY")]
248    /// The currency used to calculate contract PnL. The settlement currency can be different from the index underlying or quote currencies.
249    pub settlement_currency: String,
250    #[serde(rename = "CONTRACT_CURRENCY")]
251    /// The denomination of the CONTRACT_SIZE.
252    pub contract_currency: String,
253    #[serde(rename = "CONTRACT_SIZE")]
254    /// The contract size - how much of the contract currency does one contract contain.
255    pub contract_size: f64,
256    #[serde(rename = "TICK_SIZE")]
257    /// The minimum amount the price can move, denominated in QUOTE_CURRENCY.
258    pub tick_size: f64,
259    #[serde(rename = "CONTRACT_CREATION_TS")]
260    /// The contract creation timestamp we get for the specific derivative instrument.
261    pub contract_creation_ts:  i64,
262    #[serde(rename = "CONTRACT_EXPIRATION_TS")]
263    /// The contract expiration timestamp we get for the specific derivative instrument. Not needed for PERPETUAL contract types.
264    pub contract_expiration_ts: i64,
265    #[serde(rename = "CONTRACT_EXPIRATION_YEAR")]
266    /// Year in which the contract expires.
267    pub contract_expiration_year: i32,
268    #[serde(rename = "CONTRACT_EXPIRATION_MONTH_CODE")]
269    /// Month in which the contract expires.
270    pub contract_expiration_month_code: String,
271    #[serde(rename = "STRIKE_PRICE")]
272    /// The strike price.
273    pub strike_price: f64,
274    #[serde(rename = "STRIKE_CURRENCY")]
275    /// The denomination of the STRIKE_PRICE.
276    pub strike_currency: String,
277    #[serde(rename = "OPTION_TYPE")]
278    /// The type of option contract.
279    pub option_type: String,
280    #[serde(rename = "OPTION_STYLE")]
281    /// The style of option contract.
282    pub option_style: String,
283    #[serde(rename = "BASE_CURRENCY")]
284    /// The base currency of the contract underlying index.
285    pub base_currency: String,
286    #[serde(rename = "MIN_TRADE_AMOUNT")]
287    /// The minimum amount of contracts you can trade.
288    pub min_trade_amount: f64,
289}
290
291
292// Options: Markets
293
294
295/// Options: Markets
296#[derive(Clone, Debug, Serialize, Deserialize)]
297pub struct OptionsMarkets {
298    #[serde(rename = "TYPE")]
299    /// Type of the message.
300    pub type_: String,
301    #[serde(rename = "EXCHANGE_STATUS")]
302    /// The status of the echange. We only poll / stream / connect to the ACTIVE ones, for the RETIRED ones we no longer query for data.
303    pub exchange_status: String,
304    #[serde(rename = "MAPPED_INSTRUMENTS_TOTAL")]
305    /// The total number of instruments that have been verified by our mapping team and have been properly assigned with a base, quote,
306    /// mapping function, and other necessary fields. This is done to ensure that pairs like XXBTZUSD are accurately mapped to BTC-USD and
307    /// that the pair refers to the correct assets rather than using the same asset id to represent different assets.
308    pub mapped_instrument_total: i64,
309    #[serde(rename = "UNMAPPED_INSTRUMENTS_TOTAL")]
310    /// The number of instruments that have not yet been verified by our mapping team.
311    pub unmapped_instruments_total: i64,
312    #[serde(rename = "INSTRUMENT_STATUS")]
313    /// An object with the total number of instrument for each of the available instrument statuses.
314    pub instrument_status: InstrumentStatus,
315    #[serde(rename = "TOTAL_TRADES_OPTIONS")]
316    /// The total number of options trades that this exchange has processed.
317    pub total_trades_options: i64,
318    #[serde(rename = "TOTAL_OPEN_INTEREST_OPTIONS_UPDATES")]
319    /// The total number of options open interest updates that this exchange has processed.
320    pub total_open_interest_updates: i64,
321    #[serde(rename = "HAS_ORDERBOOK_L2_MINUTE_SNAPSHOTS_ENABLED")]
322    pub has_orderbook_l2_minute_snapshots_enabled: Option<bool>,
323}