ccdata_api/schemas/data_api/on_chain_dex.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 OCDEXMarket {
9 AERODROMESLIPSTREAM,
10 AERODROMEV1,
11 BALANCERV2,
12 CURVE,
13 PANCAKESWAPV2,
14 PANCAKESWAPV3,
15 RAYDIUM,
16 SUSHISWAPV2,
17 SUSHISWAPV3,
18 UNISWAPV1,
19 #[default]
20 UNISWAPV2,
21 UNISWAPV3,
22}
23
24impl Display for OCDEXMarket {
25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 match self {
27 Self::AERODROMESLIPSTREAM => write!(f, "aerodromeslipstream"),
28 Self::AERODROMEV1 => write!(f, "aerodromev1"),
29 Self::BALANCERV2 => write!(f, "balancerv2"),
30 Self::CURVE => write!(f, "curve"),
31 Self::PANCAKESWAPV2 => write!(f, "pancakeswapv2"),
32 Self::PANCAKESWAPV3 => write!(f, "pancakeswapv3"),
33 Self::RAYDIUM => write!(f, "raydium"),
34 Self::SUSHISWAPV2 => write!(f, "sushiswapv2"),
35 Self::SUSHISWAPV3 => write!(f, "sushiswapv3"),
36 Self::UNISWAPV1 => write!(f, "uniswapv1"),
37 Self::UNISWAPV2 => write!(f, "uniswapv2"),
38 Self::UNISWAPV3 => write!(f, "uniswapv3"),
39 }
40 }
41}
42
43
44// On-Cahin DEX: Historical OHLCV+
45
46
47/// On-Chain DEX: Historical OHLCV+
48#[derive(Clone, Debug, Serialize, Deserialize)]
49pub struct OCDEXOHLCV {
50 #[serde(rename = "UNIT")]
51 /// The unit of the historical period update: MINUTE for minute, HOUR for hour and DAY for day.
52 pub unit: String,
53 #[serde(rename = "TIMESTAMP")]
54 /// The timestamp in seconds of the beginning of the histo period.
55 /// For minute it would be every minute at the beginning of the minute, for hour it would be the start of the hour and for daily it is 00:00 GMT.
56 pub timestamp: i64,
57 #[serde(rename = "TYPE")]
58 /// The internal type of the message.
59 pub type_: String,
60 #[serde(rename = "MARKET")]
61 /// The market / exchange under consideration (uniswapv2, uniswapv3 etc.).
62 pub market: String,
63 #[serde(rename = "INSTRUMENT")]
64 /// The unmapped instrument address and the CHAIN_ASSET ID separated by underscore (e.g. 0xe83c76c50033a5396d21ceff9fa192e2550d10ca_2, etc.).
65 pub instrument: String,
66 #[serde(rename = "MAPPED_INSTRUMENT")]
67 /// The instrument id based on asset symbols, as derived from our mapping rules. This is the same as the INSTRUMENT and will not change.
68 pub mapped_instrument: String,
69 #[serde(rename = "BASE")]
70 /// Represents the base asset or coin symbol, commonly known as the ticker (e.g., BTC). This symbol may change in cases of asset rebranding.
71 /// Applicable only to instruments with a mapping.
72 pub base: String,
73 #[serde(rename = "QUOTE")]
74 /// Represents the quote asset or counter coin symbol, commonly known as the ticker (e.g., USD). This symbol may change in cases of asset rebranding.
75 /// Applicable only to instruments with a mapping.
76 pub quote: String,
77 #[serde(rename = "BASE_ID")]
78 /// Represents the internal CoinDesk ID for the base asset or coin (e.g., 1 for BTC). This ID is unique and immutable, ensuring consistent identification.
79 /// Applicable only to instruments with a mapping.
80 pub base_id: i32,
81 #[serde(rename = "QUOTE_ID")]
82 /// Represents the internal CoinDesk ID for the quote asset or counter coin (e.g., 5 for USD). This ID is unique and immutable, ensuring consistent identification.
83 /// Applicable only to instruments with a mapping.
84 pub quote_id: i32,
85 #[serde(rename = "TRANSFORM_FUNCTION")]
86 /// The transform function (or list of functions concatenated by _AND_). This is the function we apply when we do mapping to change values into easier human
87 /// readable ones and to make sure the mapped direction BASE - QUOTE is constant accross all chains and instruments.
88 pub transform_function: String,
89 #[serde(rename = "OPEN")]
90 /// The open price for the historical period, this is based on the closest swap before the period start.
91 pub open: f64,
92 #[serde(rename = "HIGH")]
93 /// The highest swap price in the time period. If there were no swaps in the time period, the open price will be given.
94 pub high: f64,
95 #[serde(rename = "LOW")]
96 /// The lowest swap price in the time period. If there were no swaps in the time period, the open price will be given.
97 pub low: f64,
98 #[serde(rename = "CLOSE")]
99 /// The price of the last swap in this time period. If there were no swaps in the time period, the open price will be given.
100 pub close: f64,
101 #[serde(rename = "FIRST_SWAP_TIMESTAMP")]
102 /// The timestamp, in seconds, of the first swap in this time period. This is only available when there is at least one swap in the time period.
103 pub first_swap_timestamp: i64,
104 #[serde(rename = "FIRST_SWAP_BLOCK")]
105 /// The block of the first swap in the time period. This is only available when there is at least one swap in the time period.
106 pub first_swap_block: i64,
107 #[serde(rename = "LAST_SWAP_TIMESTAMP")]
108 /// The timestamp, in seconds, of the last swap in this time period. This is only available when there is at least one swap in the time period.
109 pub last_swap_timestamp: i64,
110 #[serde(rename = "LAST_SWAP_BLOCK")]
111 /// The block of the last swap in the time period. This is only available when there is at least one swap in the time period.
112 pub last_swap_block: i64,
113 #[serde(rename = "FIRST_SWAP_PRICE")]
114 /// The price of the first swap in the time period. This is only available when there is at least one swap in the time period.
115 pub first_swap_price: f64,
116 #[serde(rename = "HIGH_SWAP_PRICE")]
117 /// The highest value of the swaps in the time period. This is only available when there is at least one swap in the time period.
118 pub high_swap_price: f64,
119 #[serde(rename = "HIGH_SWAP_TIMESTAMP")]
120 /// The timestamp, in seconds, of the highest swap in the time period. This is only available when there is at least one swap in the time period.
121 pub high_swap_timestamp: i64,
122 #[serde(rename = "HIGH_SWAP_BLOCK")]
123 /// The block of the highest swap in the time period. This is only available when there is at least one swap in the time period.
124 pub high_swap_block: i64,
125 #[serde(rename = "LOW_SWAP_PRICE")]
126 /// The lowest value of the swaps in the time period. This is only available when there is at least one swap in the time period.
127 pub low_swap_price: f64,
128 #[serde(rename = "LOW_SWAP_TIMESTAMP")]
129 /// The timestamp, in seconds, of the lowest swap in the time period. This is only available when there is at least one swap in the time period.
130 pub low_swap_timestamp: i64,
131 #[serde(rename = "LOW_SWAP_BLOCK")]
132 /// The block of the lowest swap in the time period. This is only available when there is at least one swap in the time period.
133 pub low_swap_block: i64,
134 #[serde(rename = "LAST_SWAP_PRICE")]
135 /// The last swap price in the time period. This is only available when there is at least one swap in the time period.
136 pub last_swap_price: f64,
137 #[serde(rename = "TOTAL_SWAPS")]
138 /// The total number of swaps seen in this time period. If there were no swaps in the time period, 0 will be returned.
139 pub total_swaps: i64,
140 #[serde(rename = "TOTAL_SWAPS_BUY")]
141 /// The total number of BUY swaps seen in this time period. If there were no swaps in the time period, 0 will be returned.
142 pub total_swaps_buy: i64,
143 #[serde(rename = "TOTAL_SWAPS_SELL")]
144 /// The total number of SELL swaps seen in this time period. If there were no swaps in the time period, 0 will be returned."
145 pub total_swaps_sell: i64,
146 #[serde(rename = "TOTAL_SWAPS_UNKNOWN")]
147 /// The total number of UNKNOWN swaps seen in this time period. If there were no swaps in the time period, 0 will be returned.
148 pub total_swaps_unknown: i64,
149 #[serde(rename = "VOLUME")]
150 /// The sum of all the swap volumes in the from asset (base symbol / coin) for the time period. If there were no swaps in the time period, 0 will be returned.
151 pub volume: f64,
152 #[serde(rename = "QUOTE_VOLUME")]
153 /// The sum of all the swap volumes in the To asset (quote/counter symbol/coin) for the time period. If there were no swaps in the time period,
154 /// 0 will be returned.
155 pub quote_volume: f64,
156 #[serde(rename = "VOLUME_BUY")]
157 /// The sum of all the BUY swap volumes in the from asset (base symbol / coin) for the time period.
158 pub volume_buy: f64,
159 #[serde(rename = "QUOTE_VOLUME_BUY")]
160 /// The sum of all the BUY swap volumes in the to asset (quote/counter symbol/coin) for the time period.
161 pub quote_volume_buy: f64,
162 #[serde(rename = "VOLUME_SELL")]
163 /// The sum of all the SELL swap volumes in the from asset (base symbol / coin) for the time period.
164 pub volume_sell: f64,
165 #[serde(rename = "QUOTE_VOLUME_SELL")]
166 /// The sum of all the SELL swap volumes in the To asset (quote/counter symbol/coin) for the time period.
167 pub quote_volume_sell: f64,
168 #[serde(rename = "VOLUME_UNKNOWN")]
169 /// The sum of all the UNKNOWN swap volumes in the from asset (base symbol / coin) for the time period.
170 pub volume_unknown: String,
171 #[serde(rename = "QUOTE_VOLUME_UNKNOWN")]
172 /// The sum of all the UNKNOWN swap volumes in the To asset (quote/counter symbol/coin) for the time period.
173 pub quote_volume_unknown: String,
174}
175
176
177// On-Chain DEX: Market
178
179
180/// On-Chain DEX: Market
181#[derive(Clone, Debug, Serialize, Deserialize)]
182pub struct OCDEXMarkets {
183 #[serde(rename = "TYPE")]
184 /// Type of the message.
185 pub type_: String,
186 #[serde(rename = "EXCHANGE_STATUS")]
187 /// The status of the echange. We only poll / stream / connect to the ACTIVE ones, for the RETIRED ones we no longer query for data.
188 pub exchange_status: String,
189 #[serde(rename = "MAPPED_INSTRUMENTS_TOTAL")]
190 /// The total number of instruments that have been verified by our mapping team and have been properly assigned with a base, quote, mapping function,
191 /// nd other necessary fields. This is done to ensure that pairs like XXBTZUSD are accurately mapped to BTC-USD and that the pair refers
192 /// to the correct assets rather than using the same asset id to represent different assets.
193 pub mapped_instrument_total: i64,
194 #[serde(rename = "UNMAPPED_INSTRUMENTS_TOTAL")]
195 /// The number of instruments that have not yet been verified by our mapping team.
196 pub unmapped_instruments_total: i64,
197 #[serde(rename = "INSTRUMENT_STATUS")]
198 /// An object with the total number of instrument for each of the available instrument statuses.
199 pub instrument_status: InstrumentStatus,
200 #[serde(rename = "TOTAL_AMM_SWAPS_ONCHAIN")]
201 /// The total number of defi swap trades this exchange has processed.
202 pub total_amm_swaps_onchain: i64,
203 #[serde(rename = "TOTAL_AMM_LIQUIDITY_UPDATES_ONCHAIN")]
204 /// The total number of defi liquidity updates this exchange has processed.
205 pub total_amm_liquidity_updates_onchain: i64,
206 #[serde(rename = "HAS_ORDERBOOK_L2_MINUTE_SNAPSHOTS_ENABLED")]
207 pub has_orderbook_l2_minute_snapshots_enabled: Option<bool>,
208}