Skip to content

Commit 3df7693

Browse files
committed
Improve Quantity and Price string parsing
1 parent a56c912 commit 3df7693

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

nautilus_core/model/src/types/price.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ impl FromStr for Price {
117117

118118
fn from_str(input: &str) -> Result<Self, Self::Err> {
119119
let float_from_input = input
120+
.replace('_', "")
120121
.parse::<f64>()
121-
.map_err(|err| format!("Cannot parse `input` string '{input}' as f64: {err}"))?;
122+
.map_err(|err| format!("Error parsing `input` string '{input}' as f64: {err}"))?;
122123

123124
Self::new(float_from_input, precision_from_str(input))
124125
.map_err(|e: anyhow::Error| e.to_string())

nautilus_core/model/src/types/quantity.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ impl FromStr for Quantity {
110110

111111
fn from_str(input: &str) -> Result<Self, Self::Err> {
112112
let float_from_input = input
113+
.replace('_', "")
113114
.parse::<f64>()
114-
.map_err(|e| format!("Cannot parse `input` string '{input}' as f64: {e}"))?;
115+
.map_err(|e| format!("Error parsing `input` string '{input}' as f64: {e}"))?;
115116

116117
Self::new(float_from_input, precision_from_str(input))
117118
.map_err(|e: anyhow::Error| e.to_string())

0 commit comments

Comments
 (0)