Skip to content

Commit

Permalink
Support various unusual symbol names (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
KonishchevDmitry committed Apr 8, 2022
1 parent 8b243f5 commit 2eff53e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/broker_statement/ib/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::time;
use crate::types::{Date, DateTime, Decimal};
use crate::util::{self, DecimalRestrictions};

pub const STOCK_SYMBOL_REGEX: &str = "[A-Z][A-Z0-9]*(?:[ .][A-Z]+)??";
pub const STOCK_SYMBOL_REGEX: &str = r"(?:[A-Z][A-Z0-9]*[a-z]*|\d+)(?:[ .][A-Z]+)??";
pub const OLD_SYMBOL_SUFFIX: &str = ".OLD";

// IB uses the following identifier types as security ID:
Expand Down Expand Up @@ -201,7 +201,7 @@ pub fn parse_symbol(symbol: &str) -> GenericResult<String> {
return Err!("Got a stock symbol with an unsupported format: {:?}", symbol);
}

Ok(symbol.replace(' ', "-"))
Ok(symbol.replace(' ', "-").to_uppercase())
}

fn parse_quantity(quantity: &str) -> GenericResult<Decimal> {
Expand Down Expand Up @@ -283,6 +283,8 @@ mod tests {
#[rstest(value, expected,
case("T", "T"),
case("VTI", "VTI"),
case("TKAd", "TKAD"), // https://github.com/KonishchevDmitry/investments/issues/64
case("1086", "1086"), // https://github.com/KonishchevDmitry/investments/issues/64
case("U.UN", "U.UN"), // https://github.com/KonishchevDmitry/investments/issues/62
case("RDS B", "RDS-B"), // https://github.com/KonishchevDmitry/investments/issues/28
case("CBL PRD", "CBL-PRD"), // https://github.com/KonishchevDmitry/investments/issues/42
Expand Down

0 comments on commit 2eff53e

Please sign in to comment.