From 4f8e74f6dc01e07b25bc35e3753a841462ab949b Mon Sep 17 00:00:00 2001 From: Adrian Gallagher Date: Thu, 12 Jul 2018 12:18:45 +1000 Subject: [PATCH] Improve Bithumb API error handling --- exchanges/bithumb/bithumb.go | 38 +++++++++++++++++++++++++++--- exchanges/bithumb/bithumb_types.go | 1 + 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/exchanges/bithumb/bithumb.go b/exchanges/bithumb/bithumb.go index 00eed06a..0d0a3f59 100644 --- a/exchanges/bithumb/bithumb.go +++ b/exchanges/bithumb/bithumb.go @@ -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 diff --git a/exchanges/bithumb/bithumb_types.go b/exchanges/bithumb/bithumb_types.go index b82caf33..8fa68432 100644 --- a/exchanges/bithumb/bithumb_types.go +++ b/exchanges/bithumb/bithumb_types.go @@ -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"` }