forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fiat display currency setting, defaults to USD
- Loading branch information
Showing
7 changed files
with
310 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package symbol | ||
|
||
import "errors" | ||
|
||
// symbols map holds the currency name and symbol mappings | ||
var symbols = map[string]string{ | ||
"ALL": "Lek", | ||
"AFN": "؋", | ||
"ARS": "$", | ||
"AWG": "ƒ", | ||
"AUD": "$", | ||
"AZN": "ман", | ||
"BSD": "$", | ||
"BBD": "$", | ||
"BYN": "Br", | ||
"BZD": "BZ$", | ||
"BMD": "$", | ||
"BOB": "$b", | ||
"BAM": "KM", | ||
"BWP": "P", | ||
"BGN": "лв", | ||
"BRL": "R$", | ||
"BND": "$", | ||
"KHR": "៛", | ||
"CAD": "$", | ||
"KYD": "$", | ||
"CLP": "$", | ||
"CNY": "¥", | ||
"COP": "$", | ||
"CRC": "₡", | ||
"HRK": "kn", | ||
"CUP": "₱", | ||
"CZK": "Kč", | ||
"DKK": "kr", | ||
"DOP": "RD$", | ||
"XCD": "$", | ||
"EGP": "£", | ||
"SVC": "$", | ||
"EUR": "€", | ||
"FKP": "£", | ||
"FJD": "$", | ||
"GHS": "¢", | ||
"GIP": "£", | ||
"GTQ": "Q", | ||
"GGP": "£", | ||
"GYD": "$", | ||
"HNL": "L", | ||
"HKD": "$", | ||
"HUF": "Ft", | ||
"ISK": "kr", | ||
"INR": "₹", | ||
"IDR": "Rp", | ||
"IRR": "﷼", | ||
"IMP": "£", | ||
"ILS": "₪", | ||
"JMD": "J$", | ||
"JPY": "¥", | ||
"JEP": "£", | ||
"KZT": "лв", | ||
"KPW": "₩", | ||
"KRW": "₩", | ||
"KGS": "лв", | ||
"LAK": "₭", | ||
"LBP": "£", | ||
"LRD": "$", | ||
"MKD": "ден", | ||
"MYR": "RM", | ||
"MUR": "₨", | ||
"MXN": "$", | ||
"MNT": "₮", | ||
"MZN": "MT", | ||
"NAD": "$", | ||
"NPR": "₨", | ||
"ANG": "ƒ", | ||
"NZD": "$", | ||
"NIO": "C$", | ||
"NGN": "₦", | ||
"NOK": "kr", | ||
"OMR": "﷼", | ||
"PKR": "₨", | ||
"PAB": "B/.", | ||
"PYG": "Gs", | ||
"PEN": "S/.", | ||
"PHP": "₱", | ||
"PLN": "zł", | ||
"QAR": "﷼", | ||
"RON": "lei", | ||
"RUB": "₽", | ||
"SHP": "£", | ||
"SAR": "﷼", | ||
"RSD": "Дин.", | ||
"SCR": "₨", | ||
"SGD": "$", | ||
"SBD": "$", | ||
"SOS": "S", | ||
"ZAR": "R", | ||
"LKR": "₨", | ||
"SEK": "kr", | ||
"CHF": "CHF", | ||
"SRD": "$", | ||
"SYP": "£", | ||
"TWD": "NT$", | ||
"THB": "฿", | ||
"TTD": "TT$", | ||
"TRY": "₺", | ||
"TVD": "$", | ||
"UAH": "₴", | ||
"GBP": "£", | ||
"USD": "$", | ||
"UYU": "$U", | ||
"UZS": "лв", | ||
"VEF": "Bs", | ||
"VND": "₫", | ||
"YER": "﷼", | ||
"ZWD": "Z$", | ||
} | ||
|
||
// GetSymbolByCurrencyName returns a currency symbol | ||
func GetSymbolByCurrencyName(currency string) (string, error) { | ||
result, ok := symbols[currency] | ||
if !ok { | ||
return "", errors.New("currency symbol not found") | ||
} | ||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package symbol | ||
|
||
import "testing" | ||
|
||
func TestGetSymbolByCurrencyName(t *testing.T) { | ||
expected := "₩" | ||
actual, err := GetSymbolByCurrencyName("KPW") | ||
if err != nil { | ||
t.Errorf("Test failed. TestGetSymbolByCurrencyName error: %s", err) | ||
} | ||
|
||
if actual != expected { | ||
t.Errorf("Test failed. TestGetSymbolByCurrencyName differing values") | ||
} | ||
|
||
_, err = GetSymbolByCurrencyName("BLAH") | ||
if err == nil { | ||
t.Errorf("Test failed. TestGetSymbolByCurrencyNam returned nil on non-existant currency") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.