mirror of
https://github.com/exchanges-lab/tradesync.git
synced 2026-08-06 05:34:49 +08:00
chore: remove Level calculation and property from code and Notion payload
This commit is contained in:
+1
-4
@@ -75,8 +75,7 @@ async fn main() -> Result<()> {
|
|||||||
let px: f64 = event.px.parse().unwrap_or(0.0);
|
let px: f64 = event.px.parse().unwrap_or(0.0);
|
||||||
let usd_val = sz * px;
|
let usd_val = sz * px;
|
||||||
|
|
||||||
// Calculate Level and Determine Order Type using NotionRowData helpers
|
// Determine Order Type using NotionRowData helper
|
||||||
let level_str = NotionRowData::calculate_level(usd_val);
|
|
||||||
let order_type_str = NotionRowData::determine_order_type(event.crossed);
|
let order_type_str = NotionRowData::determine_order_type(event.crossed);
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
@@ -85,7 +84,6 @@ async fn main() -> Result<()> {
|
|||||||
px = %event.px,
|
px = %event.px,
|
||||||
sz = %event.sz,
|
sz = %event.sz,
|
||||||
usd_val = %format!("{:.2}", usd_val),
|
usd_val = %format!("{:.2}", usd_val),
|
||||||
level = %level_str,
|
|
||||||
order_type = %order_type_str,
|
order_type = %order_type_str,
|
||||||
oid = event.oid,
|
oid = event.oid,
|
||||||
"Captured position open event, writing to Notion..."
|
"Captured position open event, writing to Notion..."
|
||||||
@@ -102,7 +100,6 @@ async fn main() -> Result<()> {
|
|||||||
time: event.time,
|
time: event.time,
|
||||||
order_id: event.oid,
|
order_id: event.oid,
|
||||||
check: false,
|
check: false,
|
||||||
level: level_str,
|
|
||||||
order_type: order_type_str,
|
order_type: order_type_str,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-14
@@ -161,20 +161,7 @@ impl NotionWriter {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// 9. Level (Select column)
|
// 9. Order Type (Select column)
|
||||||
properties.insert(
|
|
||||||
"Level".to_string(),
|
|
||||||
PageProperty::Select {
|
|
||||||
id: None,
|
|
||||||
select: Some(SelectPropertyValue {
|
|
||||||
id: None,
|
|
||||||
name: Some(data.level),
|
|
||||||
color: None,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// 10. Order Type (Select column)
|
|
||||||
properties.insert(
|
properties.insert(
|
||||||
"Order Type".to_string(),
|
"Order Type".to_string(),
|
||||||
PageProperty::Select {
|
PageProperty::Select {
|
||||||
|
|||||||
@@ -39,24 +39,10 @@ pub struct NotionRowData {
|
|||||||
pub time: u64, // Unix timestamp in milliseconds
|
pub time: u64, // Unix timestamp in milliseconds
|
||||||
pub order_id: u64, // Hyperliquid order ID (oid)
|
pub order_id: u64, // Hyperliquid order ID (oid)
|
||||||
pub check: bool, // false
|
pub check: bool, // false
|
||||||
pub level: String, // e.g. "0", "1", "2"
|
|
||||||
pub order_type: String, // "MARKET" or "LIMIT"
|
pub order_type: String, // "MARKET" or "LIMIT"
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NotionRowData {
|
impl NotionRowData {
|
||||||
/// Calculate Level from USD value:
|
|
||||||
/// level 0 = 2.5$, level 1 = 5$, level 2 = 10$, and so on (scaling logarithmically by factor of 2)
|
|
||||||
pub fn calculate_level(usd_val: f64) -> String {
|
|
||||||
if usd_val <= 0.0 {
|
|
||||||
"0".to_string()
|
|
||||||
} else {
|
|
||||||
let ratio = usd_val / 2.5;
|
|
||||||
let lvl = ratio.log2().round() as i32;
|
|
||||||
let lvl = lvl.max(0);
|
|
||||||
lvl.to_string()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Determine Order Type from the crossed flag:
|
/// Determine Order Type from the crossed flag:
|
||||||
/// crossed == true represents MARKET (taker), crossed == false represents LIMIT (maker)
|
/// crossed == true represents MARKET (taker), crossed == false represents LIMIT (maker)
|
||||||
pub fn determine_order_type(crossed: bool) -> String {
|
pub fn determine_order_type(crossed: bool) -> String {
|
||||||
@@ -72,36 +58,6 @@ impl NotionRowData {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_calculate_level() {
|
|
||||||
// Test base cases specified by user
|
|
||||||
assert_eq!(NotionRowData::calculate_level(2.5), "0");
|
|
||||||
assert_eq!(NotionRowData::calculate_level(5.0), "1");
|
|
||||||
assert_eq!(NotionRowData::calculate_level(10.0), "2");
|
|
||||||
|
|
||||||
// Test boundary limits (midpoints between levels)
|
|
||||||
// Midpoint of 2.5 and 5.0 is geometric mean sqrt(2.5 * 5.0) = ~3.535
|
|
||||||
// log2(3.5 / 2.5) = log2(1.4) = ~0.485 (rounds to 0) -> level 0
|
|
||||||
// log2(3.6 / 2.5) = log2(1.44) = ~0.526 (rounds to 1) -> level 1
|
|
||||||
assert_eq!(NotionRowData::calculate_level(3.5), "0");
|
|
||||||
assert_eq!(NotionRowData::calculate_level(3.6), "1");
|
|
||||||
|
|
||||||
// Midpoint of 5.0 and 10.0 is geometric mean sqrt(5 * 10) = ~7.07
|
|
||||||
// log2(7.0 / 2.5) = log2(2.8) = ~1.485 (rounds to 1) -> level 1
|
|
||||||
// log2(7.1 / 2.5) = log2(2.84) = ~1.506 (rounds to 2) -> level 2
|
|
||||||
assert_eq!(NotionRowData::calculate_level(7.0), "1");
|
|
||||||
assert_eq!(NotionRowData::calculate_level(7.1), "2");
|
|
||||||
|
|
||||||
// Test edge cases
|
|
||||||
assert_eq!(NotionRowData::calculate_level(0.0), "0");
|
|
||||||
assert_eq!(NotionRowData::calculate_level(-5.5), "0");
|
|
||||||
assert_eq!(NotionRowData::calculate_level(1.0), "0");
|
|
||||||
|
|
||||||
// Test higher levels
|
|
||||||
assert_eq!(NotionRowData::calculate_level(20.0), "3");
|
|
||||||
assert_eq!(NotionRowData::calculate_level(40.0), "4");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_determine_order_type() {
|
fn test_determine_order_type() {
|
||||||
assert_eq!(NotionRowData::determine_order_type(true), "MARKET");
|
assert_eq!(NotionRowData::determine_order_type(true), "MARKET");
|
||||||
|
|||||||
Reference in New Issue
Block a user