Working order
This commit is contained in:
@@ -51,7 +51,7 @@ pub struct Signal {
|
||||
|
||||
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize)]
|
||||
pub struct EngineOrder {
|
||||
pub risk_equity: Decimal,
|
||||
pub risk: Decimal,
|
||||
pub size: Decimal,
|
||||
pub stop_loss: Decimal,
|
||||
|
||||
|
||||
+18
-1
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user