Giter Club home page Giter Club logo

mt940-rs's Introduction

mt940-rs

GitHub Actions Workflow Docs Status codecov Crates.io license

A strict MT940 bank statement parser in Rust.

Features

  • Parse MT940 bank statements.
  • Strict and well-researched.
  • Super simple API and nice Rusty structs.
  • Small commandline utility that allows for quick and easy conversion of MT940 statements to JSON.
  • Well tested with many automated tests to find weird corner cases.
  • Pretty fast.

Planned features

  • MT941 support
  • MT942 support

Library usage example

use mt940::parse_mt940;

fn main() {
    let input = "\
        :20:3996-11-11111111\r\n\
        :25:DABADKKK/111111-11111111\r\n\
        :28C:00001/001\r\n\
        :60F:C090924EUR54484,04\r\n\
        :61:0909250925DR583,92NMSC1110030403010139//1234\r\n\
        :86:11100304030101391234\r\n\
        Beneficiary name\r\n\
        Something else\r\n\
        :61:0910010930DR62,60NCHGcustomer id//bank id\r\n\
        :86:Fees according to advice\r\n\
        :62F:C090930EUR53126,94\r\n\
        :64:C090930EUR53189,31\r\n\
        \r\n";

    let input_parsed = parse_mt940(input).unwrap();
    assert_eq!(input_parsed[0].transaction_ref_no, "3996-11-11111111");
}

CLI usage example

cargo run --bin sta2json tests/data/mt940/full/danskebank/MT940_DK_Example.sta

Documentation

Documentation is here.

Performance

Time to parse the provided MT940_FI_Example.sta:

mt940-rs (this crate) mt940-js (NodeJS) mt-940 (Python)
Time for file 0.054ms 0.08ms 1.15ms
Performance 600000 lines per sec 400000 lines per sec 28000 lines per sec

Strictness

Some banks bank use weird derivates of MT940 that do not strictly follow the specification. In that case you should try to do some pre-processing either by yourself or using one of the provided sanitizers.

Resources and acknowledgements

Referencing proper docs is important because because banks seem to be somewhat lenient about their strictness in implementing MT940. Below I assembled a list of resources that I reference.

Other projects

iotafinance.com

Amazing interactive docs.

DanskeBank

They provide tons of good docs.

Bank Austria

Deutsche Bank

ABN AMRO

Westpac Banking

Societe Generale Srbija

Bank Millennium

DZ Bank

Handelsbanken

ING Bank

Kontopruef

Rabo Bank

SEPA for Corporates

mt940-rs's People

Contributors

andreaskundig avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar markus-k avatar prior99 avatar svenstaro avatar twistedfall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mt940-rs's Issues

Needs at least serde version 1.0.119

When trying to compile mt940 with serde <= 1.0.118, I get a lot of error messages like this:

    Checking mt940 v1.0.1
error[E0433]: failed to resolve: could not find `__private` in `_serde`
 --> /home/jan/.cargo/registry/src/github.com-1ecc6299db9ec823/mt940-1.0.1/src/transaction_types.rs:9:39
  |
9 | #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, EnumString, EnumIter)]
  |                                       ^^^^^^^^^ could not find `__private` in `_serde`
  |
  = note: this error originates in the derive macro `Serialize` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: could not find `__private` in `_serde`
 --> /home/jan/.cargo/registry/src/github.com-1ecc6299db9ec823/mt940-1.0.1/src/transaction_types.rs:9:50
  |
9 | #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, EnumString, EnumIter)]
  |                                                  ^^^^^^^^^^^ could not find `__private` in `_serde`
  |
  = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)

Of course, serde 1.0.118 is rather old, so I only noticed it when adding mt940 to an older project with an existing Cargo.lock.

I think it's not worth the effort to find out what's going wrong. But mt940-rs should specify that it needs at least 1.0.119 in it's Cargo.toml.

Parse `86` tag (information_to_account_owner) as a struct

Thanks for this great library.

I'm struggling to understand the meaning of these character encodings for the information_to_account_owner field, like they can be seen here: https://github.com/svenstaro/mt940-rs/blob/master/tests/data/mt940/full/betterplace/with_binary_character.json#L26

They don't seem to be modified by the parsing code and I wonder, where the decoding logic for that should be located. Is that some part of the MT940 standard that's not implemented yet? Or is the user expected to decode this? And if yes, does any resource come to your mind explaining the encoding?

Because I suppose the two digit codes ?20 represent ASCII characters, but I can't make any sense of strings like the 051?00 in the beginning.

Edit: I now got some idea of the ? encoding. It doesn't encode special characters but separates fields identified by the two digits after the ?. What I don't get yet is what the three digits at the beginning and end mean.

UnknownTagError when tag 86 details contains colon

First of all: I'm not an expert at all on MT940, so this may be a problem with an invalid MT940 statement, but I'm not sure.

Parsing an MT940 statement fails, when the details following tag 86 contain a colon (e.g. from a time). For example this modified statement from the tests, containing a time:

:20:STARTUMSE
:25:20752041/0291593375
:28C:00000/001
:60F:C181126EUR13564,13
:61:1811271127DR119,35NDDTNONREF
:86:basically some information here
lots of information
then some
:61:1811271127DR16,69NDDTNONREF
:86:Lorem ipsum dolor sit amet, consetetur sadipscing elitr, seda
diam nonumy eirmod tempor invidunt ut labore et dolore magna alda
quyam erat, sed diam voluptua. At vero eos et accusam et justo da
uo dolores et ea rebum. 20:44:45 clita kasd gubergren, no sea tak
a sanctus est Lorem ipsum dolor sit amet.
:61:1811271127DR5,00N033NONREF
:86:a lot of information again
very important indeed
but totally conformant
however, some ümläuté and öther stüff för some rëäsön
which the bank didn't escape
:62F:C181127EUR13523,09

Parsing this statement fails with:

UnknownTagError("44")

Code used to parse it:

let input = to_swift_charset(&input);
let input = strip_stuff_between_messages(&input);

let parsed = parse_mt940(&input).unwrap();

Thank you for any input on this!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.