forked from thrasher-corp/gocryptotrader
/
currency.go
119 lines (103 loc) · 3.38 KB
/
currency.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
110
111
112
113
114
115
116
117
118
119
package currency
// GetDefaultExchangeRates returns the currency exchange rates based off the
// default fiat values
func GetDefaultExchangeRates() (Conversions, error) {
return storage.GetDefaultForeignExchangeRates()
}
// GetExchangeRates returns the full fiat currency exchange rates base off
// configuration parameters supplied to the currency storage
func GetExchangeRates() (Conversions, error) {
return storage.GetExchangeRates()
}
// UpdateBaseCurrency updates storage base currency
func UpdateBaseCurrency(c Code) error {
return storage.UpdateBaseCurrency(c)
}
// GetBaseCurrency returns the storage base currency
func GetBaseCurrency() Code {
return storage.GetBaseCurrency()
}
// GetDefaultBaseCurrency returns storage default base currency
func GetDefaultBaseCurrency() Code {
return storage.GetDefaultBaseCurrency()
}
// GetCryptocurrencies returns the storage enabled cryptocurrencies
func GetCryptocurrencies() Currencies {
return storage.GetCryptocurrencies()
}
// GetDefaultCryptocurrencies returns a list of default cryptocurrencies
func GetDefaultCryptocurrencies() Currencies {
return storage.GetDefaultCryptocurrencies()
}
// GetFiatCurrencies returns the storage enabled fiat currencies
func GetFiatCurrencies() Currencies {
return storage.GetFiatCurrencies()
}
// GetDefaultFiatCurrencies returns a list of default fiat currencies
func GetDefaultFiatCurrencies() Currencies {
return storage.GetDefaultFiatCurrencies()
}
// UpdateCurrencies updates the local cryptocurrency or fiat currency store
func UpdateCurrencies(c Currencies, isCryptocurrency bool) {
if isCryptocurrency {
storage.UpdateEnabledCryptoCurrencies(c)
return
}
storage.UpdateEnabledFiatCurrencies(c)
}
// ConvertCurrency converts an amount from one currency to another
func ConvertCurrency(amount float64, from, to Code) (float64, error) {
return storage.ConvertCurrency(amount, from, to)
}
// SeedForeignExchangeData seeds FX data with the currencies supplied
func SeedForeignExchangeData(c Currencies) error {
return storage.SeedForeignExchangeRatesByCurrencies(c)
}
// GetTotalMarketCryptocurrencies returns the full market cryptocurrencies
func GetTotalMarketCryptocurrencies() ([]Code, error) {
return storage.GetTotalMarketCryptocurrencies()
}
// RunStorageUpdater runs a new foreign exchange updater instance
func RunStorageUpdater(o BotOverrides, m *MainConfiguration, filepath string, v bool) error {
return storage.RunUpdater(o, m, filepath, v)
}
// CopyPairFormat copies the pair format from a list of pairs once matched
func CopyPairFormat(p Pair, pairs []Pair, exact bool) Pair {
for x := range pairs {
if exact {
if p.Equal(pairs[x]) {
return pairs[x]
}
}
if p.EqualIncludeReciprocal(pairs[x]) {
return pairs[x]
}
}
return Pair{Base: NewCode(""), Quote: NewCode("")}
}
// FormatPairs formats a string array to a list of currency pairs with the
// supplied currency pair format
func FormatPairs(pairs []string, delimiter, index string) (Pairs, error) {
var result Pairs
for x := range pairs {
if pairs[x] == "" {
continue
}
var p Pair
if delimiter != "" {
p = NewPairDelimiter(pairs[x], delimiter)
} else {
if index != "" {
var err error
p, err = NewPairFromIndex(pairs[x], index)
if err != nil {
return Pairs{}, err
}
} else {
p = NewPairFromStrings(pairs[x][0:3], pairs[x][3:])
}
}
result = append(result, p)
}
return result, nil
}