-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
109 lines (89 loc) · 2.52 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package bsvrates
import "strings"
const (
// version is the current package version
version = "v0.4.3"
// defaultUserAgent is the default user agent for all requests
defaultUserAgent string = "go-bsvrates: " + version
// CoinPaprikaQuoteID is the id for CoinPaprika (BSV)
CoinPaprikaQuoteID = "bsv-bitcoin-sv"
)
var (
// defaultProviders (if no provider slice is set, use this as the default set)
defaultProviders = []Provider{ProviderCoinPaprika, ProviderWhatsOnChain}
)
// Provider is a provider for rates or prices
type Provider uint8
// Provider constants for the different available rate providers.
// Leave the start and last constants in place
const (
_ Provider = iota // 0
ProviderWhatsOnChain // 1
ProviderCoinPaprika // 2
providerLast // 3
)
// IsValid tests if the provider is valid or not
func (p Provider) IsValid() bool {
return p >= ProviderWhatsOnChain && p < providerLast
}
// Name will return the display name for the given provider
func (p Provider) Name() string {
switch p {
case ProviderWhatsOnChain:
return "WhatsOnChain"
case ProviderCoinPaprika:
return "CoinPaprika"
case providerLast:
return ""
default:
return ""
}
}
// ProviderToName helper function to convert the provider value to it's associated name
func ProviderToName(provider Provider) string {
return provider.Name()
}
// Currency is a valid currency for rates or prices
type Currency uint8
// Currency constants for the different available currencies.
// Leave the start and last constants in place
const (
_ Currency = iota
CurrencyDollars = 1
CurrencyBitcoin = 2
currencyLast = iota
)
// IsValid tests if the provider is valid or not
func (c Currency) IsValid() bool {
return c >= CurrencyDollars && c < currencyLast
}
// IsAccepted tests if the currency is accepted by all providers
func (c Currency) IsAccepted() bool {
return c == CurrencyDollars
}
// Name will return the display name for the given currency
func (c Currency) Name() string {
switch c {
case CurrencyDollars:
return usd
case CurrencyBitcoin:
return "bsv"
default:
return ""
}
}
// CurrencyToName helper function to convert the currency value to it's associated name
func CurrencyToName(currency Currency) string {
return currency.Name()
}
// CurrencyFromName helper function to convert the name into it's Currency type
func CurrencyFromName(name string) Currency {
switch strings.ToLower(name) {
case usd:
return CurrencyDollars
case "bsv":
return CurrencyBitcoin
default:
return CurrencyDollars
}
}