### Money Comparison Examples Source: https://github.com/randomseed-io/bankster/blob/main/docs/11_sneak-peeks.html Demonstrates basic comparison operations for monetary values. ```clojure (money/ge? #money[1 JPY] #money[1 JPY]) true (money/lt? #money[1 JPY] #money[0 JPY]) false (money/le? #money[1 JPY] #money[0 JPY]) false (money/zero? #money[0 USD]) true (money/neg? #money[-2 XXX]) true (money/pos? #money[-2 XXX]) false ``` -------------------------------- ### Using Bankster API Helpers Source: https://github.com/randomseed-io/bankster/blob/main/docs/11_sneak-peeks.html Examples of using the front API for monetary operations, including checking for auto-scaled currencies and getting the BigDecimal amount. Requires importing `api`, `money`, and `currency` namespaces. ```clojure (require '[io.randomseed.bankster.api :as api] '[io.randomseed.bankster.api.money :as money] '[io.randomseed.bankster.api.currency :as currency]) (api/with-rescaling :HALF_UP (api/auto-scaled? :XAU)) ;; => true (api/amount 12.30M) ;; => 12.30M ; BigDecimal ``` -------------------------------- ### load-registry! Source: https://github.com/randomseed-io/bankster/blob/main/docs/io.randomseed.bankster.init.html Loads a Bankster registry from an EDN configuration resource file and installs it as the global registry. ```APIDOC ## load-registry! ### Description Similar to `load-registry`, but this function installs the loaded registry as the global registry for subsequent operations. ### Signature `(load-registry! resource-path)` `(load-registry! resource-path opts)` ### Parameters #### Path Parameters - **resource-path** (string) - Required - The classpath path to the EDN configuration file. #### Options Map (`opts`) - **`:keep-dist?`** (boolean) - Optional - If true, loads the distribution registry first and overlays it with the user registry. Defaults to false. - **`:dist-resource-path`** (string) - Optional - The resource path for the distribution registry. Defaults to `io.randomseed.bankster.config/default-resource-path`. - **`:optional?`** (boolean) - Optional - If true, a missing `resource-path` is treated as no overlay, returning the distribution registry or an empty registry. Defaults to false. - **`:merge-opts`** (map) - Optional - A map of options for `importer/merge-registry`, including `:verbose?`, `:preserve-fields`, and `:iso-like?`. ### Returns - **Registry** - The loaded and globally installed Bankster registry. ``` -------------------------------- ### Start Interactive Development REPL Source: https://github.com/randomseed-io/bankster/blob/main/README.md Starts the Read-Eval-Print Loop (REPL) for interactive development. If an nREPL server is running, its port will be stored in the .nrepl-port file. ```bash bin/repl ``` -------------------------------- ### Using API (Front API) Source: https://github.com/randomseed-io/bankster/blob/main/doc/11_sneak-peeks.md Examples of using the front API functions for currency resolution, amount scaling, and type casting. ```APIDOC ## Front API Usage ### Description Examples of using the front API for various monetary and currency-related operations. ### Usage ```clojure ;; require namespaces (require '[io.randomseed.bankster.api :as api] '[io.randomseed.bankster.api.money :as money] '[io.randomseed.bankster.api.currency :as currency]) ;; Check if a currency is auto-scaled (api/with-rescaling :HALF_UP (api/auto-scaled? :XAU)) ;; => true ;; Get the BigDecimal amount (api/amount 12.30M) ;; => 12.30M ;; Get the scale of a Money amount (api/scale #money[12.30 EUR]) ;; => 2 ;; Get the nominal scale of an auto-scaled currency (api/scale :XAU) ;; => -1 ;; Add two Money values (money/add #money[10 EUR] #money[5 EUR]) ;; => #money[15 EUR] ;; Check if one Money value is greater than another (money/gt? #money[10 EUR] #money[5 EUR]) ;; => true ;; Resolve all currency information (currency/resolve-all :EUR) ;; => #{#currency{:id :EUR, ...}} ;; Get currency ID as string (currency/id-str :crypto/eth) ;; => "crypto/ETH" ;; Get currency code as string (currency/code-str :crypto/eth) ;; => "ETH" ;; Get currency symbol (currency/symbol :USD :en_US) ;; => "$" ;; Get currency name (currency/name :EUR :en_US) ;; => "Euro" ;; Create Money from default registry (money/of-registry (api/default-registry) #money[10 EUR]) ;; => #money[10.00 EUR] ;; Cast Money to another currency with rounding (money/cast #money[10 EUR] :USD :HALF_UP) ;; => #money[... USD] ;; Try to cast Money to an invalid currency (returns nil) (money/cast-try #money[10 EUR] :NOPE) ;; => nil ;; Format Money according to locale (money/format #money[1234.50 PLN] :pl_PL) ;; => "1 234,50 zł" ``` ``` -------------------------------- ### Monetary Conversions and Comparisons Source: https://github.com/randomseed-io/bankster/blob/main/docs/11_sneak-peeks.html Examples of converting between currencies and comparing monetary values. ```APIDOC ## Converting Money ### Description Converts a monetary amount from one currency to another using a given exchange rate. ### Code Example ```clojure (money/convert #money/crypto[1.5 ETH] :crypto/USDT 1646.75) ;; => #money/crypto[2470.12500000 USDT] ``` ## Comparing Money ### Description Compares and sorts a collection of monetary amounts. ### Code Example ```clojure (sort money/compare [(money/of 10 PLN) (money/of 0 PLN) (money/of 30 PLN) (money/of 1.23 PLN)]) ;; => (#money[0.00 PLN] ;; #money[1.23 PLN] ;; #money[10.00 PLN] ;; #money[30.00 PLN]) ``` ``` -------------------------------- ### Scale Money and Currencies Source: https://github.com/randomseed-io/bankster/blob/main/docs/11_sneak-peeks.html Demonstrates how to get the scale of currencies and monetary amounts. Use `api/scale` for general use and `currency/scale` for the nominal scale of a currency. ```clojure (api/scale #money[12.30 EUR]) 2 ``` ```clojure (api/scale :XAU) -1 ; auto-scaled currency ``` ```clojure (api/scale #currency PLN) 2 ``` ```clojure (api/scale #currency crypto/ETH) 18 ``` ```clojure (api/scale 123.45) 2 ``` ```clojure (api/scale :GBP) 2 ``` ```clojure (api/scale :XXX) -1 ; scale of the currency (low-level) ``` ```clojure (api/scale #money[12.34567 XXX]) 5 ; current scale ``` ```clojure (currency/scale #money[12.34567 XXX]) -1 ; auto-scaled ``` -------------------------------- ### Load Registry with Bankster Init Source: https://github.com/randomseed-io/bankster/blob/main/docs/10_introduction.html Use `init/load-registry` to load currency configurations. Optionally overlay Bankster's distribution config by setting `:keep-dist?` to true. The `init/load-registry!` variant installs the loaded registry globally. ```clojure (require '[io.randomseed.bankster.init :as init]) ;; Load ONLY the provided config (no dist overlay). (def r1 (init/load-registry "my/app/currencies.edn")) ;; Load dist config first, then overlay user config ;; using importer/merge-registry. (def r2 (init/load-registry "my/app/currencies.edn" {:keep-dist? true :merge-opts {:verbose? true :preserve-fields [:domain :kind] :iso-like? false}})) ;; Side-effecting variant: installs the result as the global registry. (init/load-registry! "my/app/currencies.edn" {:keep-dist? true}) ``` -------------------------------- ### Example EDN Currency and Token Configuration Source: https://github.com/randomseed-io/bankster/blob/main/doc/50_example_config.md This snippet shows a portion of an EDN configuration file defining various legacy ISO 4217 currencies and a crypto token. It includes properties like kind, numeric code, scale, weight, and specific traits for tokens. ```edn :iso-4217-legacy/PTE {:kind :iso/fiat, :numeric 620, :scale 0, :weight 10000}, :iso-4217-legacy/RUR {:kind :iso/fiat, :numeric 810, :scale 2, :weight 10000}, :iso-4217-legacy/SIT {:kind :iso/fiat, :numeric 705, :scale 2, :weight 10000}, :iso-4217-legacy/SKK {:kind :iso/fiat, :numeric 703, :scale 2, :weight 10000}, :iso-4217-legacy/SLL {:kind :iso/fiat, :numeric 694, :scale 2, :weight 10000}, :iso-4217-legacy/STD {:kind :iso/fiat, :numeric 678, :scale 2, :weight 10000}, :iso-4217-legacy/VEF {:kind :iso/fiat, :numeric 937, :scale 2, :weight 10000}, :iso-4217-legacy/XEU {:kind :iso/fiat, :numeric 954, :weight 10000}, :iso-4217-legacy/XFU {:kind :iso/fiat, :weight 10000}, :iso-4217-legacy/ZWL {:kind :iso/fiat, :numeric 932, :scale 2, :weight 10000}, "crypto/1INCH" {:kind :virtual/token, :localized {:* {:name "1inch", :symbol "1INCH"}}, :scale 18, :traits [:blockchain/ethereum :defi/governance :token/erc20], :weight 10}}} ``` -------------------------------- ### Example EDN Crypto Configurations Source: https://github.com/randomseed-io/bankster/blob/main/doc/50_example_config.md This snippet demonstrates EDN configuration for various crypto assets. It includes native tokens, staked tokens, and stablecoins, each with specific properties like localization, scale, traits, and weight. ```edn :crypto/STETH {:kind :virtual/staked, :localized {:* {:name "Lido Staked Ether", :symbol "STETH"}}, :scale 18, :traits [:blockchain/ethereum :token/erc20], :weight 10} ``` ```edn :crypto/SUI {:kind :virtual/native, :localized {:* {:name "Sui", :symbol "SUI"}}, :scale 9, :traits [:blockchain/sui :control/decentralized], :weight 10} ``` ```edn :crypto/SUSDE {:kind :virtual/staked, :localized {:* {:name "Ethena Staked USDe", :symbol "SUSDE"}}, :scale 8, :traits [:blockchain/ethereum :peg/fiat :stable/coin :token/erc20], :weight 10} ``` ```edn :crypto/SUSDS {:kind :virtual/staked, :localized {:* {:name "sUSDS", :symbol "SUSDS"}}, :scale 8, :traits [:blockchain/ethereum :peg/fiat :stable/coin :token/erc20], :weight 10} ``` ```edn :crypto/TON {:kind :virtual/native, :localized {:* {:name "Toncoin", :symbol "TON"}}, :scale 9, :traits [:blockchain/ton :control/decentralized], :weight 10} ``` ```edn :crypto/TRX {:kind :virtual/native, :localized {:* {:name "TRON", :symbol "TRX"}}, :scale 18, :traits [:blockchain/tron :control/decentralized], :weight 10} ``` ```edn :crypto/UNI {:kind :virtual/token, :scale 18, :traits [:blockchain/ethereum :defi/governance :token/erc20], :weight 10} ``` ```edn :crypto/USD1 {:kind :virtual.stable.peg/fiat, :localized {:* {:name "USD1", :symbol "USD1"}}, :scale 8, :traits [:blockchain/ethereum :peg/fiat :stable/coin :token/erc20], :weight 4} ``` ```edn :crypto/USDC {:kind :virtual.stable.peg/fiat, :localized {:* {:name "USD Coin", :symbol "USDC"}}, :scale 8, :traits [:blockchain/ethereum :peg/fiat :stable/coin :token/erc20], :weight 4} ``` ```edn :crypto/USDE {:kind :virtual.stable.peg/fiat, :localized {:* {:name "Ethena USDe", :symbol "USDE"}}, :scale 8, :traits [:blockchain/ethereum :peg/fiat :stable/coin :token/erc20], :weight 4} ``` ```edn :crypto/USDS {:kind :virtual.stable.peg/fiat, :localized {:* {:name "USDS", :symbol "USDS"}}, :scale 8, :traits [:blockchain/ethereum :peg/fiat :stable/coin :token/erc20], :weight 4} ``` ```edn :crypto/USDT {:kind :virtual.stable.peg/fiat, :localized {:* {:name "Tether", :symbol "₮"}}, :scale 8, :traits [:blockchain/ethereum :peg/fiat :stable/coin :token/erc20], :weight 4} ``` ```edn :crypto/USDT0 {:kind :virtual.stable.peg/fiat, :localized {:* {:name "USDT0", :symbol "USDT0"}}, :scale 8, :traits [:blockchain/ethereum :peg/fiat :stable/coin ``` -------------------------------- ### Converting Monetary Amounts Source: https://github.com/randomseed-io/bankster/blob/main/docs/11_sneak-peeks.html Example of converting a cryptocurrency amount to another currency (USDT) with a given exchange rate. ```clojure (money/convert #money/crypto[1.5 ETH] :crypto/USDT 1646.75) #money/crypto[2470.12500000 USDT] ``` -------------------------------- ### Currency Resolution and Identification Source: https://github.com/randomseed-io/bankster/blob/main/doc/11_sneak-peeks.md Shows how to resolve all currency definitions for a given currency code and how to get string representations of currency IDs and codes. ```clojure (currency/resolve-all :EUR) ;; => #{#currency{:id :EUR, ...}} (currency/id-str :crypto/eth) ;; => "crypto/ETH" (currency/code-str :crypto/eth) ;; => "ETH" ``` -------------------------------- ### Cryptocurrency EDN Configuration Examples Source: https://github.com/randomseed-io/bankster/blob/main/doc/50_example_config.md This snippet demonstrates the EDN structure for defining various cryptocurrency assets. Each entry specifies the asset's kind, localized name and symbol, decimal scale, blockchain traits, and weight. ```edn :crypto/BAT {:kind :virtual/token, :localized {:* {:name "Basic Attention Token", :symbol "▵"}}, :scale 18, :traits [:blockchain/ethereum :token/erc20], :weight 10}, :crypto/BCC {:kind :virtual/token, :localized {:* {:name "Basiscoin Cash", :symbol "⟥"}}, :scale 18, :traits [:blockchain/ethereum :token/erc20], :weight 10}, :crypto/BCH {:kind :virtual/native, :localized {:* {:name "Bitcoin Cash", :symbol "Ƀ"}}, :scale 8, :traits [:blockchain/bitcoin-cash :control/decentralized], :weight 10}, :crypto/BCP {:kind :virtual/token, :localized {:* {:name "Bitcashpay", :symbol "BCP"}}, :scale 18, :traits [:blockchain/ethereum :token/erc20], :weight 10}, :crypto/BNB {:kind :virtual/native, :localized {:* {:name "Binance Coin", :symbol "BNB"}}, :scale 8, :traits [:blockchain/bnb-chain :control/decentralized], :weight 10}, :crypto/BSC-USD {:kind :virtual.stable.peg/fiat, :localized {:* {:name "Binance Bridged USDT (BNB Smart Chain)", :symbol "BSC-USD"}}, :scale 8, :traits [:blockchain/bnb-chain :peg/fiat :stable/coin :token/bep20], :weight 4}, :crypto/BSV {:kind :virtual/native, :localized {:* {:name "Bitcoin SV", :symbol "Ɓ"}}, :scale 8, :traits [:blockchain/bitcoin-sv :control/decentralized], :weight 10}, :crypto/BTC {:kind :virtual/native, :localized {:* {:name "Bitcoin", :symbol "₿"}}, :scale 8, :traits [:blockchain/bitcoin :control/decentralized], :weight 5}, :crypto/BTG {:kind :virtual/native, :localized {:* {:name "Bitcoin Gold", :symbol "BTG"}}, :scale 8, :traits [:blockchain/bitcoin-gold :control/decentralized], :weight 10}, :crypto/CBBTC {:kind :virtual/wrapped, :localized {:* {:name "Coinbase Wrapped BTC", :symbol "CBBTC"}}, :scale 8, :traits [:blockchain/ethereum :token/erc20], :weight 10}, :crypto/CC {:kind :virtual/native, :localized {:* {:name "Canton", :symbol "CC"}}, :scale 18, :traits [:blockchain/canton :control/decentralized], :weight 10}, :crypto/CRO {:kind :virtual/native, :localized {:* {:name "Cronos", :symbol "CRO"}}, :scale 8, :traits [:blockchain/cronos :control/decentralized], :weight 10}, :crypto/DAI {:kind :virtual.stable.peg/fiat, :localized {:* {:name "Dai", :symbol "◈"}}, :scale 18, :traits [:blockchain/ethereum :collateral/crypto :peg/fiat :stable/coin :token/erc20], :weight 4}, :crypto/DASH {:kind :virtual/native, :localized {:* {:name "DASH", :symbol "DASH"}}, :scale 8, :traits [:blockchain/dash :control/decentralized], :weight 10}, :crypto/DOGE {:kind :virtual/native, :localized {:* {:name "Dogecoin", :symbol "Ð"}}, :scale 8, :traits [:blockchain/dogecoin :control/decentralized], ``` -------------------------------- ### Example EDN Currency Registry Configuration Source: https://github.com/randomseed-io/bankster/blob/main/doc/50_example_config.md This EDN configuration defines a currency registry for Bankster. It includes registry-level attributes and currency hierarchies. Use this as a base for custom currency definitions. ```clojure {:version "2026013114025983", ;; Allow-list of extra per-currency keys that may be propagated from currency maps ;; into constructed Currency objects (extension fields). Useful for importer/merge tooling. :propagate-keys [], ;; Registry-level attributes stored in top-level branches. ;; - :countries maps country-id -> currency-id. ;; - :localized, :traits, :weights map currency-id -> data. ;; These branches may be populated directly (as here) and/or via inline keys inside ;; individual currency entries under :currencies (inline values are merged; per-currency ;; values take precedence). :traits {:PLN [:testing]}, :weights {:PLN 0}, :localized {:PLN {:pl {:name "zloty"}}}, :countries {:PL :PLN}, ;; Hierarchies define parent relationships used by predicates like of-kind?/of-domain?/of-trait?. ;; Each axis is a map of `child -> parent(s)`; use a vector/set to express multiple parents. :hierarchies {:domain {:CRYPTO :VIRTUAL, :ISO-4217-LEGACY :ISO-4217}, :kind {:NULL :special, :asset :all, :claim :asset, :commodity :all, :credit :claim, :currency :all, :experimental :special, :fiat :all, :fiduciary :currency, :funds :all, :iso :all, :metal :commodity, :nil :NULL, :none :NULL, :peg :reference, :reference :asset, :special :all, :stable :asset, :staked :claim, :test :experimental, :virtual :all, :wrapped :claim, :asset/reference :reference, :asset/referenced [:asset :reference], :commodity/reference [:asset/reference :commodity], :commodity/referenced :asset/referenced, :fiat/issuer [:fiat :fiduciary], :fiat/legal-tender :fiat/issuer, :fiat/reference :fiat/anchor, :fiat/referenced [:asset/referenced :fiat/anchor], :iso/commodity [:commodity :iso], :iso/currency [:currency :iso], :iso/experimental [:experimental :iso/special], :iso/fiat [:fiat/issuer :iso/fiduciary], :iso/fiduciary [:fiduciary :iso/currency], :iso/funds [:funds :iso], :iso/metal [:iso/commodity :metal], :iso/null [:NULL :iso/special], :iso/special [:iso :special], :iso/test [:iso/experimental :test], :iso.funds/institutional :iso/funds, :iso.funds/international :iso/funds, :iso.funds/market :iso/funds, :iso.funds/settlement :iso/funds, :iso.funds.settlement/combanks :iso.funds/settlement, :metal/reference [:commodity/reference :metal], :metal/referenced :commodity/referenced, :virtual/credit [:credit :virtual], :virtual/experimental [:experimental :virtual/special], :virtual/native [:asset :virtual], :virtual/null [:NULL :virtual/special], :virtual/special [:special :virtual], :virtual/stable [:stable :virtual], :virtual/staked [:staked :virtual], :virtual/token [:asset :virtual], :virtual/wrapped [:virtual :wrapped], :virtual.credit/exchange :virtual/credit, :virtual.credit/loyalty :virtual/credit, :virtual.credit/platform :virtual/credit, :virtual.stable/peg [:peg :virtual/stable], :virtual.stable.peg/asset [:asset/referenced :virtual.stable/peg], :virtual.stable.peg/commodity [:commodity/referenced :virtual.stable/peg], :virtual.stable.peg/fiat [:fiat/referenced :virtual.stable/peg], :virtual.stable.peg/metal [:metal/referenced :virtual.stable/peg]}, :traits {:blockchain :all, :collateral :all, :control :all, :defi :all, :legacy :all, :network :all, :peg :all, :privacy :all, :stable :all, :token :all, :blockchain/arbitrum :blockchain, :blockchain/avalanche :blockchain, :blockchain/bitcoin :blockchain, :blockchain/bitcoin-cash :blockchain, :blockchain/bitcoin-gold :blockchain, :blockchain/bitcoin-sv :blockchain, :blockchain/bnb-chain :blockchain, :blockchain/canton :blockchain, :blockchain/cardano :blockchain, :blockchain/cronos :blockchain} ``` -------------------------------- ### Load Bankster Registry Source: https://github.com/randomseed-io/bankster/blob/main/README.md Use `init/load-registry` to load a registry configuration. Optionally overlay Bankster's distribution config by setting `:keep-dist?` to true. The side-effecting variant `init/load-registry!` installs the result as the global registry. ```clojure (require '[io.randomseed.bankster.init :as init]) ;; Load ONLY the provided config (no dist overlay). (def r1 (init/load-registry "my/app/currencies.edn")) ;; Load dist config first, then overlay user config ;; using importer/merge-registry. (def r2 (init/load-registry "my/app/currencies.edn" {:keep-dist? true :merge-opts {:verbose? true :preserve-fields [:domain :kind] :iso-like? false}})) ;; Side-effecting variant: installs the result as the global registry. (init/load-registry! "my/app/currencies.edn" {:keep-dist? true}) ``` -------------------------------- ### Retrieve full currency information Source: https://github.com/randomseed-io/bankster/blob/main/docs/11_sneak-peeks.html Use the `currency/info` function to get comprehensive currency details, including registry metadata like countries and localized names. This function is useful for obtaining all available information about a specific currency. ```clojure ;; Full currency information (including registry metadata). (currency/info :PLN) {:id :PLN, :numeric 985, :scale 2, :domain :ISO-4217, :kind :iso/fiat, :weight 0, :countries #{:PL}, :localized {:pl {:name "złoty polski", :symbol "zł"}}} (currency/info :crypto/USDC) {:id :crypto/USDC, :numeric -1, :scale 8, :domain :CRYPTO, ``` -------------------------------- ### Retrieving Currency Information Source: https://github.com/randomseed-io/bankster/blob/main/docs/11_sneak-peeks.html Demonstrates how to retrieve currency information from the global registry using different identifiers like keywords, namespaced symbols, strings, currency codes, ISO numeric codes, and tagged literals. It also shows how to get full currency details including metadata. ```APIDOC ## Retrieving Currency Information ### Description This section shows how to retrieve currency information using the `currency/of` function and tagged literals. It covers various lookup methods including keywords, namespaced symbols, strings, currency codes, ISO numeric codes, and tagged literals. ### Usage Examples **Using `currency/of`:** ```clojure ;; Global registry lookup with a keyword (currency/of :PLN) ;; => #currency{:id :PLN, :domain :ISO-4217, :kind :iso/fiat, :numeric 985, :scale 2} ;; Global registry lookup using namespaced symbol (currency/of crypto/ETH) ;; => #currency{:id :crypto/ETH, :domain :CRYPTO, :kind :virtual/native, :scale 18, :weight 5} ;; Global registry lookup with a string (incl. namespace a.k.a domain) (currency/of "crypto/BTC") ;; => #currency{:id :crypto/BTC, :domain :CRYPTO, :kind :virtual/native, :scale 8, :weight 5} ;; Global registry lookup with a currency code (currency/of ETH) ;; => #currency{:id :crypto/ETH, :domain :CRYPTO, :kind :virtual/native, :scale 18, :weight 5} ;; Global registry lookup using ISO currency number (currency/of 840) ;; => #currency{:id :USD, :domain :ISO-4217, :kind :iso/fiat, :numeric 840, :scale 2} ``` **Using Tagged Literals:** ```clojure ;; Global registry lookup using tagged literal with a currency code #currency XLM ;; => #currency{:id :crypto/XLM, :domain :CRYPTO, :kind :virtual/native, :scale 8} ;; Tagged literal accepts single-element vector (unwrapped) #currency [EUR] ;; => #currency{:id :EUR, :domain :ISO-4217, :kind :iso/fiat, :numeric 978, :scale 2} ;; Global registry lookup using tagged literal with a namespaced identifier #currency crypto/XLM ;; => #currency{:id :crypto/XLM, :domain :CRYPTO, :kind :virtual/native, :scale 8} ;; Global registry lookup using tagged literal with an ISO currency number #currency 978 ;; => #currency{:id :EUR, :domain :ISO-4217, :kind :iso/fiat, :numeric 978, :scale 2} ``` **Retrieving Full Currency Information:** ```clojure ;; Full currency information (including registry metadata) (currency/info :PLN) ;; => {:id :PLN, ;; :numeric 985, ;; :scale 2, ;; :domain :ISO-4217, ;; :kind :iso/fiat, ;; :weight 0, ;; :countries #{:PL}, ;; :localized {:pl {:name "złoty polski", :symbol "zł"}}} (currency/info :crypto/USDC) ;; => {:id :crypto/USDC, ;; :numeric -1, ;; :scale 8, ;; :domain :CRYPTO, ...} ``` ### Note on Code Literals Tagged literals (`#money`, `#currency`) are handled at read time via `data_readers.clj`. Ensure Bankster namespaces are loaded before code containing these literals is read to avoid errors. ``` -------------------------------- ### Build Documentation Source: https://github.com/randomseed-io/bankster/blob/main/README.md Run this command to build the project's documentation. ```bash make docs ``` -------------------------------- ### Extract Amount, Integer, and Fractional Parts Source: https://github.com/randomseed-io/bankster/blob/main/docs/11_sneak-peeks.html Extracts different components of a monetary amount. `api/amount` gets the numeric value, `scale/integer` gets the integer part, and `scale/fractional` gets the fractional part. ```clojure (api/amount #money[108.11 CHF]) 108.11M ``` ```clojure (scale/integer #money[108.11 CHF]) 108M ``` ```clojure (scale/fractional #money[108.11 CHF]) 11M ``` -------------------------------- ### Prepare for Release Source: https://github.com/randomseed-io/bankster/blob/main/README.md Run this command to prepare the project for a new release. ```bash make release ``` -------------------------------- ### Get Amount Scale with API Source: https://github.com/randomseed-io/bankster/blob/main/doc/11_sneak-peeks.md Use `api/scale` to get the current scale of a specific monetary amount. This differs from the currency's nominal scale. ```clojure ;; scale of the currency (low-level) (api/scale :XXX) -1 ;; scale of the amount (api/scale #money[12.34567 XXX]) 5 ; current scale ``` -------------------------------- ### Create and register a currency Source: https://github.com/randomseed-io/bankster/blob/main/doc/11_sneak-peeks.md Explains how to create new currency instances using constructor functions or tagged literals, and how to register them into the global registry. ```APIDOC ## Create and register a currency ### Description This section covers the creation of new currency instances and their registration into the global registry. ### Usage **Ad hoc currency creation using constructor function:** ```clojure (require '[io.randomseed.bankster.api.currency :as currency]) (currency/new :petro/USD 999 2 :COMBANK) ;; #currency{:id :petro/USD, :domain :PETRO, :kind :COMBANK, :numeric 999, :scale 2} ``` **Ad-hoc currency creation using tagged literal:** ```clojure #currency{:id :crypto/ETH :scale 18} ;; #currency{:id :crypto/ETH, :domain :CRYPTO, :scale 18} ``` **Registering a new currency into the global registry:** ```clojure (currency/register! (currency/new :petro/USD 9999 2 :COMBANK) :USA) ;; #Registry[{:currencies 221, :countries 250, :version "2021022121170359"} 0x11efe93f] (currency/of :petro/USD) ;; #currency{:id :petro/USD, :domain :PETRO, :kind :COMBANK, :numeric 9999, :scale 2} (currency/register! #currency{:id :crypto/AAA :scale 8}) ;; #Registry[{:currencies 221, :countries 249, :version "2021022121170359"} 0x7eaf7a70] ``` **Creating an ISO currency (requires a simple 3-letter code and a numeric ID):** ```clojure (currency/new :XOX 999 2 :COMBANK) ;; #currency{:id :XOX, :domain :ISO-4217, :kind :COMBANK, :numeric 999, :scale 2} ``` **Creating a strange ISO currency (forced namespace without a numerical ID):** ```clojure (currency/new :ISO-4217/XOX nil 2 :COMBANK) ;; #currency{:id :XOX, :domain :ISO-4217, :kind :COMBANK, :scale 2} ``` ``` -------------------------------- ### Get Currency Weight Source: https://github.com/randomseed-io/bankster/blob/main/docs/io.randomseed.bankster.api.currency.html Returns the weight of the given currency, used to resolve conflicts when getting currencies with conflicting codes. When `registry` is true, the default registry is used. ```clojure (weight c) (weight c registry) (weight c _locale registry) ``` -------------------------------- ### with Source: https://github.com/randomseed-io/bankster/blob/main/docs/io.randomseed.bankster.api.v2.registry.html Creates a new registry with specified configurations. ```APIDOC ## with ### Description Creates a new registry with specified configurations. ### Signature `(with registry & args)` ``` -------------------------------- ### EDN Currency Configuration Examples Source: https://github.com/randomseed-io/bankster/blob/main/doc/50_example_config.md These examples show various currency definitions in EDN format. They include ISO fiat currencies with their associated countries, numeric codes, and decimal scales. Some entries also include localized names and symbols. ```edn :KWD {:countries [:KW], :kind :iso/fiat, :numeric 414, :scale 3}, :KYD {:countries [:KY], :kind :iso/fiat, :numeric 136, :scale 2}, :KZT {:countries [:KZ], :kind :iso/fiat, :numeric 398, :scale 2}, :LAK {:countries [:LA], :kind :iso/fiat, :numeric 418, :scale 2}, :LBP {:countries [:LB], :kind :iso/fiat, :numeric 422, :scale 2}, :LKR {:countries [:LK], :kind :iso/fiat, :numeric 144, :scale 2}, :LRD {:countries [:LR], :kind :iso/fiat, :numeric 430, :scale 2}, :LSL {:countries [:LS], :kind :iso/fiat, :numeric 426, :scale 2}, :LYD {:countries [:LY], :kind :iso/fiat, :numeric 434, :scale 3}, :MAD {:countries [:EH :MA], :kind :iso/fiat, :numeric 504, :scale 2}, :MDL {:countries [:MD], :kind :iso/fiat, :numeric 498, :scale 2}, :MGA {:countries [:MG], :kind :iso/fiat, :numeric 969, :scale 2}, :MKD {:countries [:MK], :kind :iso/fiat, :numeric 807, :scale 2}, :MMK {:countries [:MM], :kind :iso/fiat, :numeric 104, :scale 2}, :MNT {:countries [:MN], :kind :iso/fiat, :numeric 496, :scale 2}, :MOP {:countries [:MO], :kind :iso/fiat, :numeric 446, :scale 2}, :MRU {:countries [:MR], :kind :iso/fiat, :numeric 929, :scale 2}, :MUR {:countries [:MU], :kind :iso/fiat, :numeric 480, :scale 2}, :MVR {:countries [:MV], :kind :iso/fiat, :numeric 462, :scale 2}, :MWK {:countries [:MW], :kind :iso/fiat, :numeric 454, :scale 2}, :MXN {:countries [:MX], :kind :iso/fiat, :numeric 484, :scale 2}, :MXV {:kind :iso.funds/market, :numeric 979, :scale 2}, :MYR {:countries [:MY], :kind :iso/fiat, :numeric 458, :scale 2}, :MZN {:countries [:MZ], :kind :iso/fiat, :numeric 943, :scale 2}, :NAD {:countries [:NA], :kind :iso/fiat, :numeric 516, :scale 2}, :NGN {:countries [:NG], :kind :iso/fiat, :numeric 566, :scale 2}, :NIO {:countries [:NI], :kind :iso/fiat, :numeric 558, :scale 2}, :NOK {:countries [:BV :NO :SJ], :kind :iso/fiat, :numeric 578, :scale 2}, :NPR {:countries [:NP], :kind :iso/fiat, :numeric 524, :scale 2}, :NZD {:countries [:CK :NU :NZ :PN :TK], :kind :iso/fiat, :numeric 554, :scale 2}, :OMR {:countries [:OM], :kind :iso/fiat, :numeric 512, :scale 3}, :PAB {:countries [:PA], :kind :iso/fiat, :numeric 590, :scale 2}, :PEN {:countries [:PE], :kind :iso/fiat, :numeric 604, :scale 2}, :PGK {:countries [:PG], :kind :iso/fiat, :numeric 598, :scale 2}, :PHP {:countries [:PH], :kind :iso/fiat, :numeric 608, :scale 2}, :PKR {:countries [:PK], :kind :iso/fiat, :numeric 586, :scale 2}, :PLN {:countries [:PL], :kind :iso/fiat, :localized {:pl {:name "złoty polski", :symbol "zł"}}, :numeric 985, :scale 2}, :PYG {:countries [:PY], :kind :iso/fiat, :numeric 600, :scale 0}, :QAR {:countries [:QA], :kind :iso/fiat, :numeric 634, :scale 2}, :RON {:countries [:RO], :kind :iso/fiat, :numeric 946, :scale 2}, :RSD {:countries [:RS], :kind :iso/fiat, :numeric 941, :scale 2}, :RUB {:countries [:RU], :kind :iso/fiat, :numeric 643, :scale 2}, :RWF {:countries [:RW], :kind :iso/fiat, :numeric 646, :scale 0}, :SAR {:countries [:SA], :kind :iso/fiat, :numeric 682, :scale 2}, :SBD {:countries [:SB], :kind :iso/fiat, :numeric 90, :scale 2}, :SCR {:countries [:SC], :kind :iso/fiat, :numeric 690, :scale 2}, :SDG {:countries [:SD], :kind :iso/fiat, :numeric 938, :scale 2}, :SEK {:countries [:SE], :kind :iso/fiat, :numeric 752, :scale 2}, :SGD {:countries [:SG], :kind :iso/fiat, :numeric 702, :scale 2}, :SHP {:countries [:SH], :kind :iso/fiat, :numeric 654, :scale 2}, :SLE {:countries [:SL], :kind :iso/fiat, :numeric 925, :scale 2}, :SOS {:countries [:SO], :kind :iso/fiat, :numeric 706, :scale 2}, :SRD {:countries [:SR], :kind :iso/fiat, :numeric 968, :scale 2}, :SSP {:countries [:SS], :kind :iso/fiat, :numeric 728, :scale 2}, :STN {:countries [:ST], :kind :iso/fiat, :numeric 930, :scale 2}, :SVC {:countries [:SV], :kind :iso/fiat, :numeric 222, :scale 2}, :SYP {:countries [:SY], :kind :iso/fiat, :numeric 760, :scale 2}, :SZL {:countries [:SZ], :kind :iso/fiat, :numeric 748, :scale 2} ``` -------------------------------- ### Build JAR Package Source: https://github.com/randomseed-io/bankster/blob/main/README.md Execute this command to build the project's JAR package. ```bash make jar ``` -------------------------------- ### Get Currency Domain Source: https://github.com/randomseed-io/bankster/blob/main/docs/io.randomseed.bankster.currency.html Returns currency domain as a keyword. ```APIDOC ## domain ### Description Returns currency domain as a keyword. For currencies added with simple identifiers (without a namespace) and numerical IDs present it will be `:ISO-4217`. For currencies with namespace-qualified identifiers it will be the upper-cased namespace name (e.g. `:CRYPTO`) set during creation of a currency object. Locale argument is ignored. ### Function Signature `(domain currency registry)` ### Parameters - `currency` (object) - The currency object. - `registry` (object) - The registry to use. ### Returns - `keyword` - The domain of the currency. ``` -------------------------------- ### Monetary Comparison and Formatting Source: https://github.com/randomseed-io/bankster/blob/main/doc/11_sneak-peeks.md Demonstrates comparing monetary values using `money/gt?` and formatting them for specific locales using `money/format`. ```clojure (money/gt? #money[10 EUR] #money[5 EUR]) ;; => true (money/format #money[1234.50 PLN] :pl_PL) ;; => "1 234,50 zł" ``` -------------------------------- ### io.randomseed.bankster.init Source: https://github.com/randomseed-io/bankster/blob/main/docs/index.html Provides helpers for initializing the Bankster registry. ```APIDOC ## io.randomseed.bankster.init ### Description Bankster library, registry initialization helpers. ### Public Functions * **load-registry** * **load-registry!** ``` -------------------------------- ### Absolute Value and Negation Source: https://github.com/randomseed-io/bankster/blob/main/docs/index.html Functions to get the absolute value and negate a monetary amount. ```APIDOC ## Absolute Value and Negation ### Description Provides functions to obtain the absolute value of a monetary amount and to negate it. ### Functions - **abs**() - **negate**() ### Example ``` // Example for getting the absolute value let absoluteAmount = abs(negativeAmount) ``` ``` -------------------------------- ### Get Countries for a Currency Source: https://github.com/randomseed-io/bankster/blob/main/docs/io.randomseed.bankster.currency.html Returns a set of country IDs for which the given currency is the main currency. ```APIDOC ## countries ### Description Returns a set of country IDs (keywords) for which the given currency is main currency. If there are no countries associated with a currency, returns nil. Locale argument is ignored. Throws when a currency cannot be resolved in the registry. ### Function Signature `(countries currency registry)` ### Parameters - `currency` (object) - The currency object. - `registry` (object) - The registry to use. ### Returns - `set` - A set of country IDs (keywords) or nil if no countries are associated. ``` -------------------------------- ### config->registry Source: https://github.com/randomseed-io/bankster/blob/main/docs/io.randomseed.bankster.api.currency.html Loads currencies and countries from an EDN file and initializes a registry. ```APIDOC ## config->registry ### Description Loads currencies and countries from an EDN file. First argument should be a string with path to the EDN resource file containing registry data, second should be a registry. Returns a registry initialized using values from the EDN file. ### Parameters #### Path Parameters - **resource-path** (string) - Required - Path to the EDN resource file. - **regi** (any) - Optional - The registry to initialize. ``` -------------------------------- ### Currency Resolution and Formatting Source: https://github.com/randomseed-io/bankster/blob/main/docs/11_sneak-peeks.html Demonstrates resolving currency information and formatting monetary amounts. `currency/resolve-all` fetches currency details, and `money/format` formats the amount according to locale. ```clojure (currency/resolve-all :EUR) ;; => #{#currency{:id :EUR, ...}} ``` ```clojure (money/format #money[1234.50 PLN] :pl_PL) ;; => "1 234,50 zł" ```