{"id":32187858,"url":"https://github.com/randomseed-io/bankster","last_synced_at":"2026-02-07T03:02:31.272Z","repository":{"id":62433072,"uuid":"339372404","full_name":"randomseed-io/bankster","owner":"randomseed-io","description":"Money as data, done right.","archived":false,"fork":false,"pushed_at":"2026-02-03T23:44:08.000Z","size":1764,"stargazers_count":38,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-02-04T02:47:12.652Z","etag":null,"topics":["banking","bigdecimal","bitcoin","btc","clojure","cryptocurrency","currency","eth","ethereum","finance","financial","fintech","funds","java","ledger","library","monetary","monetaryunit","money","money-processing"],"latest_commit_sha":null,"homepage":"https://randomseed.io/software/bankster/","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/randomseed-io.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-02-16T11:11:55.000Z","updated_at":"2026-02-03T23:44:12.000Z","dependencies_parsed_at":"2023-01-22T05:37:29.872Z","dependency_job_id":null,"html_url":"https://github.com/randomseed-io/bankster","commit_stats":null,"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"purl":"pkg:github/randomseed-io/bankster","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/randomseed-io%2Fbankster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/randomseed-io%2Fbankster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/randomseed-io%2Fbankster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/randomseed-io%2Fbankster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/randomseed-io","download_url":"https://codeload.github.com/randomseed-io/bankster/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/randomseed-io%2Fbankster/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29185113,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T00:44:15.062Z","status":"online","status_checked_at":"2026-02-07T02:00:07.217Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["banking","bigdecimal","bitcoin","btc","clojure","cryptocurrency","currency","eth","ethereum","finance","financial","fintech","funds","java","ledger","library","monetary","monetaryunit","money","money-processing"],"created_at":"2025-10-22T00:34:48.785Z","updated_at":"2026-02-07T03:02:31.255Z","avatar_url":"https://github.com/randomseed-io.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bankster /ˈbæŋkstə/\n\n**Money as data, done right.**\n\n*A pragmatic, EDN-friendly money \u0026 currency toolkit for Clojure: ISO 4217 / crypto /\ncustom currencies, with precision-first arithmetic and an expressive DSL layer.*\n\n[![Bankster on Clojars](https://img.shields.io/clojars/v/io.randomseed/bankster.svg)](https://clojars.org/io.randomseed/bankster)\n[![Bankster on cljdoc](https://cljdoc.org/badge/io.randomseed/bankster)](https://cljdoc.org/d/io.randomseed/bankster/CURRENT)\n[![CircleCI](https://circleci.com/gh/randomseed-io/bankster.svg?style=svg)](https://circleci.com/gh/randomseed-io/bankster)\n\nThis is a Clojure library for operating on monetary units with cryptocurrency and\ncustom currency support.\n\n## Who is this for?\n\nBankster shines when you need *money as data* — predictable, comparable, composable —\nwithout sacrificing ergonomics.\n\nTypical users and use-cases:\n\n- **Fintech / payments / wallets / exchanges**: model fiat + crypto under one coherent API (including non-standard codes).\n- **Accounting-ish domains**: operate on amounts with fixed, explicit scale and controlled rounding.\n- **Data pipelines \u0026 ETL**: parse/emit EDN safely (tagged literals, data readers) and keep currency semantics attached to numbers.\n- **Systems integrating many “currency worlds”**: keep separate registries per source/environment (dynamic/global/local registries).\n- **Apps that want a small “money DSL”**: concise literals/macros for currencies and amounts.\n\nIf your primary need is exchange-rate discovery, market data, or full-blown\naccounting/ledger rules — Bankster is intentionally smaller and focuses on\nrepresenting currency + amount and doing safe operations around that.\n\n## Why Bankster (in one breath)\n\n- **Precision-first arithmetic**: `BigDecimal` everywhere, currency scale-aware operations, and tooling for non-terminating expansions.\n- **Allocation and distribution**: built-in functions for allocating and distributing monetary amounts.\n- **One model for ISO + crypto + custom**: namespaced identifiers like `crypto/ETH`, plus conflict-safe code resolution via weights.\n- **EDN-native ergonomics**: tagged literals (`#money`, `#currency`), readers, macros, and parsing that make data pipelines pleasant.\n- **Registry concept**: treat currencies as a database you can extend, swap, or scope per computation.\n- **Polymorphism**: protocols (`Scalable`, `Monetary`, `Accountable`) keep it extensible and composition-friendly.\n\n## Features\n\n* Pure Clojure implementation based on Java's **BigDecimal**.\n* Uses **records** to organize data: `Registry`, `Currency`, `Money`.\n* Built-in standard **currencies database**, extendable with EDN file.\n* Ability to create *ad hoc* currencies (with optional registering).\n* Different sources of **currency registries** (dynamic, global or local).\n* Registry **hierarchies** for classification (`:domain`, `:kind`, custom)  \n  and optional per-currency **traits**.\n* **Polymorphic** interfaces (`Scalable`, `Monetary`, `Accountable` protocols).\n* Ability to **cast** and **convert** monetary amounts.\n* Useful **macros** to express currencies and monetary amounts with various forms.\n* **Namespaced identifiers** for non-ISO currencies (e.g. `crypto/ETH`).\n* Common **math operators**.\n* **Auto-rescaling** in math operations to handle non-terminating decimal expansion.\n* Variants of **variadic math functions** with rescaling after each consecutive operation.\n* Optional **rescaling** of monetary amounts with keeping track of nominal scales.\n* Functions for **rounding** to a scale or to the given **interval**.\n* Functions for **allocating** and **distributing** of monetary amounts.\n* **Tagged literals** for currencies and monetary amounts.\n* **Data readers** for currencies and monetary amounts expressed with EDN.\n* Customizable currency and money **formatting** with **locale support**.\n* **JSON and EDN serialization** with per-format protocols, minimal/full representations, and Cheshire integration.\n\n## Contracts\n\nSee [Bankster Contracts](CONTRACTS.md) for practical contracts (what is guaranteed,\nwhat is \"soft\" vs \"strict\", how the default registry is chosen, when exceptions are\nthrown, how the protocols behave) for Bankster's core axis: `Currency`, `Money`,\n`Registry` records and the `Monetary`, `Scalable` and `Accountable` protocols.\n\n## Front API\n\nBankster provides a curated front API under `io.randomseed.bankster.api.*`\n(recommended for application code). See [API](API.md) for an overview.\n\nFor major-version stability there is a frozen API namespace:\n`io.randomseed.bankster.api.v2` and its sub-namespaces. It mirrors\n`io.randomseed.bankster.api` for the Bankster 2.x line. When Bankster 3 appears,\nthe v2 API will remain available for compatibility. In the current release,\n`io.randomseed.bankster.api.v2.*` is equivalent to `io.randomseed.bankster.api.*`.\n\n## Installation\n\nTo use Bankster in your project, add the following to dependencies section of\n`project.clj` or `build.boot`:\n\n```clojure\n[io.randomseed/bankster \"2.2.0\"]\n```\n\nFor `deps.edn` add the following as an element of a map under `:deps` or\n`:extra-deps` key:\n\n```clojure\nio.randomseed/bankster {:mvn/version \"2.2.0\"}\n```\n\nYou can also download JAR from [Clojars](https://clojars.org/io.randomseed/bankster).\n\n## Design\n\nThe core design principle: **money is a value with a currency attached**, and\ncurrencies live in a **registry** that can be global, dynamic, or explicitly passed\naround. This keeps both *precision* and *context* explicit.\n\n### Registry of currencies\n\nThere is a global, shared **registry** (`Registry`) of currencies, which is\nthread-safe and encapsulated in an Atom. It consists of databases (maps) for quickly\naccessing important currency properties. Most of the functions will use this global\nregistry, unless a registry is explicitly passed as an argument or set as a dynamic\nvariable.\n\nRegistry is implemented as a record of maps keeping the following associations:\n\n* currency ID to currency object;\n* currency ID to a set of country IDs;\n* currency numeric ID to currency object;\n* country ID to currency object;\n* currency ID to localized properties map;\n* currency ID to traits set (advisory tags/features);\n* currency ID to weight (an integer used for conflict resolution);\n* currency code to a sorted set of currency objects (weighted);\n* currency numeric ID to a sorted set of currency objects (weighted);\n* currency domain to a sorted set of currency objects (weighted).\n\nRegistry also carries:\n\n* `:hierarchies` – classification hierarchies (e.g. `:domain`, `:kind`, `:traits`, and any custom axes);\n* `:ext` – a free-form extension map for registry-level metadata.\n\nIn most cases you won't have to worry about the internals of a registry. However,\nwhen working with multiple data sources or data processing engines (like currency\nexchange platforms), you may find it useful to have **different registries** (with\nthe same currencies but of different scales). Most of the functions operating on\nmonetary units and currencies will accept a registry object as their additional\nargument. The exceptions are math operations (especially variadic) for which the only\nway to use different registry is to set a dynamic variable\n`io.randomseed.bankster.registry/*default*` (which can be done using the macro\n`io.randomseed.bankster.currency/with-registry`).\n\n`registry/new-registry` expects *base maps* (e.g. `:cur-id-\u003ecur`, `:ctr-id-\u003ecur`,\n`:cur-id-\u003elocalized`, `:cur-id-\u003etraits`, `:cur-id-\u003eweight`) and builds all derived\nindex maps during initialization (`:cur-code-\u003ecurs`, `:cur-nr-\u003ecur`, `:cur-nr-\u003ecurs`,\n`:cur-dom-\u003ecurs`, `:cur-id-\u003ectr-ids`). Even the arity that accepts a Registry\nmap/record ignores any derived index fields (they are recomputed during\ninitialization).\n\nWhen the library loads, its predefined configuration is read from a default EDN file\nand its contents populate the default, global registry. This registry can be\nmodified too.\n\n#### Custom registry initialization (disable auto-init)\n\n```clojure\n;; Disable Bankster's default registry auto-initialization (config.edn)\n;; at namespace load time. You typically want this when you plan\n;; to fully control which registry is used.\n\n(binding [io.randomseed.bankster/*initialize-registry* false]\n  (require '[io.randomseed.bankster.currency :as currency]\n           '[io.randomseed.bankster.registry :as registry]))\n\n;; Load your registry from a classpath resource\n;; (e.g. resources/my/app/currencies.edn).\n\n(def my-registry\n  (currency/config-\u003eregistry \"my/app/currencies.edn\" (registry/new-registry)))\n\n;; Option A: pass the registry explicitly.\n\n(currency/unit :EUR my-registry)\n(currency/unit-try :EUR my-registry)  ; nil when missing\n\n;; Option B: install it as the global registry.\n\n(registry/set! my-registry)\n```\n\n#### Registry loader helpers (`io.randomseed.bankster.init`)\n\nIf you want to load a registry in a single call (optionally overlaying Bankster's\ndistribution config), use `io.randomseed.bankster.init`:\n\n```clojure\n(require '[io.randomseed.bankster.init :as init])\n\n;; Load ONLY the provided config (no dist overlay).\n\n(def r1 (init/load-registry \"my/app/currencies.edn\"))\n\n;; Load dist config first, then overlay user config\n;; using importer/merge-registry.\n\n(def r2 (init/load-registry \"my/app/currencies.edn\"\n                            {:keep-dist? true\n                             :merge-opts {:verbose? true\n                                          :preserve-fields [:domain :kind]\n                                          :iso-like? false}}))\n\n;; Side-effecting variant: installs the result as the global registry.\n\n(init/load-registry! \"my/app/currencies.edn\" {:keep-dist? true})\n```\n\nConfiguration (`config.edn`) is branch-oriented by default (`:currencies`, plus\ntop-level branches like `:countries`, `:localized`, `:traits`, and `:weights`).\n`:countries` is keyed by country ID (country -\u003e currency), whereas `:localized`,\n`:traits`, and `:weights` are keyed by currency ID. For convenience, each currency\nentry may also carry inline `:countries` (seq of country IDs), `:localized` and\n`:traits` which are merged into the global branches while loading (they do not\nbecome currency fields; per-currency values take precedence). Similarly, a currency\nentry may include inline `:weight` (or `:we`) which is normalized into the top-level\n`:weights` branch.\n\nIf you need selected extra keys from currency maps to be preserved on the constructed\n`Currency` objects (extension fields), use `:propagate-keys` in the config (global\nallowlist) or per-currency `:propagate-keys` (override).\n\n### Hierarchies and traits\n\nBankster can store classification hierarchies in a registry and use them for semantic\nqueries via `clojure.core/isa?`.\n\nRegistry key `:hierarchies` is a `CurrencyHierarchies` record that may contain:\n\n* `:domain` – hierarchy of domains (e.g. `:ISO-4217-LEGACY` is a kind of `:ISO-4217`);\n* `:kind` – hierarchy of currency kinds (your taxonomy, including namespaced kinds);\n* `:traits` – optional hierarchy of traits (advisory; useful for tags like token standards).\n\nHierarchy specs are expressed as a parent-map `{child parent}` and may also use a\nvector/set of parents for multiple inheritance.\n\nTraits are stored separately as a registry map `currency-id -\u003e traits` (sets/vectors\nof keywords). They are intentionally *not* part of currency identity and do not\naffect money equality or arithmetic.\n\n```clojure\n(require '[io.randomseed.bankster.registry :as registry]\n         '[io.randomseed.bankster.currency :as currency])\n\n(def r\n  (assoc (registry/new\n          {:hierarchies {:domain {:ISO-4217-LEGACY :ISO-4217\n                                  :CRYPTO          :VIRTUAL}\n                         :traits {:token/erc20 :token/fungible\n                                  :token/bep20 :token/fungible\n                                  :stable/coin [:stable :token/fungible]}}})\n         :cur-id-\u003etraits {:crypto/USDC #{:token/erc20 :stable/coin}}))\n\n;; Domains can be queried using a hierarchy-aware predicate.\n\n(currency/of-domain? :ISO-4217 (currency/new :iso-4217-legacy/ADP) r)\n;; =\u003e true\n\n;; Traits can be queried via the traits hierarchy.\n\n(currency/of-trait? :token/fungible :crypto/USDC r)\n;; =\u003e true\n```\n\nTo extend a hierarchy programmatically use `registry/hierarchy-derive` (pure) or\n`registry/hierarchy-derive!` (mutates the global registry).\n\n### Currency\n\nEach **currency** (`Currency`) is a record having the following fields, reflecting\nits properties:\n\n* `id` – a keyword **identifying** a currency unit (e.g. `:EUR` or `:crypto/ETH`);\n* `numeric` – a long value being a **numeric identifier** of ISO-standardized currencies;\n* `scale` – an integer of supported **scale** (decimal places);\n* `kind` – a keyword with currency **kind**;\n* `domain` – a keyword with currency **domain**.\n\nAdditionally, currency may carry a non-inherent attribute `:weight` (an integer),\nused only to resolve conflicts when multiple currencies share the same currency code\nor numeric ID (lower weight wins).\n\nThe source of truth for weights is the registry base map `:cur-id-\u003eweight` (exported\nto EDN under top-level `:weights`). Currency instances stored in registries carry the\nweight in metadata as an optimization (hot-path: weighted buckets), but weight does\nnot affect `=` / `hash` semantics. Use `currency/weight` to read it.\n\nTo mutate weights and traits (which are registry attributes) use:\n`currency/set-weight`/`currency/clear-weight` and\n`currency/set-traits`/`currency/add-traits`/`currency/remove-traits` (plus `!`\nvariants operating on the global registry).\n\n**Currency ID** is a unique identifier of a currency within a registry. Internally it\nis a keyword and optionally it can have a namespace. By default Bankster identifies\nstandard currencies with IDs reflecting their official currency codes and\ncryptocurrencies with identifiers having `crypto` namespace.\n\n**Currency code** is a name of currency ID without its namespace. It is potentially\nconflicting attribute, therefore the mapping of currency codes to sets of currency\nobjects exists in a registry. It allows to get currencies using their codes (and not\nadd namespace, especially when interacting with some external API) and still maintain\nuniqueness of identifiers. If custom currency is created with the same code as\nalready existing currency, it is possible to give it a **weight** (lower weight wins)\nwhich will decide whether its code will have priority during resolution (and getting\nfrom a registry).  Currency `:weight` is a registry resolution mechanism and is\ntreated as non-semantic in equality and arithmetic on monetary values.\n\n**Currency domain** is a keyword which groups currencies into separate \"worlds\". By\ndefault it is derived from the namespace of currency ID (upper-cased), e.g.\n`:crypto/ETH` implies `:domain :CRYPTO`. Namespace `ISO-4217` is treated specially:\nit is stripped (case-insensitive) and implies `:domain :ISO-4217`. Additionally,\nISO-like currencies may get `:ISO-4217` inferred from their code + numeric ID.\n\nDomains can be organized in a registry hierarchy (`registry/hierarchy :domain`) and\nqueried with `currency/of-domain?`. To list or select currencies by domain, use\n`currency/domains` and `currency/of-domain`.\n\n**Currency kind** is a case-sensitive keyword that should describe what the currency\nis. It can be set to anything, even nil. Some common values are:\n\n  - `:iso`       - ISO-4217 currencies, funds, commodities, special markers.\n  - `:virtual`   - Virtual units (stable tokens, credits, native tokens, special).\n  - `:currency`  - Meta: currency-like units; parent for `:fiduciary` money.\n  - `:asset`     - Meta: value-bearing units (`:assets`, `:claims`, `:stable`, reference-based).\n  - `:fiat`      - Meta umbrella: fiat-related tags (issuer fiats vs fiat-as-anchor).\n  - `:funds`     - Meta: funds, settlement units, units of account.\n  - `:commodity` - Meta: commodity-based units and commodity anchoring.\n  - `:special`   - Meta: special-purpose markers (`:experimental`, `:test`, `:null`).\n\nIn new code it is recommended to use namespaced kinds (for example: `:iso/fiat`,\n`:iso/funds`, `:virtual/native`, `:virtual/token`, `:virtual.stable.peg/fiat`).\n\nKinds can be organized in a registry hierarchy (`registry/hierarchy :kind`) and\nqueried with `currency/of-kind?`.\n\nCurrencies can can be tested against their ancestors in a hierarchy of kinds using\nAPI functions, so doing `(currency/of-kind :fiat :PLN)` will return `true` since this\ncurrency has its kind set to `:iso/fiat`.\n\nThe default kind taxonomy and its relationships (as shipped in the default\n`config.edn`) are documented in `doc/30_currency-kinds.md`. The default traits\ntaxonomy is documented in `doc/32_currency_traits.md`.\n\n**Currency scale** is the nominal scale of a currency. If it is not set, the\nautomatic scale will be used on monetary amounts using such a currency.\n\nRegistry-related functions are accepting currency representations based on their\n**identifiers**. Other functions and macros will usually accept **currency\ncodes**. In case of conflict the currency with lower **currency weight** will be\npicked up.\n\nCurrencies can also have **additional**, external properties, like relations to\ncountries, localized (l10n) settings etc. They are stored in registries too.\n\nTo inspect a currency including registry-associated metadata (countries, localized\nproperties, traits) use `currency/info`.\n\n### Money\n\nHaving a currency defined we can create **money** objects (`Money`) which are based\non records having 2 fields:\n\n* `currency` – a `Currency` object;\n* `amount` – a `BigDecimal` value.\n\nThe initial scale (number of decimal places) of an amount will be set to nominal\nscale of the currency. Math operations will then respect this scale during\ncalculations and preserve it. In rare cases it is possible to rescale the amount,\ncheck whether the monetary object is rescaled and scale it back to a scale of the\ncurrency.\n\n#### Rounding mode (performance note)\n\nRounding in Bankster is controlled by dynamic vars from `io.randomseed.bankster.scale`:\n`scale/*rounding-mode*` (and for some multi-arg operations also `scale/*each*`).\n\nPrefer using Bankster macros:\n\n* `money/with-rounding` (alias for `scale/with-rounding`) to set the rounding mode;\n* `money/with-rescaling` / `scale/with-rescaling` to also rescale after each step.\n\nThese macros keep semantics consistent with a plain `binding`, but they also set an\ninternal thread-local fast path for rounding-mode lookups. Direct `binding` of\n`scale/*rounding-mode*` is supported, but does not use this fast path and may be\nnoticeably slower in tight numeric loops.\n\n### Importing and merging registries\n\nNamespace `io.randomseed.bankster.util.importer` provides practical tooling for\nbuilding and merging currency registries from external sources (most notably: Joda\nMoney CSV files).\n\nHighlights:\n\n* CSV loader supports comment lines and inline `# ...` comments (preserved for\n  post-processing).\n\n* Joda currency comments are used to infer ISO legacy IDs (\"Old, now ...\") and ISO\n  funds kinds (\"FundsCode ...\").\n\n* When ISO legacy is inferred, Bankster also tags the currency with trait `:legacy`.\n\n* When merging `seed.edn` with Joda CSV imports, a practical default is to treat\n  `seed.edn` as the semantic authority (domain/kind/traits/weights/localized), while\n  refreshing `:numeric` and `:scale` from the CSV. This is expressed via\n  `importer/merge-registry` + `preserve-fields` (and optionally `::importer/countries`\n  if you want to preserve assigned countries from the seed).\n\n* `importer/merge-registry` merges registries together with `:hierarchies` and\n  `:ext`, supports preserving selected currency fields (and/or localized properties\n  and assigned countries), and can align ISO vs legacy classification in \"ISO-like\"\n  mode.\n\n* Export helpers:\n  - `importer/export` writes a branch-oriented config (as produced by `registry-\u003emap`),\n  - `importer/export-currency-oriented` writes a currency-oriented config (per-currency\n    `:countries/:localized/:traits` embedded into `:currencies`, top-level branches keep\n    only orphaned entries),\n  - `importer/map-\u003ecurrency-oriented` is the post-process transformer (map -\u003e map).\n\n```clojure\n(require '[io.randomseed.bankster.util.importer :as importer])\n\n;; Generate a Bankster EDN export from Joda Money CSV resources.\n(importer/joda-\u003ebankster-export)\n\n;; Merge two registries (verbose + preserve :domain/:kind and localized props, while\n;; letting ISO-like source align ISO vs legacy classification).\n;;\n;; In this setup `seed.edn` stays authoritative for domain/kind and localized props,\n;; while numeric/scale (and countries, unless preserved) are refreshed from CSV.\n(let [dst (importer/seed-import)\n      src (importer/joda-import)]\n  (importer/merge-registry dst src true [:domain :kind ::importer/localized] true))\n\n;; Export a registry in two equivalent shapes.\n(importer/export dst)                    ; branch-oriented\n(importer/export-currency-oriented dst)  ; currency-oriented\n```\n\n### Experimental: JSR-354 semantic bridge\n\nNamespace `io.randomseed.bankster.jsr-354` is an experimental, work-in-progress\nClojure semantic bridge inspired by JSR-354 (JavaMoney). It is not a Java\nimplementation/interface of the standard. The goal is to progressively cover more\nof JSR-354 semantics in future Bankster releases; until then, treat this namespace\nas unstable.\n\n## Sneak peeks\n\nNote on code literals (`#money`, `#currency`): tagged literals in Clojure code are\nhandled at read time via `data_readers.clj`. Clojure does not auto-`require` the\nhandler namespaces, so make sure Bankster namespaces are loaded before code\ncontaining these literals is read (otherwise you may see\n`Attempting to call unbound fn .../code-literal`). For scripts, prefer using\n`read-string` after `require` (or `clojure.edn/read-string` with `money/readers`).\n\n* It **shows information** about a currency:\n\n```clojure\n;; global registry lookup with a keyword\n(currency/of :PLN)\n#currency{:id :PLN, :domain :ISO-4217, :kind :iso/fiat, :numeric 985, :scale 2}\n\n;; global registry lookup using namespaced symbol\n(currency/of crypto/ETH)\n#currency{:id :crypto/ETH, :domain :CRYPTO, :kind :virtual/native, :scale 18, :weight 5}\n\n;; global registry lookup with a string (incl. namespace a.k.a domain)\n(currency/of \"crypto/BTC\")\n#currency{:id :crypto/BTC, :domain :CRYPTO, :kind :virtual/native, :scale 8, :weight 5}\n\n;; global registry lookup with a currency code\n;; (weight solves potential conflicts when two currencies have the same currency code)\n(currency/of ETH)\n#currency{:id :crypto/ETH, :domain :CRYPTO, :kind :virtual/native, :scale 18, :weight 5}\n\n;; global registry lookup using ISO currency number\n(currency/of 840)\n#currency{:id :USD, :domain :ISO-4217, :kind :iso/fiat, :numeric 840, :scale 2}\n\n;; global registry lookup using tagged literal with a currency code\n#currency XLM\n#currency{:id :crypto/XLM, :domain :CRYPTO, :kind :virtual/native, :scale 8}\n\n;; tagged literal accepts single-element vector (unwrapped)\n#currency [EUR]\n#currency{:id :EUR, :domain :ISO-4217, :kind :iso/fiat, :numeric 978, :scale 2}\n\n;; global registry lookup using tagged literal with a namespaced identifier\n#currency crypto/XLM\n#currency{:id :crypto/XLM, :domain :CRYPTO, :kind :virtual/native, :scale 8}\n\n;; global registry lookup using tagged literal with an ISO currency number\n#currency 978\n#currency{:id :EUR, :domain :ISO-4217, :kind :iso/fiat, :numeric 978, :scale 2}\n\n;; Full currency information (including registry metadata).\n(currency/info :PLN)\n{:id :PLN,\n :numeric 985,\n :scale 2,\n :domain :ISO-4217,\n :kind :iso/fiat,\n :weight 0,\n :countries #{:PL},\n :localized {:pl {:name \"złoty polski\", :symbol \"zł\"}}}\n\n(currency/info :crypto/USDC)\n{:id :crypto/USDC,\n :numeric -1,\n :scale 8,\n :domain :CRYPTO,\n :kind :virtual.stable.peg/fiat,\n :weight 4,\n :localized {:* {:name \"USD Coin\", :symbol \"USDC\"}},\n :traits #{:peg/fiat :stable/coin :token/erc20}}\n```\n\n* It allows to **create a currency** and **register it**:\n\n```clojure\n;; ad hoc currency creation using constructor function\n(currency/new :petro/USD 999 2 :COMBANK)\n#currency{:id :petro/USD, :domain :PETRO, :kind :COMBANK, :numeric 999, :scale 2}\n\n;; ad-hoc currency creation using tagged literal\n#currency{:id :crypto/ETH :scale 18}\n#currency{:id :crypto/ETH, :domain :CRYPTO, :scale 18}\n\n;; putting new currency into a global, shared registry\n(currency/register! (currency/new :petro/USD 9999 2 :COMBANK) :USA)\n#Registry[{:currencies 221, :countries 250, :version \"2021022121170359\"} 0x11efe93f]\n\n;; getting currency from a global registry\n(currency/of :petro/USD)\n#currency{:id :petro/USD, :domain :PETRO, :kind :COMBANK, :numeric 9999, :scale 2}\n\n;; registering new currency expressed as a tagged literal\n(currency/register! #currency{:id :crypto/AAA :scale 8})\n#Registry[{:currencies 221, :countries 249, :version \"2021022121170359\"} 0x7eaf7a70]\n\n;; creating an ISO currency (must have: a simple 3-letter code w/o ns and a numeric ID)\n(currency/new :XOX 999 2 :COMBANK)\n#currency{:id :XOX, :domain :ISO-4217, :kind :COMBANK, :numeric 999, :scale 2}\n\n;; creating a strange ISO currency (forced by a namespace but w/o a numerical ID)\n(currency/new :ISO-4217/XOX nil 2 :COMBANK)\n#currency{:id :XOX, :domain :ISO-4217, :kind :COMBANK, :scale 2}\n```\n\n* It allows to create **monetary amounts**:\n\n```clojure\n;; using money/of macro with keyword ID and an amount\n(money/of :EUR 25)\n#money[25.00 EUR]\n\n;; using money/of macro with keyword ID and an amount as a first argument\n(money/of 25 :EUR)\n#money[25.00 EUR]\n\n;; using money/of macro with joint keyword ID and an amount as a first argument\n(money/of :25_EUR)\n#money[25.00 EUR]\n\n(money/of :25EUR)\n#money[25.00 EUR]\n\n;; using money/of macro with unquoted symbolic ID and an amount\n(money/of EUR 25)\n#money[25.00 EUR]\n\n;; using money/of macro with joint unquoted symbolic ID and an amount\n(money/of EUR_25)\n#money[25.00 EUR]\n\n(money/of EUR25)\n#money[25.00 EUR]\n\n;; using money/of macro with namespaced keyword ID and an amount\n(money/of crypto/BTC 10.1)\n#money/crypto[10.10000000 BTC]\n\n;; using money/of macro with currency code and an amount\n(money/of BTC 10.1)\n#money/crypto[10.10000000 BTC]\n\n;; using tagged literals\n#money EUR\n#money[0.00 EUR]\n\n#money/crypto ETH\n#money/crypto[0.000000000000000000 ETH]\n\n#money[PLN 2.50]\n#money[2.50 PLN]\n\n;; using tagged literal with a namespace\n#money/crypto[1.31337 ETH]\n#money/crypto[1.313370000000000000 ETH]\n\n;; using tagged literal with a currency code\n#money[1.31337 ETH]\n#money/crypto[1.313370000000000000 ETH]\n\n;; using tagged literal with a namespace but the amount goes first\n#money/crypto[BTC 1.31337]\n#money/crypto[1.31337000 BTC]\n\n;; using default currency in a lexical context\n(currency/with EUR (money/of 1000))\n#money[1000.00 EUR]\n\n;; using default currency in a lexical context (alias for the above)\n(money/with-currency EUR (money/of 1000))\n#money[1000.00 EUR]\n\n;; using composed amounts and currencies\n#money EUR100\n#money[100 EUR]\n\n#money :100_EUR\n#money[100 EUR]\n\n#money :100EUR\n#money[100 EUR]\n\n#money \"100 EUR\"\n#money[100 EUR]\n\n(money/of \"100EUR\")\n#money[100 EUR]\n```\n\nIt allows to perform **logical operations** on monetary amounts:\n\n``` clojure\n(money/eq? #money[5 GBP] #money[GBP 5])\ntrue\n\n(money/ne? #money[5 GBP] #money[GBP 5])\nfalse\n\n(money/eq? #money[5 GBP] #money/crypto[5 ETH])\nfalse\n\n(money/gt? #money[1 JPY] #money[0 JPY])\ntrue\n\n(money/ge? #money[1 JPY] #money[1 JPY])\ntrue\n\n(money/lt? #money[1 JPY] #money[0 JPY])\nfalse\n\n(money/le? #money[1 JPY] #money[0 JPY])\nfalse\n\n(money/zero? #money[0 USD])\ntrue\n\n(money/neg? #money[-2 XXX])\ntrue\n\n(money/pos? #money[-2 XXX])\nfalse\n```\n\nIt allows to perform **math operations** on monetary amounts:\n\n``` clojure\n;; adding money expressed with tagged literals and with a macro call\n(money/add #money[EUR 7] #money[0.54 EUR] (money/of 4.40 EUR))\n#money[11.94 EUR]\n\n;; dividing money by a number\n(money/div #money/crypto[5 USDT] 2)\n#money/crypto[2.50000000 USDT]\n\n;; dividing money by numbers that separately would require rounding\n(money/div #money[1 GBP] 8 0.5)\n#money[0.25 GBP]\n\n;; dividing money by numbers with rounding after each consecutive calculation\n(money/with-rescaling HALF_UP\n  (money/div #money[1 GBP] 8 0.5))\n#money[0.26 GBP]\n\n;; dividing money by money (of the same currency)\n(money/div #money/crypto[5 BTC] #money/crypto[2 BTC])\n2.5M\n\n;; dividing causing scale to exceed in one of the steps\n;; but no rounding is necessary due to later operation\n(money/div #money[1 PLN] 8 0.5)\n#money[0.25 PLN]\n\n;; dividing, scaled and rounded with each operation\n(scale/with-rounding HALF_UP\n  (money/div-scaled #money[1 PLN] 8 0.5))\n#money[0.26 PLN]\n\n;; same as the above but shorter\n(scale/with-rescaling HALF_UP\n  (money/div #money[1 PLN] 8 0.5))\n#money[0.26 PLN]\n\n;; handling non-terminating decimal expansion\n(scale/with-rounding HALF_UP\n  (money/div #money[1 PLN] 3))\n#money[0.33 PLN]\n\n;; rounding with unit reduction\n(scale/with-rounding HALF_UP\n  (money/div #money[1 PLN] #money[3 PLN]))\n0.33M\n\n;; rounding and unit reduction (regular numbers, dynamic scale)\n(scale/with-rounding HALF_UP\n  (money/div 1 3))\n0.33333M\n\n;; multiplying money by numbers\n(money/mul #money/crypto[5 ETH] 1 2 3 4 5)\n#money/crypto[600.000000000000000000 ETH]\n\n;; adding to major part\n(money/add-major #money[1.23 PLN] 100)\n#money[101.23 PLN]\n\n;; adding to minor part\n(money/add-minor #money[1.23 PLN] 77)\n#money[2.00 PLN]\n\n;; converting\n(money/convert #money/crypto[1.5 ETH] :crypto/USDT 1646.75)\n#money/crypto[2470.12500000 USDT]\n\n;; comparing\n(sort money/compare [(money/of 10    PLN)\n                     (money/of  0    PLN)\n                     (money/of 30    PLN)\n                     (money/of  1.23 PLN)])\n(#money[0.00 PLN]\n #money[1.23 PLN]\n #money[10.00 PLN]\n #money[30.00 PLN])\n\n;; rounding to the given interval\n\n(money/round-to #money[31.33 USD] 0.5)\n#money[31.50 USD]\n\n;; allocation\n\n(money/allocate #money[10.00 PLN] [1 1 1])\n[#money[3.34 PLN]\n #money[3.33 PLN]\n #money[3.33 PLN]]\n\n(money/allocate #money[1.00 PLN] [1 2 3])\n[#money[0.17 PLN]\n #money[0.33 PLN]\n #money[0.50 PLN]]\n\n;; distribution\n\n(money/distribute (money/of 1 PLN) 3)\n[#money[0.34 PLN]\n #money[0.33 PLN]\n #money[0.33 PLN]]\n\n(money/distribute (money/of 3 PLN) 3)\n[#money[1.00 PLN]\n #money[1.00 PLN]\n #money[1.00 PLN]]\n\n;;\n;; using inter-ops\n;;\n\n(require '[io.randomseed.bankster.money.inter-ops :refer :all])\n\n;; NOTE: inter-ops is intentionally polymorphic (Money + numeric fallbacks),\n;; so boxed-math warnings are suppressed in that namespace.\n;; NOTE: operator shadowing lives in `io.randomseed.bankster.api.ops`.\n;; Use `:refer :all` there intentionally if you want `+`, `-`, `*`, `/`, `=`, etc.\n;; to be money-aware.\n;; (require '[io.randomseed.bankster.api.ops :refer :all])\n\n(+ 1 2 3)\n6\n\n(+ #money[USD 8] #money[USD 7.12])\n#money[15.12 USD]\n\n(* 1 2 3 4 5 #money/crypto[0.7 ETH])\n#money/crypto[84.000000000000000000 ETH]\n\n;;\n;; using api (front API)\n;;\n\n(require '[io.randomseed.bankster.api          :as          api]\n         '[io.randomseed.bankster.api.money    :as    api-money]\n         '[io.randomseed.bankster.api.currency :as api-currency]\n         '[io.randomseed.bankster.api.registry :as api-registry])\n\n;; NOTE: `api/amount` is an alias for `scale/amount`.\n;; NOTE: `api/scale` returns scale (Money amount scale / Currency nominal scale).\n;; For auto-scaled currencies, Money scale reflects the current amount's scale\n;; (it adapts to the value), not a nominal currency scale.\n\n(api/with-rescaling :HALF_UP\n  (api/auto-scaled? :XAU))\n;; =\u003e true\n\n(api/amount 12.30M)\n;; =\u003e 12.30M  ; BigDecimal\n\n(api/scale #money[12.30 EUR])\n;; =\u003e 2\n\n(api/scale :XAU)\n;; =\u003e -1  ; auto-scaled currency\n\n(api-money/add #money[10 EUR] #money[5 EUR])\n;; =\u003e #money[15 EUR]\n\n(api-money/gt? #money[10 EUR] #money[5 EUR])\n;; =\u003e true\n\n(api-currency/resolve-all :EUR)\n;; =\u003e #{#currency{:id :EUR, ...}}\n\n(api-currency/id-str :crypto/eth)\n;; =\u003e \"crypto/ETH\"\n\n(api-currency/code-str :crypto/eth)\n;; =\u003e \"ETH\"\n\n(api-currency/symbol :USD :en_US)\n;; =\u003e \"$\"\n\n(api-currency/name :EUR :en_US)\n;; =\u003e \"Euro\"\n\n(api-money/of-registry (api/default-registry) #money[10 EUR])\n;; =\u003e #money[10.00 EUR]\n\n(api-money/cast #money[10 EUR] :USD :HALF_UP)\n;; =\u003e #money[... USD]\n\n(api-money/cast-try #money[10 EUR] :NOPE)\n;; =\u003e nil\n\n(api-money/format #money[1234.50 PLN] :pl_PL)\n;; =\u003e \"1 234,50 zł\"\n```\n\nIt allows to perform **generic, polymorphic operations** on monetary amounts and\ncurrencies:\n\n```clojure\n(scale/of #currency PLN)\n2\n\n(scale/of #currency crypto/ETH)\n18\n\n(scale/of 123.45)\n2\n\n(scale/of #money[100 EUR])\n2\n\n(scale/of :GBP)\n2\n\n;; scale of the currency (low-level)\n(scale/of :XXX)\n-1\n\n;; scale of the amount\n(scale/of #money[12.34567 XXX])\n5 ; current scale\n\n;; nominal scale of the currency\n(currency/scale #money[12.34567 XXX])\n-1 ; auto-scaled\n\n(currency/auto-scaled? :XXX)\ntrue\n\n(currency/auto-scaled? #money[12.34567 XXX])\ntrue\n\n(scale/auto? :XXX)\ntrue\n\n(scale/auto? #money[12.34567 XXX])\nfalse ; scale of the amount, not the currency\n\n(scale/apply #money[10 USD] 8) ;; use with caution\n#money[10.00000000 USD]\n\n(scale/apply #currency USD 8)  ;; use with caution\n#currency{:id :USD, :domain :ISO-4217, :kind :iso/fiat, :numeric 840, :scale 8}\n\n(money/rescale #money[10 USD] 8)\n#money[10.00000000 USD]\n\n;; unary variant of money/rescale\n;; rescales back to nominal scale\n(money/rescale\n (money/rescale #money[10 USD] 8))\n#money[10.00 USD]\n\n(scale/amount #money[108.11 CHF])\n108.11M\n\n(scale/integer #money[108.11 CHF])\n108M\n\n(scale/fractional #money[108.11 CHF])\n11M\n\n(currency/iso? #money[1 GBP])\ntrue\n\n(currency/code #money[1 GBP])\n\"GBP\"\n```\n\n* It allows to **serialize and deserialize** monetary amounts:\n\n```clojure\n(require '[io.randomseed.bankster.serializers.json :as sj]\n         '[io.randomseed.bankster.serializers.edn  :as se])\n\n;; JSON serialization (minimal - only currency ID and amount)\n\n(sj/money-\u003ejson-map #money[12.30 PLN])\n{:currency \"PLN\", :amount \"12.30\"}\n\n;; JSON full serialization (currency as nested map)\n\n(sj/money-\u003ejson-full-map #money[12.30 PLN])\n{:currency {:id \"PLN\", :numeric 985, :scale 2, :kind \"iso/fiat\", :domain \"ISO-4217\"},\n :amount \"12.30\"}\n\n;; JSON with :full? option\n\n(sj/to-json-map #money[12.30 PLN] {:full? true})\n{:currency {:id \"PLN\", :numeric 985, :scale 2, :kind \"iso/fiat\", :domain \"ISO-4217\"},\n :amount \"12.30\"}\n\n;; JSON with :keys filtering (nested options for currency)\n\n(sj/money-\u003ejson-full-map #money[12.30 PLN]\n                        {:keys [:amount {:currency {:keys [:id :numeric]}}]})\n{:amount \"12.30\", :currency {:id \"PLN\", :numeric 985}}\n\n;; JSON string representation\n\n(sj/money-\u003ejson-string #money[12.30 PLN])\n\"12.30 PLN\"\n\n;; EDN serialization (BigDecimals, keyword IDs)\n\n(se/money-\u003eedn-map #money[12.30 PLN])\n{:currency :PLN, :amount 12.30M}\n\n;; EDN tagged literal string\n\n(se/money-\u003eedn-string #money[12.30 PLN])\n\"#money[12.30M PLN]\"\n\n(se/money-\u003eedn-string #money/crypto[1.5 ETH])\n\n\"#money/crypto[1.500000000000000000M ETH]\"\n\n;; Deserialization\n\n(sj/json-map-\u003emoney {:currency \"PLN\" :amount \"12.30\"})\n#money[12.30 PLN]\n\n;; Note: for JSON inputs prefer string amounts (or configure your\n;; JSON parser to produce BigDecimal) to avoid double-precision loss.\n\n(sj/json-text-\u003emoney \"{\\\"currency\\\":\\\"PLN\\\",\\\"amount\\\":12.30}\")\n#money[12.30 PLN]\n\n(sj/json-string-\u003emoney \"12.30 PLN\")\n#money[12.30 PLN]\n\n(se/edn-string-\u003emoney \"#money[12.30M PLN]\")\n#money[12.30 PLN]\n\n;; With custom registry and rounding (also accepts keywords/strings)\n\n(sj/json-map-\u003emoney {:currency \"PLN\" :amount \"1.005\"}\n                    {:rounding-mode :HALF_UP})\n#money[1.01 PLN]\n\n;; Rescaling - preserve precision beyond currency's nominal scale\n\n(sj/json-map-\u003emoney {:currency \"PLN\" :amount \"12.3456\"}\n                    {:rescale 4})\n#money[12.3456 PLN]  ; Currency has scale 4, not the registry's 2\n\n;; Rescaling during serialization\n\n(sj/money-\u003ejson-map #money[12.30 PLN] {:rescale 4})\n{:currency \"PLN\", :amount \"12.3000\"}\n\n;; Currency serialization (minimal by default)\n\n(sj/currency-\u003ejson-map #currency PLN)\n{:id \"PLN\"}\n\n(sj/currency-\u003ejson-full-map #currency PLN)\n{:id \"PLN\", :numeric 985, :scale 2, :kind \"iso/fiat\", :domain \"ISO-4217\"}\n\n;; :code-only? omits namespace\n\n(sj/money-\u003ejson-map #money/crypto[1.5 ETH] {:code-only? true})\n{:currency \"ETH\", :amount \"1.500000000000000000\"}\n```\n\nAnd more…\n\nFor more complete, runnable examples see the `examples/` directory in the\n[source repository](https://github.com/randomseed-io/bankster/tree/main/examples).\n\n### Warning about literal amounts\n\nClojure changes number literals into objects of various numeric data types.\nSome of them will have fixed precision when there is a decimal separator\npresent, yet they will not be big decimals before entering monetary functions of\nBankster.\n\nPutting a decimal number having more than 16–17 digits will often result in\n**accidental approximation** and casting it to a double value. This value may\nbecome the amount of money which probably is not what you want:\n\n```clojure\n1234.5678910111213000001\n; =\u003e 1234.5678910111212\n```\n\nTo work around that you should:\n\n* Use **big decimal literals** (e.g. `(money/of XXX 1234.56789101112M)` – note the `M`).\n* Use **strings** (e.g. `(money/of \"1234.56789101112 XXX\")`).\n* Use `money/of` macro or `#money` tagged literal with amount and currency in joint\n  form (or with the above tactics applied), e.g.:\n  * `(money/of XXX123.45678)`,\n  * `#money XXX123.45678`,\n  * `#money \"XXX123.45678\"`,\n  * `#money \"123.456789101112 XXX\"`,\n  * `#money[123.45678M XXX]`.\n\nAs it may not be a problem in case of regular currencies, it may pop-up when using\nscale-wide cryptocurrencies, like Ether or Ethereum tokens, having 18 decimal places.\n\n## Documentation\n\nFull documentation is available at:\n\n* https://randomseed.io/software/bankster/\n* https://cljdoc.org/d/io.randomseed/bankster/\n\n## Why?\n\nIn one of my personal projects I needed support for both, ISO-standardized and custom\ncurrencies. My first try was Money (by Clojurewerkz), which is quite mature library\nbased on Java's Joda Money. However, I needed cryptocurrencies support, and I mean\nall of them, including those having non-standard codes (like `DASH`).\n\nFirst I tried to modify Money and work-around this limitation by imitating such\ncurrencies with an additional map translating custom codes into standardized\nones. Then I looked at Joda Money to see that the important classes are marked as\nfinal and the support for currencies is limited to the \"official\" ones.\n\n## License\n\nCopyright © 2021–2026 Paweł Wilk\n\nBankster is copyrighted software owned by Paweł Wilk (pw@gnu.org). You may\nredistribute and/or modify this software as long as you comply with the terms of\nthe [GNU Lesser General Public License][LICENSE] (version 3).\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n## Development\n\n### Building docs\n\n```bash\nmake docs\n```\n\n### Building JAR\n\n```bash\nmake jar\n```\n\n### Updating POM\n\n```bash\nmake pom\n```\n\n### Preparing for release\n\n```bash\nmake release\n```\n\n### Deploying to Clojars\n\n```bash\nmake deploy\n```\n\n### Interactive development\n\n```bash\nbin/repl\n```\n\nStarts REPL (and optionally nREPL server with port number is stored in `.nrepl-port`).\n\n[LICENSE]:    LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frandomseed-io%2Fbankster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frandomseed-io%2Fbankster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frandomseed-io%2Fbankster/lists"}