ccdata_api/schemas/data_api/derivatives_indices.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 DerIndicesMarket {
9 BINANCE,
10 BIT,
11 BITGET,
12 BITMEX,
13 BTCEX,
14 BULLISH,
15 BYBIT,
16 COINBASEINTERNATIONAL,
17 CROSSTOWER,
18 CRYPTODOTCOM,
19 DERIBIT,
20 DYDXV4,
21 FTX,
22 GATEIO,
23 HUOBIPRO,
24 HYPERLIQUID,
25 #[default]
26 KRAKEN,
27 KUCOIN,
28 MOCK,
29 OKEX,
30}
31
32impl Display for DerIndicesMarket {
33 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34 match self {
35 Self::BINANCE => write!(f, "binance"),
36 Self::BIT => write!(f, "bit"),
37 Self::BITGET => write!(f, "bitget"),
38 Self::BITMEX => write!(f, "bitmex"),
39 Self::BTCEX => write!(f, "btcex"),
40 Self::BULLISH => write!(f, "bullish"),
41 Self::BYBIT => write!(f, "bybit"),
42 Self::COINBASEINTERNATIONAL => write!(f, "coinbaseinternational"),
43 Self::CROSSTOWER => write!(f, "crosstower"),
44 Self::CRYPTODOTCOM => write!(f, "cryptodotcom"),
45 Self::DERIBIT => write!(f, "deribit"),
46 Self::DYDXV4 => write!(f, "dydxv4"),
47 Self::FTX => write!(f, "ftx"),
48 Self::GATEIO => write!(f, "gateio"),
49 Self::HUOBIPRO => write!(f, "huobipro"),
50 Self::HYPERLIQUID => write!(f, "hyperliquid"),
51 Self::KRAKEN => write!(f, "kraken"),
52 Self::KUCOIN => write!(f, "kucoin"),
53 Self::MOCK => write!(f, "mock"),
54 Self::OKEX => write!(f, "okex"),
55 }
56 }
57}
58
59
60// Derivatives Indices: Historical OHLCV+
61
62
63/// Derivatives Indices: Historical OHLCV+
64#[derive(Clone, Debug, Serialize, Deserialize)]
65pub struct DerIndicesOHLCV {
66 #[serde(rename = "UNIT")]
67 /// The unit of the historical period update: MINUTE for minute, HOUR for hour and DAY for day.
68 pub unit: String,
69 #[serde(rename = "TIMESTAMP")]
70 /// The timestamp in seconds of the histo period, for minute it would be every minute at the beginning of the minute,
71 /// for hour it would be start of the hour and for daily it is 00:00 GMT/UTC.
72 pub timestamp: i64,
73 #[serde(rename = "TYPE")]
74 /// Type of the message.
75 pub type_: String,
76 #[serde(rename = "MARKET")]
77 /// The market / exchange you have requested (name of the market / exchange e.g. bitmex, deribit, ftx, etc.).
78 pub market: String,
79 #[serde(rename = "INSTRUMENT")]
80 /// The specific financial asset pair that an index is tracking in unmapped format. In most cases this is a combiation of the base and quote assets of the pair.
81 pub instrument: String,
82 #[serde(rename = "OPEN")]
83 /// The unmapped instrument ID.
84 pub open: f64,
85 #[serde(rename = "HIGH")]
86 /// The open value for the historical period, this is based on the closest index update before the period start.
87 pub high: f64,
88 #[serde(rename = "LOW")]
89 /// The max between the open and the highest index update value in this time period (same as open when there no messages in the time period).
90 pub low: f64,
91 #[serde(rename = "CLOSE")]
92 /// The min between the open and the lowest index update value in this time period (same as open when there no messages in the time period).
93 pub close: f64,
94 #[serde(rename = "FIRST_MESSAGE_TIMESTAMP")]
95 /// The timestamp in seconds of the first index update in this time period (only available when we have at least one index update in the time period).
96 pub first_message_timestamp: i64,
97 #[serde(rename = "LAST_MESSAGE_TIMESTAMP")]
98 /// The timestamp in seconds of the last index update in this time period (only available when we have at least one index update in the time period).
99 pub last_message_timestamp: i64,
100 #[serde(rename = "FIRST_MESSAGE_VALUE")]
101 /// The open based on the first index update in the time period (only available when we have at least one index update in the time period).
102 pub first_message_value: f64,
103 #[serde(rename = "HIGH_MESSAGE_VALUE")]
104 /// The highest value of the messages in the time period (only available when we have at least one index update in the time period).
105 pub high_message_value: f64,
106 #[serde(rename = "HIGH_MESSAGE_TIMESTAMP")]
107 /// The timestamp in seconds of the highest index update in this time period (only available when we have at least one index update in the time period).
108 pub high_message_timestamp: i64,
109 #[serde(rename = "LOW_MESSAGE_VALUE")]
110 /// The lowest value of the messages in the time period (only available when we have at least one index update in the time period).
111 pub low_message_value: f64,
112 #[serde(rename = "LOW_MESSAGE_TIMESTAMP")]
113 /// The timestamp in seconds of the lowest index update in this time period (only available when we have at least one index update in the time period).
114 pub low_message_timestamp: i64,
115 #[serde(rename = "LAST_MESSAGE_VALUE")]
116 /// The last index update value in the time period (only available when we have at least one index update in the time period).
117 pub last_message_value: f64,
118 #[serde(rename = "TOTAL_INDEX_UPDATES")]
119 /// The total number of message updates seen in this time period (0 when there no messages in the time period).
120 pub total_index_updates: i32,
121 #[serde(rename = "MAPPED_INSTRUMENT")]
122 /// The instrument ID, as derived from our mapping rules. Only available on instruments that have been mapped.
123 pub mapped_instrument: Option<String>,
124 #[serde(rename = "CURRENCY")]
125 /// The mapped index currency. Only available on instruments that have mapping.
126 pub currency: Option<String>,
127 #[serde(rename = "CURRENCY_ID")]
128 /// Represents the internal CoinDesk ID for the mapped index currency, e.g. 1. This ID is unique and immutable, ensuring consistent identification.
129 // Applicable only to instruments with a mapping.
130 pub currency_id: Option<i32>,
131 #[serde(rename = "TRANSFORM_FUNCTION")]
132 /// The transform function. This is the function we apply when we do mapping to change values into easier human readable ones and to make
133 /// sure the mapped direction BASE - QUOTE is constant accross all instruments.
134 pub transform_function: Option<String>,
135}
136
137
138// Derivatives Indices: Markets
139
140
141/// Derivatives Indices: Markets
142#[derive(Clone, Debug, Serialize, Deserialize)]
143pub struct DerIndicesMarkets {
144 #[serde(rename = "TYPE")]
145 /// Type of the message.
146 pub type_: String,
147 #[serde(rename = "EXCHANGE_STATUS")]
148 /// The status of the echange. We only poll / stream / connect to the ACTIVE ones, for the RETIRED ones we no longer query for data.
149 pub exchange_status: String,
150 #[serde(rename = "MAPPED_INSTRUMENTS_TOTAL")]
151 /// The total number of instruments that have been verified by our mapping team and have been properly assigned with a base, quote,
152 /// mapping function, and other necessary fields. This is done to ensure that pairs like XXBTZUSD are accurately mapped to BTC-USD and that
153 /// the pair refers to the correct assets rather than using the same asset id to represent different assets.
154 pub mapped_instrument_total: i64,
155 #[serde(rename = "UNMAPPED_INSTRUMENTS_TOTAL")]
156 /// The number of instruments that have not yet been verified by our mapping team.
157 pub unmapped_instruments_total: i64,
158 #[serde(rename = "INSTRUMENT_STATUS")]
159 /// An object with the total number of instrument for each of the available instrument statuses.
160 pub instrument_status: InstrumentStatus,
161}