-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnormalization.go
116 lines (105 loc) · 2.8 KB
/
normalization.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
package ticker
import (
"encoding/json"
"log"
)
// RequiredSymbols are symbols we expect to be present and their absence should
// be treated as an error.
var RequiredSymbols = []string{
"USD",
"EUR",
"GBP",
"CAD",
"RUB",
"BRL",
"AUD",
"BGN",
"NOK",
"CZK",
"BTC",
"BCH",
"ZEC",
"ETH",
}
// AltSymbolsToCanonicalSymbols maps symbols that may be used in some sources to
// represent coins that we use a different symbol for
var AltSymbolsToCanonicalSymbols = map[string]string{
"IOTA": "MIOTA",
}
// PinnedSymbolsToIDs maps symbols that may be used by multiple coins to a
// single coin by its CMC IDs.
var PinnedSymbolsToIDs = map[string]int64{
"BTC": 1, // Bitcoin
"LTC": 2, // Litecoin
"NXT": 66, // Nxt
"DOGE": 74, // Dogecoin
"DASH": 131, // Dash
"XMR": 328, // Monero
"ETH": 1027, // Ethereum
"ZEC": 1437, // Zcash
"BCH": 1831, // Bitcoin Cash
"BTG": 2083, // Bitcoin Gold
"CMT": 2246, // CyberMiles
"KNC": 1982, // Kyber Network
"BTM": 1866, // Bytom
"ICN": 1408, // Iconomi
"GTC": 2336, // Game.com
"BLZ": 2505, // Bluzelle
"HOT": 2682, // Holo
"RCN": 2096, // Ripio Credit Network
"FAIR": 224, // FairCoin
"EDR": 2835, // Endor Protocol
"CPC": 2482, // CPChain
"QBT": 2242, // Qbao
"KEY": 2398, // Selfkey
"RED": 2771, // RED
"HMC": 2484, // Hi Mutual Society
"NET": 1811, // Nimiq Exchange Token
"LNC": 2677, // Linker Coin
"CAN": 2343, // CanYaCoin
"BET": 1771, // DAO.Casino
"SPD": 2616, // Stipend
"CAT": 2334, // BitClave
"GCC": 1531, // Global Cryptocurrency
"PUT": 2419, // Profile Utility Token
"MAG": 2218, // Magnet
"CRC": 2664, // CryCash
"ACC": 2225, // Accelerator Network
"PXC": 35, // Phoenixcoin
"ETT": 1714, // EncryptoTel [WAVES]
"XIN": 2349, // Mixin
"HERO": 1805, // Sovereign Hero
"HNC": 1004, // Helleniccoin
"ENT": 1474, // Eternity
"LBTC": 1825, // LiteBitcoin
"CMS": 2262, // COMSA [ETH]
}
var pinnedSymbolsToIDsJSON []byte
// PinnedSymbolsToIDsJSON returns the PinnedSymbolsToIDs marshaled to JSON
func PinnedSymbolsToIDsJSON() []byte {
return pinnedSymbolsToIDsJSON
}
func init() {
var err error
pinnedSymbolsToIDsJSON, err = json.Marshal(&PinnedSymbolsToIDs)
if err != nil {
log.Fatalln(err)
}
}
// CanonicalizeSymbol returns the canonical symbol from the given one, which may
// or may not be a nickname
func CanonicalizeSymbol(symbol string) string {
if canonicalSymbol, ok := AltSymbolsToCanonicalSymbols[symbol]; ok {
symbol = canonicalSymbol
}
return symbol
}
// IsCorrectIDForSymbol checks if the given id is the correct one for the given
// symbol based on the map `PinnedSymbolsToIDs`
func IsCorrectIDForSymbol(symbol string, id int64) bool {
pinnedSymbolID, symbolHasDupes := PinnedSymbolsToIDs[symbol]
if !symbolHasDupes || pinnedSymbolID == id {
return true
}
return false
}