Skip to content

Commit 5781052

Browse files
committed
bump: 💫 Bump version to 0.6.0
1 parent c8ec3b2 commit 5781052

File tree

10 files changed

+78
-12
lines changed

10 files changed

+78
-12
lines changed

‎Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pragma-common"
3-
version = "0.5.0"
3+
version = "0.6.0"
44
edition = "2021"
55
rust-version = "1.81"
66
categories = ["finance", "api-bindings"]

‎schema/entries.proto‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ message PriceEntry {
7676
bool noExpiration = 8;
7777
int64 expirationTimestamp = 9;
7878
}
79+
InstrumentType instrumentType = 10;
80+
int64 receivedTimestampMs = 11;
7981
}
8082

8183
message OrderbookEntry {
@@ -85,20 +87,25 @@ message OrderbookEntry {
8587
OrderbookUpdateType type = 4;
8688
OrderbookData data = 5;
8789
int64 timestampMs = 6;
90+
int64 receivedTimestampMs = 7;
8891
}
8992

9093
message FundingRateEntry {
9194
string source = 1;
9295
Pair pair = 2;
9396
double annualizedRate = 3;
9497
int64 timestampMs = 4;
98+
InstrumentType instrumentType = 5;
99+
int64 receivedTimestampMs = 6;
95100
}
96101

97102
message OpenInterestEntry {
98103
string source = 1;
99104
Pair pair = 2;
100105
double openInterest = 3;
101106
int64 timestampMs = 4;
107+
InstrumentType instrumentType = 5;
108+
int64 receivedTimestampMs = 6;
102109
}
103110

104111
message VolumeEntry {
@@ -107,6 +114,7 @@ message VolumeEntry {
107114
Pair pair = 3;
108115
double volumeDaily = 4;
109116
int64 timestampMs = 5;
117+
int64 receivedTimestampMs = 6;
110118
}
111119

112120
message TradeEntry {
@@ -120,4 +128,5 @@ message TradeEntry {
120128
double size = 8;
121129
double price = 9;
122130
int64 timestampMs = 10;
131+
int64 receivedTimestampMs = 11;
123132
}

‎src/entries/funding_rate.rs‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(feature = "proto")]
22
use prost::Message;
33

4-
use crate::Pair;
4+
use crate::{instrument_type::InstrumentType, Pair};
55
#[cfg(feature = "proto")]
66
use crate::{ProtoDeserialize, ProtoSerialize};
77

@@ -17,6 +17,8 @@ pub struct FundingRateEntry {
1717
pub pair: Pair,
1818
pub annualized_rate: f64,
1919
pub timestamp_ms: i64,
20+
pub instrument_type: InstrumentType,
21+
pub received_timestamp_ms: i64,
2022
}
2123

2224
#[cfg(feature = "proto")]
@@ -30,13 +32,23 @@ impl FundingRateEntry {
3032
}),
3133
annualized_rate: self.annualized_rate,
3234
timestamp_ms: self.timestamp_ms,
35+
instrument_type: match self.instrument_type {
36+
InstrumentType::Spot => crate::schema::InstrumentType::Spot as i32,
37+
InstrumentType::Perp => crate::schema::InstrumentType::Perp as i32,
38+
},
39+
received_timestamp_ms: self.received_timestamp_ms,
3340
}
3441
}
3542

3643
fn from_proto(proto: crate::schema::FundingRateEntry) -> Result<Self, prost::DecodeError> {
3744
let pair = proto
3845
.pair
3946
.ok_or_else(|| prost::DecodeError::new("Missing pair field in FundingRateEntry"))?;
47+
let instrument_type = match proto.instrument_type {
48+
x if x == crate::schema::InstrumentType::Spot as i32 => InstrumentType::Spot,
49+
x if x == crate::schema::InstrumentType::Perp as i32 => InstrumentType::Perp,
50+
_ => InstrumentType::Perp, // Default to Perp for funding rates (backwards compat)
51+
};
4052
Ok(FundingRateEntry {
4153
source: proto.source,
4254
pair: Pair {
@@ -45,6 +57,8 @@ impl FundingRateEntry {
4557
},
4658
annualized_rate: proto.annualized_rate,
4759
timestamp_ms: proto.timestamp_ms,
60+
instrument_type,
61+
received_timestamp_ms: proto.received_timestamp_ms,
4862
})
4963
}
5064
}

