-
-
Notifications
You must be signed in to change notification settings - Fork 326
Support minor currencies #329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
0e52e8d
eb30f61
0f05f89
5430bb2
b18b595
420ea93
92553b1
3889b47
2de909e
f5753d1
9caeee1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| package unary | ||
|
|
||
| // minorCurrency represents the scaling ('minor unit') for a minor currency. | ||
| // Convert major to minor by multiplying by 10^n and minor to major by dividing by 10^n. | ||
| type minorCurrency struct { | ||
| MajorCurrencyCode string | ||
| MinorCurrencyCode string | ||
| MinorUnit float64 | ||
| } | ||
|
|
||
| // Just consider the currencies traded on major exchanges | ||
| func MinorUnitForCurrencyCode(majorCurrency string) (bool, string, float64) { | ||
|
|
||
| var minorCurrencyCodeByMajorCurrencyCode = map[string]minorCurrency{ | ||
| "AUD": {"AUD", "AUd", 2}, | ||
| "CAD": {"CAD", "CAd", 2}, | ||
| "CHF": {"CHF", "CHf", 2}, | ||
| "CNY": {"CNY", "CNy", 2}, | ||
| "EUR": {"EUR", "EUr", 2}, | ||
| "GBP": {"GBP", "GBp", 2}, | ||
| "HKD": {"HKD", "HKd", 2}, | ||
| "INR": {"INR", "INr", 2}, | ||
| "TWD": {"TWD", "TWd", 2}, | ||
| "USD": {"USD", "USd", 2}, | ||
| "ZAR": {"ZAR", "ZAr", 2}, | ||
| } | ||
|
|
||
| if mc, ok := minorCurrencyCodeByMajorCurrencyCode[majorCurrency]; ok { | ||
|
|
||
| return true, mc.MinorCurrencyCode, mc.MinorUnit | ||
| } | ||
|
|
||
| return false, "", 0 | ||
|
|
||
| } | ||
|
|
||
| /* | ||
| // This map is derived from https://www.six-group.com/dam/download/financial-information/data-center/iso-currrency/lists/list-one.xls | ||
| // Retaining this as a reference to the complete list as at October 2025. | ||
| var _minorCurrencyCodeByMajorCurrencyCode = map[string]minorCurrency{ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this list be limited to only trading currencies for major exchanges? I expect most of these currencies do not have trading pairs on any exchanges so the list could be slimed down. This like should be a good start and based on reported issues, others can be added.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reduced the list of minor currencies considered to those you suggest. |
||
| "AED": {"AED", "AEd", 2}, | ||
| "AFN": {"AFN", "AFn", 2}, | ||
| "ALL": {"ALL", "ALl", 2}, | ||
| "AMD": {"AMD", "AMd", 2}, | ||
| "AOA": {"AOA", "AOa", 2}, | ||
| "ARS": {"ARS", "ARs", 2}, | ||
| "AUD": {"AUD", "AUd", 2}, | ||
| "AWG": {"AWG", "AWg", 2}, | ||
| "AZN": {"AZN", "AZn", 2}, | ||
| "BAM": {"BAM", "BAm", 2}, | ||
| "BBD": {"BBD", "BBd", 2}, | ||
| "BDT": {"BDT", "BDt", 2}, | ||
| "BGN": {"BGN", "BGn", 2}, | ||
| "BHD": {"BHD", "BHd", 3}, | ||
| "BMD": {"BMD", "BMd", 2}, | ||
| "BND": {"BND", "BNd", 2}, | ||
| "BOB": {"BOB", "BOb", 2}, | ||
| "BOV": {"BOV", "BOv", 2}, | ||
| "BRL": {"BRL", "BRl", 2}, | ||
| "BSD": {"BSD", "BSd", 2}, | ||
| "BTN": {"BTN", "BTn", 2}, | ||
| "BWP": {"BWP", "BWp", 2}, | ||
| "BYN": {"BYN", "BYn", 2}, | ||
| "BZD": {"BZD", "BZd", 2}, | ||
| "CAD": {"CAD", "CAd", 2}, | ||
| "CDF": {"CDF", "CDf", 2}, | ||
| "CHE": {"CHE", "CHe", 2}, | ||
| "CHF": {"CHF", "CHf", 2}, | ||
| "CHW": {"CHW", "CHw", 2}, | ||
| "CLF": {"CLF", "CLf", 4}, | ||
| "CNY": {"CNY", "CNy", 2}, | ||
| "COP": {"COP", "COp", 2}, | ||
| "COU": {"COU", "COu", 2}, | ||
| "CRC": {"CRC", "CRc", 2}, | ||
| "CUP": {"CUP", "CUp", 2}, | ||
| "CVE": {"CVE", "CVe", 2}, | ||
| "CZK": {"CZK", "CZk", 2}, | ||
| "DKK": {"DKK", "DKk", 2}, | ||
| "DOP": {"DOP", "DOp", 2}, | ||
| "DZD": {"DZD", "DZd", 2}, | ||
| "EGP": {"EGP", "EGp", 2}, | ||
| "ERN": {"ERN", "ERn", 2}, | ||
| "ETB": {"ETB", "ETb", 2}, | ||
| "EUR": {"EUR", "EUr", 2}, | ||
| "FJD": {"FJD", "FJd", 2}, | ||
| "FKP": {"FKP", "FKp", 2}, | ||
| "GBP": {"GBP", "GBp", 2}, | ||
| "GEL": {"GEL", "GEl", 2}, | ||
| "GHS": {"GHS", "GHs", 2}, | ||
| "GIP": {"GIP", "GIp", 2}, | ||
| "GMD": {"GMD", "GMd", 2}, | ||
| "GTQ": {"GTQ", "GTq", 2}, | ||
| "GYD": {"GYD", "GYd", 2}, | ||
| "HKD": {"HKD", "HKd", 2}, | ||
| "HNL": {"HNL", "HNl", 2}, | ||
| "HTG": {"HTG", "HTg", 2}, | ||
| "HUF": {"HUF", "HUf", 2}, | ||
| "IDR": {"IDR", "IDr", 2}, | ||
| "ILS": {"ILS", "ILs", 2}, | ||
| "INR": {"INR", "INr", 2}, | ||
| "IQD": {"IQD", "IQd", 3}, | ||
| "IRR": {"IRR", "IRr", 2}, | ||
| "JMD": {"JMD", "JMd", 2}, | ||
| "JOD": {"JOD", "JOd", 3}, | ||
| "KES": {"KES", "KEs", 2}, | ||
| "KGS": {"KGS", "KGs", 2}, | ||
| "KHR": {"KHR", "KHr", 2}, | ||
| "KPW": {"KPW", "KPw", 2}, | ||
| "KWD": {"KWD", "KWd", 3}, | ||
| "KYD": {"KYD", "KYd", 2}, | ||
| "KZT": {"KZT", "KZt", 2}, | ||
| "LAK": {"LAK", "LAk", 2}, | ||
| "LBP": {"LBP", "LBp", 2}, | ||
| "LKR": {"LKR", "LKr", 2}, | ||
| "LRD": {"LRD", "LRd", 2}, | ||
| "LSL": {"LSL", "LSl", 2}, | ||
| "LYD": {"LYD", "LYd", 3}, | ||
| "MAD": {"MAD", "MAd", 2}, | ||
| "MDL": {"MDL", "MDl", 2}, | ||
| "MGA": {"MGA", "MGa", 2}, | ||
| "MKD": {"MKD", "MKd", 2}, | ||
| "MMK": {"MMK", "MMk", 2}, | ||
| "MNT": {"MNT", "MNt", 2}, | ||
| "MOP": {"MOP", "MOp", 2}, | ||
| "MRU": {"MRU", "MRu", 2}, | ||
| "MUR": {"MUR", "MUr", 2}, | ||
| "MVR": {"MVR", "MVr", 2}, | ||
| "MWK": {"MWK", "MWk", 2}, | ||
| "MXN": {"MXN", "MXn", 2}, | ||
| "MXV": {"MXV", "MXv", 2}, | ||
| "MYR": {"MYR", "MYr", 2}, | ||
| "MZN": {"MZN", "MZn", 2}, | ||
| "NAD": {"NAD", "NAd", 2}, | ||
| "NGN": {"NGN", "NGn", 2}, | ||
| "NIO": {"NIO", "NIo", 2}, | ||
| "NOK": {"NOK", "NOk", 2}, | ||
| "NPR": {"NPR", "NPr", 2}, | ||
| "NZD": {"NZD", "NZd", 2}, | ||
| "OMR": {"OMR", "OMr", 3}, | ||
| "PAB": {"PAB", "PAb", 2}, | ||
| "PEN": {"PEN", "PEn", 2}, | ||
| "PGK": {"PGK", "PGk", 2}, | ||
| "PHP": {"PHP", "PHp", 2}, | ||
| "PKR": {"PKR", "PKr", 2}, | ||
| "PLN": {"PLN", "PLn", 2}, | ||
| "QAR": {"QAR", "QAr", 2}, | ||
| "RON": {"RON", "ROn", 2}, | ||
| "RSD": {"RSD", "RSd", 2}, | ||
| "RUB": {"RUB", "RUb", 2}, | ||
| "SAR": {"SAR", "SAr", 2}, | ||
| "SBD": {"SBD", "SBd", 2}, | ||
| "SCR": {"SCR", "SCr", 2}, | ||
| "SDG": {"SDG", "SDg", 2}, | ||
| "SEK": {"SEK", "SEk", 2}, | ||
| "SGD": {"SGD", "SGd", 2}, | ||
| "SHP": {"SHP", "SHp", 2}, | ||
| "SLE": {"SLE", "SLe", 2}, | ||
| "SOS": {"SOS", "SOs", 2}, | ||
| "SRD": {"SRD", "SRd", 2}, | ||
| "SSP": {"SSP", "SSp", 2}, | ||
| "STN": {"STN", "STn", 2}, | ||
| "SVC": {"SVC", "SVc", 2}, | ||
| "SYP": {"SYP", "SYp", 2}, | ||
| "SZL": {"SZL", "SZl", 2}, | ||
| "THB": {"THB", "THb", 2}, | ||
| "TJS": {"TJS", "TJs", 2}, | ||
| "TMT": {"TMT", "TMt", 2}, | ||
| "TND": {"TND", "TNd", 3}, | ||
| "TOP": {"TOP", "TOp", 2}, | ||
| "TRY": {"TRY", "TRy", 2}, | ||
| "TTD": {"TTD", "TTd", 2}, | ||
| "TWD": {"TWD", "TWd", 2}, | ||
| "TZS": {"TZS", "TZs", 2}, | ||
| "UAH": {"UAH", "UAh", 2}, | ||
| "USD": {"USD", "USd", 2}, | ||
| "USN": {"USN", "USn", 2}, | ||
| "UYU": {"UYU", "UYu", 2}, | ||
| "UYW": {"UYW", "UYw", 4}, | ||
| "UZS": {"UZS", "UZs", 2}, | ||
| "VED": {"VED", "VEd", 2}, | ||
| "VES": {"VES", "VEs", 2}, | ||
| "WST": {"WST", "WSt", 2}, | ||
| "XAD": {"XAD", "XAd", 2}, | ||
| "XCD": {"XCD", "XCd", 2}, | ||
| "XCG": {"XCG", "XCg", 2}, | ||
| "YER": {"YER", "YEr", 2}, | ||
| "ZAR": {"ZAR", "ZAr", 2}, | ||
| "ZMW": {"ZMW", "ZMw", 2}, | ||
| "ZWG": {"ZWG", "ZWg", 2}, | ||
| } | ||
| */ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for improving test coverage here!