-
Notifications
You must be signed in to change notification settings - Fork 0
/
CurrencyPair.go
107 lines (89 loc) · 2.79 KB
/
CurrencyPair.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
package goex
import "strings"
type Currency struct {
Symbol string
Desc string
}
func (c Currency) String() string {
return c.Symbol
}
// A->B(A兑换为B)
type CurrencyPair struct {
CurrencyA Currency
CurrencyB Currency
}
var (
UNKNOWN = Currency{"UNKNOWN", ""}
CNY = Currency{"CNY", "rmb (China Yuan)"}
USD = Currency{"USD", "USA dollar"}
USDT = Currency{"USDT", "http://tether.io"}
EUR = Currency{"EUR", ""}
BTC = Currency{"BTC", "bitcoin.org"}
XBT = Currency{"XBT", "bitcoin.org"}
BCC = Currency{"BCC", "bitcoin-abc"}
BCH = Currency{"BCH", "bitcoin-abc"}
LTC = Currency{"LTC", "litecoin.org"}
ETH = Currency{"ETH", ""}
ETC = Currency{"ETC", ""}
EOS = Currency{"EOS", ""}
BTS = Currency{"BTS", ""}
QTUM = Currency{"QTUM", ""}
SC = Currency{"SC", "sia.tech"}
ANS = Currency{"ANS", "www.antshares.org"}
ZEC = Currency{"ZEC", ""}
DCR = Currency{"DCR", ""}
XRP = Currency{"XRP", ""}
//currency pair
BTC_CNY = CurrencyPair{BTC, CNY}
LTC_CNY = CurrencyPair{LTC, CNY}
BCC_CNY = CurrencyPair{BCC, CNY}
ETH_CNY = CurrencyPair{ETH, CNY}
ETC_CNY = CurrencyPair{ETC, CNY}
EOS_CNY = CurrencyPair{EOS, CNY}
BTS_CNY = CurrencyPair{BTS, CNY}
QTUM_CNY = CurrencyPair{QTUM, CNY}
SC_CNY = CurrencyPair{SC, CNY}
ANS_CNY = CurrencyPair{ANS, CNY}
ZEC_CNY = CurrencyPair{ZEC, CNY}
BTC_USD = CurrencyPair{BTC, USD}
LTC_USD = CurrencyPair{LTC, USD}
ETH_USD = CurrencyPair{ETH, USD}
ETC_USD = CurrencyPair{ETC, USD}
BCH_USD = CurrencyPair{BCH, USD}
BCC_USD = CurrencyPair{BCC, USD}
XRP_USD = CurrencyPair{XRP, USD}
XRP_EUR = CurrencyPair{XRP, EUR}
LTC_BTC = CurrencyPair{LTC, BTC}
ETH_BTC = CurrencyPair{ETH, BTC}
ETC_BTC = CurrencyPair{ETC, BTC}
BCC_BTC = CurrencyPair{BCC, BTC}
BCH_BTC = CurrencyPair{BCH, BTC}
DCR_BTC = CurrencyPair{DCR, BTC}
XRP_BTC = CurrencyPair{XRP, BTC}
ETC_ETH = CurrencyPair{ETC, ETH}
EOS_ETH = CurrencyPair{EOS, ETH}
UNKNOWN_PAIR = CurrencyPair{UNKNOWN, UNKNOWN}
)
func (c CurrencyPair) String() string {
return c.ToSymbol("_")
}
func NewCurrency(symbol, desc string) Currency {
return Currency{symbol, desc}
}
func NewCurrencyPair(currencyA Currency, currencyB Currency) CurrencyPair {
return CurrencyPair{currencyA, currencyB}
}
func NewCurrencyPair2(currencyPairSymbol string) CurrencyPair {
currencys := strings.Split(currencyPairSymbol, "_")
if len(currencys) == 2 {
return CurrencyPair{NewCurrency(currencys[0], ""),
NewCurrency(currencys[1], "")}
}
return UNKNOWN_PAIR
}
func (pair CurrencyPair) ToSymbol(joinChar string) string {
return strings.Join([]string{pair.CurrencyA.Symbol, pair.CurrencyB.Symbol}, joinChar)
}
func (pair CurrencyPair) ToSymbol2(joinChar string) string {
return strings.Join([]string{pair.CurrencyB.Symbol, pair.CurrencyA.Symbol}, joinChar)
}