ccdata_api/schemas/data_api/
on_chain_dex.rs

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