‎src/entries/open_interest.rs‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(feature = "proto")]
22
use prost::Message;
33

4-
use crate::Pair;
4+
use crate::{instrument_type::InstrumentType, Pair};
55
#[cfg(feature = "proto")]
66
use crate::{ProtoDeserialize, ProtoSerialize};
77

@@ -17,6 +17,8 @@ pub struct OpenInterestEntry {
1717
pub pair: Pair,
1818
pub open_interest: f64,
1919
pub timestamp_ms: i64,
20+
pub instrument_type: InstrumentType,
21+
pub received_timestamp_ms: i64,
2022
}
2123

2224
#[cfg(feature = "proto")]
@@ -30,13 +32,23 @@ impl OpenInterestEntry {
3032
}),
3133
open_interest: self.open_interest,
3234
timestamp_ms: self.timestamp_ms,
35+
instrument_type: match self.instrument_type {
36+
InstrumentType::Spot => crate::schema::InstrumentType::Spot as i32,
37+
InstrumentType::Perp => crate::schema::InstrumentType::Perp as i32,
38+
},
39+
received_timestamp_ms: self.received_timestamp_ms,
3340
}
3441
}
3542

3643
fn from_proto(proto: crate::schema::OpenInterestEntry) -> Result<Self, prost::DecodeError> {
3744
let pair = proto
3845
.pair
3946
.ok_or_else(|| prost::DecodeError::new("Missing pair field in OpenInterestEntry"))?;
47+
let instrument_type = match proto.instrument_type {
48+
x if x == crate::schema::InstrumentType::Spot as i32 => InstrumentType::Spot,
49+
x if x == crate::schema::InstrumentType::Perp as i32 => InstrumentType::Perp,
50+
_ => InstrumentType::Perp, // Default to Perp for OI (backwards compat)
51+
};
4052

4153
Ok(OpenInterestEntry {
4254
source: proto.source,
@@ -46,6 +58,8 @@ impl OpenInterestEntry {
4658
},
4759
open_interest: proto.open_interest,
4860
timestamp_ms: proto.timestamp_ms,
61+
instrument_type,
62+
received_timestamp_ms: proto.received_timestamp_ms,
4963
})
5064
}
5165
}

‎src/entries/orderbook.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub struct OrderbookEntry {
1717
pub r#type: OrderbookUpdateType,
1818
pub data: OrderbookData,
1919
pub timestamp_ms: i64,
20+
pub received_timestamp_ms: i64,
2021
}
2122

2223
#[derive(Debug, Clone, PartialEq)]
@@ -124,6 +125,7 @@ impl OrderbookEntry {
124125
.collect(),
125126
}),
126127
timestamp_ms: self.timestamp_ms,
128+
received_timestamp_ms: self.received_timestamp_ms,
127129
}
128130
}
129131

@@ -205,6 +207,7 @@ impl OrderbookEntry {
205207
r#type,
206208
data,
207209
timestamp_ms: proto.timestamp_ms,
210+
received_timestamp_ms: proto.received_timestamp_ms,
208211
})
209212
}
210213
}

‎src/entries/price.rs‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,10 @@ pub struct PriceEntry {
1818
pub price: u128,
1919
pub volume: u128,
2020
pub expiration_timestamp: Option<i64>,
21+
pub instrument_type: InstrumentType,
22+
pub received_timestamp_ms: i64,
2123
}
2224

23-
impl PriceEntry {
24-
pub fn instrument_type(&self) -> InstrumentType {
25-
match self.expiration_timestamp {
26-
None => InstrumentType::Spot,
27-
Some(_) => InstrumentType::Perp,
28-
}
29-
}
30-
}
3125

