Skip to content

Commit

Permalink
add two api for huobipro
Browse files Browse the repository at this point in the history
1. GetCurrenciesList
2. GetCurrenciesPrecision
fix bug in getPairFromChannel
  • Loading branch information
Eric HU authored and Eric HU committed Nov 15, 2018
1 parent cf076e8 commit 173fef2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
61 changes: 57 additions & 4 deletions huobi/HuobiPro.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ type HuoBiPro struct {
wsKLineHandleMap map[string]func(*Kline)
}

type HuoBiProSymbol struct {
BaseCurrency string
QuoteCurrency string
PricePrecision float64
AmountPrecision float64
SymbolPartition string
Symbol string
}

func NewHuoBiPro(client *http.Client, apikey, secretkey, accountId string) *HuoBiPro {
hbpro := new(HuoBiPro)
hbpro.baseUrl = "https://api.huobi.br.com"
Expand Down Expand Up @@ -636,13 +645,13 @@ func (hbpro *HuoBiPro) getPairFromChannel(ch string) CurrencyPair {
var currA, currB string
if strings.HasSuffix(s[1], "usdt") {
currB = "usdt"
} else if strings.HasSuffix(ch, "husd") {
} else if strings.HasSuffix(s[1], "husd") {
currB = "husd"
} else if strings.HasSuffix(ch, "btc") {
} else if strings.HasSuffix(s[1], "btc") {
currB = "btc"
} else if strings.HasSuffix(ch, "eth") {
} else if strings.HasSuffix(s[1], "eth") {
currB = "eth"
} else if strings.HasSuffix(ch, "ht") {
} else if strings.HasSuffix(s[1], "ht") {
currB = "ht"
}

Expand Down Expand Up @@ -704,6 +713,50 @@ func (hbpro *HuoBiPro) GetExchangeName() string {
return HUOBI_PRO
}

func (hbpro *HuoBiPro) GetCurrenciesList() ([]string, error) {
url := hbpro.baseUrl + "/v1/common/currencys"

ret, err := HttpGet(hbpro.httpClient, url)
if err != nil {
return nil, err
}

data, ok := ret["data"].([]interface{})
if !ok {
return nil, errors.New("response format error")
}
fmt.Println(data)
return nil, nil
}

func (hbpro *HuoBiPro) GetCurrenciesPrecision() ([]HuoBiProSymbol, error) {
url := hbpro.baseUrl + "/v1/common/symbols"

ret, err := HttpGet(hbpro.httpClient, url)
if err != nil {
return nil, err
}

data, ok := ret["data"].([]interface{})
if !ok {
return nil, errors.New("response format error")
}
var Symbols []HuoBiProSymbol
for _, v := range data {
_sym := v.(map[string]interface{})
var sym HuoBiProSymbol
sym.BaseCurrency = _sym["base-currency"].(string)
sym.QuoteCurrency = _sym["quote-currency"].(string)
sym.PricePrecision = _sym["price-precision"].(float64)
sym.AmountPrecision = _sym["amount-precision"].(float64)
sym.SymbolPartition = _sym["symbol-partition"].(string)
sym.Symbol = _sym["symbol"].(string)
Symbols = append(Symbols, sym)
}
//fmt.Println(Symbols)
return Symbols, nil
}

func (hbpro *HuoBiPro) GetTickerWithWs(pair CurrencyPair, handle func(ticker *Ticker)) error {
hbpro.createWsConn()
sub := fmt.Sprintf("market.%s.detail", strings.ToLower(pair.ToSymbol("")))
Expand Down
12 changes: 11 additions & 1 deletion huobi/HuobiPro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,19 @@ func TestHuobiPro_GetTickerWithWs(t *testing.T) {
}

func TestHuobiPro_GetKLineWithWs(t *testing.T) {
//return
return
hbpro.GetKLineWithWs(goex.BTC_USDT, goex.KLINE_PERIOD_60MIN, func(kline *goex.Kline) {
log.Println("%+v", *kline)
})
time.Sleep(time.Minute)
}

func TestHuobiPro_GetCurrenciesList(t *testing.T) {
return
hbpro.GetCurrenciesList()
}

func TestHuobiPro_GetCurrenciesPrecision(t *testing.T) {
//return
t.Log(hbpro.GetCurrenciesPrecision())
}

0 comments on commit 173fef2

Please sign in to comment.