mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-24 23:16:52 +00:00
Improve Bithumb API error handling
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user