3226
#[cfg(feature = "proto")]
3327
impl PriceEntry {
@@ -72,6 +66,11 @@ impl PriceEntry {
7266
Some(ts) => crate::schema::price_entry::ExpirationOption::ExpirationTimestamp(ts),
7367
None => crate::schema::price_entry::ExpirationOption::NoExpiration(true),
7468
}),
69+
instrument_type: match self.instrument_type {
70+
InstrumentType::Spot => crate::schema::InstrumentType::Spot as i32,
71+
InstrumentType::Perp => crate::schema::InstrumentType::Perp as i32,
72+
},
73+
received_timestamp_ms: self.received_timestamp_ms,
7574
}
7675
}
7776

@@ -134,6 +133,12 @@ impl PriceEntry {
134133
}
135134
};
136135

136+
let instrument_type = match proto.instrument_type {
137+
x if x == crate::schema::InstrumentType::Spot as i32 => InstrumentType::Spot,
138+
x if x == crate::schema::InstrumentType::Perp as i32 => InstrumentType::Perp,
139+
_ => InstrumentType::Spot, // Default for backwards compatibility
140+
};
141+
137142
Ok(PriceEntry {
138143
source: proto.source,
139144
chain,
@@ -142,6 +147,8 @@ impl PriceEntry {
142147
price,
143148
volume,
144149
expiration_timestamp,
150+
instrument_type,
151+
received_timestamp_ms: proto.received_timestamp_ms,
145152
})
146153
}
147154
}

‎src/entries/trade.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub struct TradeEntry {
2323
pub size: f64,
2424
pub price: f64,
2525
pub timestamp_ms: i64,
26+
pub received_timestamp_ms: i64,
2627
}
2728

2829
#[derive(Debug, Clone, PartialEq)]
@@ -69,6 +70,7 @@ impl TradeEntry {
6970
size: self.size,
7071
price: self.price,
7172
timestamp_ms: self.timestamp_ms,
73+
received_timestamp_ms: self.received_timestamp_ms,
7274
}
7375
}
7476

@@ -113,6 +115,7 @@ impl TradeEntry {
113115
size: proto.size,
114116
price: proto.price,
115117
timestamp_ms: proto.timestamp_ms,
118+
received_timestamp_ms: proto.received_timestamp_ms,
116119
})
117120
}
118121
}

‎src/entries/volume.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub struct VolumeEntry {
1818
pub pair: Pair,
1919
pub volume_daily: f64,
2020
pub timestamp_ms: i64,
21+
pub received_timestamp_ms: i64,
2122
}
2223

2324
#[cfg(feature = "proto")]
@@ -35,6 +36,7 @@ impl VolumeEntry {
3536
}),
3637
volume_daily: self.volume_daily,
3738
timestamp_ms: self.timestamp_ms,
39+
received_timestamp_ms: self.received_timestamp_ms,
3840
}
3941
}
4042

@@ -63,6 +65,7 @@ impl VolumeEntry {
6365
},
6466
volume_daily: proto.volume_daily,
6567
timestamp_ms: proto.timestamp_ms,
68+
received_timestamp_ms: proto.received_timestamp_ms,
6669
})
6770
}
6871
}

‎src/pair/mod.rs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::str::FromStr;
22

3+
use crate::instrument_type::InstrumentType;
4+
35
const STABLE_SUFFIXES: [&str; 4] = ["USDT", "USDC", "USD", "DAI"];
46

57
pub type AssetSymbol = String;
@@ -72,6 +74,17 @@ impl Pair {
7274
pub fn to_pair_id(&self) -> String {
7375
self.format_with_separator("/")
7476
}
77+
78+
/// Get the market ID in unified format: BASE:QUOTE:TYPE
79+
/// Used for ClickHouse joins across different data sources
80+
/// instrument_type is formatted in UPPERCASE (SPOT, PERP)
81+
pub fn to_market_id(&self, instrument_type: InstrumentType) -> String {
82+
let type_str = match instrument_type {
83+
InstrumentType::Spot => "SPOT",
84+
InstrumentType::Perp => "PERP",
85+
};
86+
format!("{}:{}:{}", self.base, self.quote, type_str)
87+
}
7588
}
7689

7790
impl std::fmt::Display for Pair {

0 commit comments

Comments
 (0)