Improve Bithumb API error handling

This commit is contained in:
Adrian Gallagher
2018-07-12 12:18:45 +10:00
parent ed675bde30
commit 4f8e74f6dc
2 changed files with 36 additions and 3 deletions

View File

@@ -124,12 +124,22 @@ func (b *Bithumb) GetTicker(symbol string) (Ticker, error) {
response := Ticker{}
path := fmt.Sprintf("%s%s%s", apiURL, publicTicker, common.StringToUpper(symbol))
return response, b.SendHTTPRequest(path, &response)
err := b.SendHTTPRequest(path, &response)
if err != nil {
return response, err
}
if response.Status != noError {
return response, errors.New(response.Message)
}
return response, nil
}
// GetAllTickers returns all ticker information
func (b *Bithumb) GetAllTickers() (map[string]Ticker, error) {
type Response struct {
ActionStatus
Data map[string]interface{}
}
@@ -141,6 +151,10 @@ func (b *Bithumb) GetAllTickers() (map[string]Ticker, error) {
return nil, err
}
if response.Status != noError {
return nil, errors.New(response.Message)
}
result := make(map[string]Ticker)
for k, v := range response.Data {
if k == "date" {
@@ -172,7 +186,16 @@ func (b *Bithumb) GetOrderBook(symbol string) (Orderbook, error) {
response := Orderbook{}
path := fmt.Sprintf("%s%s%s", apiURL, publicOrderBook, common.StringToUpper(symbol))
return response, b.SendHTTPRequest(path, &response)
err := b.SendHTTPRequest(path, &response)
if err != nil {
return response, err
}
if response.Status != noError {
return response, errors.New(response.Message)
}
return response, nil
}
// GetRecentTransactions returns recent transactions
@@ -182,7 +205,16 @@ func (b *Bithumb) GetRecentTransactions(symbol string) (RecentTransactions, erro
response := RecentTransactions{}
path := fmt.Sprintf("%s%s%s", apiURL, publicRecentTransaction, common.StringToUpper(symbol))
return response, b.SendHTTPRequest(path, &response)
err := b.SendHTTPRequest(path, &response)
if err != nil {
return response, err
}
if response.Status != noError {
return response, errors.New(response.Message)
}
return response, nil
}
// GetAccountInfo returns account information

View File

@@ -12,6 +12,7 @@ type Ticker struct {
Volume7Day float64 `json:"volume_7day,string"`
BuyPrice float64 `json:"buy_price,string"`
SellPrice float64 `json:"sell_price,string"`
ActionStatus
// Date int64 `json:"date,string"`
}