-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from nntaoli-project/dev
Merge from org source
- Loading branch information
Showing
18 changed files
with
283 additions
and
734 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
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"} | ||
BTC = Currency{"BTC", "bitcoin.org"} | ||
BCC = Currency{"BCC", "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", ""} | ||
|
||
//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} | ||
|
||
LTC_BTC = CurrencyPair{LTC, BTC} | ||
ETH_BTC = CurrencyPair{ETH, BTC} | ||
ETC_BTC = CurrencyPair{ETC, BTC} | ||
BCC_BTC = CurrencyPair{BCC, BTC} | ||
|
||
ETC_ETH = CurrencyPair{ETC, ETH} | ||
EOS_ETH = CurrencyPair{EOS, ETH} | ||
) | ||
|
||
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 (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) | ||
} |
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,19 @@ | ||
package goex | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestCurrency2_String(t *testing.T) { | ||
btc := NewCurrency("btc", "bitcoin") | ||
ltc := NewCurrency("ltc", "litecoin") | ||
t.Log(btc) | ||
t.Log(ltc) | ||
} | ||
|
||
func TestCurrencyPair2_String(t *testing.T) { | ||
btccny := NewCurrencyPair(NewCurrency("btc", ""), NewCurrency("cny", "")) | ||
t.Log(strings.ToUpper(btccny.String())) | ||
t.Log(BTC_CNY) | ||
} |
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,16 @@ | ||
package goex | ||
|
||
import "strconv" | ||
|
||
func ToFloat64(v interface{}) float64 { | ||
switch v.(type) { | ||
case float64: | ||
return v.(float64) | ||
case string: | ||
vStr, _ := v.(string) | ||
vF, _ := strconv.ParseFloat(vStr, 64) | ||
return vF | ||
default: | ||
panic("to float64 error.") | ||
} | ||
} |
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.