Working order

This commit is contained in:
2026-08-02 06:05:15 +02:00
parent c18dceb291
commit 1cba37296d
4 changed files with 36 additions and 15 deletions
+18 -1
View File
@@ -3,6 +3,8 @@ pub mod strategy;
pub mod terminal;
pub use hypersdk;
use hypersdk::Decimal;
use rust_decimal::RoundingStrategy;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use crate::{general::LogKind, strategy::StrategyEngineMessage};
@@ -10,9 +12,9 @@ use crate::{general::LogKind, strategy::StrategyEngineMessage};
pub mod prelude {
pub use crate::Strategy;
pub use crate::general::*;
pub use crate::server_path;
pub use crate::strategy::*;
pub use crate::terminal::*;
pub use crate::{round_price, server_path};
pub use hypersdk;
pub use postcard;
@@ -26,6 +28,21 @@ pub fn map_postcard_err<T>(res: postcard::Result<T>) -> tokio::io::Result<T> {
res.map_err(|e| tokio::io::Error::new(std::io::ErrorKind::Other, e))
}
pub fn round_price(price: Decimal) -> Decimal {
let digits = price.trunc().to_string().len() as u32;
let decimal_places = 5_i32 - digits as i32;
if decimal_places < 0 {
let factor = Decimal::from(10_u64.pow((-decimal_places) as u32));
(price / factor).round() * factor
} else {
price.round_dp_with_strategy(
decimal_places as u32,
RoundingStrategy::MidpointAwayFromZero,
)
}
}
pub async fn send_raw(data: &[u8]) -> tokio::io::Result<()> {
let mut stdout = tokio::io::stdout();