-
-
Notifications
You must be signed in to change notification settings - Fork 328
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 6 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 |
|---|---|---|
|
|
@@ -610,5 +610,62 @@ var _ = Describe("Cli", func() { | |
| }) | ||
| }) | ||
|
|
||
| Describe("currency", func() { | ||
|
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. Thank you for improving test coverage here! |
||
| When("a mixed-case currency is specified in the config file", func() { | ||
| It("should return an error (even if a valid minor currency)", func() { | ||
| options.Watchlist = "SEIT.L" | ||
| config = c.Config{ | ||
| Currency: "USd", | ||
| } | ||
| outputErr := Validate(&config, &options, nil)(&cobra.Command{}, []string{}) | ||
| Expect(outputErr).To(MatchError("invalid config: Display currency may only be an ISO 4712 major currency or blank (eg GBP not GBp; default: USD)")) | ||
| }) | ||
| }) | ||
|
|
||
| When("a blank currency is specified in the config file", func() { | ||
| It("should not return an error", func() { | ||
| options.Watchlist = "SEIT.L" | ||
| config := c.Config{ | ||
| Currency: "", | ||
| } | ||
| outputErr := Validate(&config, &options, nil)(&cobra.Command{}, []string{}) | ||
| Expect(outputErr).NotTo(HaveOccurred()) | ||
| }) | ||
| }) | ||
|
|
||
| When("a short currency (len < 3) is specified in the config file", func() { | ||
| It("should return an error", func() { | ||
| options.Watchlist = "SEIT.L" | ||
| config := c.Config{ | ||
| Currency: "US", | ||
| } | ||
| outputErr := Validate(&config, &options, nil)(&cobra.Command{}, []string{}) | ||
| Expect(outputErr).To(MatchError("invalid config: Display currency may only be an ISO 4712 major currency or blank (eg GBP not GBp; default: USD)")) | ||
| }) | ||
| }) | ||
|
|
||
| When("a long currency (len > 3) is specified in the config file", func() { | ||
| It("should return an error", func() { | ||
| options.Watchlist = "SEIT.L" | ||
| config := c.Config{ | ||
| Currency: "USD2", | ||
| } | ||
| outputErr := Validate(&config, &options, nil)(&cobra.Command{}, []string{}) | ||
| Expect(outputErr).To(MatchError("invalid config: Display currency may only be an ISO 4712 major currency or blank (eg GBP not GBp; default: USD)")) | ||
| }) | ||
| }) | ||
|
|
||
| PWhen("a non-ISO 4712 currency is specified in the config file", func() { | ||
|
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. Should this be unskipped?
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. To do this properly I'd have to included the full list of ISO 4217 codes. But if you want just the ones suggested above to be included then I'd be happy to do that. Or the full list, whichever you prefer. |
||
| PIt("should return an error", func() { | ||
| options.Watchlist = "SEIT.L" | ||
| config = c.Config{ | ||
| Currency: "XXX", | ||
| } | ||
| outputErr := Validate(&config, &options, nil)(&cobra.Command{}, []string{}) | ||
| Expect(outputErr).To(MatchError("invalid config: Display currency may only be an ISO 4712 major currency or blank (eg GBP not GBp; default: USD)")) | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| 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 | ||
| } | ||
|
|
||
| // This map is derived from https://www.six-group.com/dam/download/financial-information/data-center/iso-currrency/lists/list-one.xls | ||
| 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}, | ||
| } | ||
|
|
||
| func MinorUnitForCurrencyCode(majorCurrency string) (bool, string, float64) { | ||
|
|
||
| if mc, ok := _minorCurrencyCodeByMajorCurrencyCode[majorCurrency]; ok { | ||
|
|
||
| return true, mc.MinorCurrencyCode, mc.MinorUnit | ||
| } | ||
|
|
||
| return false, "", 0 | ||
|
|
||
| } | ||
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.
Typo here - should be
ISO 4217There 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.
Corrected above and in other places