diff --git a/exchanges/bithumb/bithumb.go b/exchanges/bithumb/bithumb.go index 31dd7c24..cd6f0961 100644 --- a/exchanges/bithumb/bithumb.go +++ b/exchanges/bithumb/bithumb.go @@ -9,6 +9,7 @@ import ( "net/url" "reflect" "strconv" + "strings" "time" "github.com/thrasher-corp/gocryptotrader/common" @@ -143,29 +144,27 @@ func (b *Bithumb) GetTradablePairs() ([]string, error) { // // symbol e.g. "btc" func (b *Bithumb) GetTicker(symbol string) (Ticker, error) { - response := Ticker{} - path := fmt.Sprintf("%s%s%s", b.APIUrl, publicTicker, common.StringToUpper(symbol)) + var response TickerResponse + path := fmt.Sprintf("%s%s%s", + b.APIUrl, + publicTicker, + strings.ToUpper(symbol)) err := b.SendHTTPRequest(path, &response) if err != nil { - return response, err + return response.Data, err } if response.Status != noError { - return response, errors.New(response.Message) + return response.Data, errors.New(response.Message) } - return response, nil + return response.Data, nil } // GetAllTickers returns all ticker information func (b *Bithumb) GetAllTickers() (map[string]Ticker, error) { - type Response struct { - ActionStatus - Data map[string]interface{} - } - - response := Response{} + var response TickersResponse path := fmt.Sprintf("%s%s%s", b.APIUrl, publicTicker, "all") err := b.SendHTTPRequest(path, &response) @@ -182,25 +181,12 @@ func (b *Bithumb) GetAllTickers() (map[string]Ticker, error) { if k == "date" { continue } - - if reflect.TypeOf(v).String() != "map[string]interface {}" { - continue + var newTicker Ticker + err := common.JSONDecode(v, &newTicker) + if err != nil { + return nil, err } - - data := v.(map[string]interface{}) - var t Ticker - t.AveragePrice, _ = strconv.ParseFloat(data["average_price"].(string), 64) - t.BuyPrice, _ = strconv.ParseFloat(data["buy_price"].(string), 64) - t.ClosingPrice, _ = strconv.ParseFloat(data["closing_price"].(string), 64) - t.MaxPrice, _ = strconv.ParseFloat(data["max_price"].(string), 64) - t.MinPrice, _ = strconv.ParseFloat(data["min_price"].(string), 64) - t.OpeningPrice, _ = strconv.ParseFloat(data["opening_price"].(string), 64) - t.SellPrice, _ = strconv.ParseFloat(data["sell_price"].(string), 64) - t.UnitsTraded, _ = strconv.ParseFloat(data["units_traded"].(string), 64) - t.Volume1Day, _ = strconv.ParseFloat(data["volume_1day"].(string), 64) - t.Volume7Day, _ = strconv.ParseFloat(data["volume_7day"].(string), 64) - result[k] = t - + result[k] = newTicker } return result, nil } @@ -596,7 +582,7 @@ func (b *Bithumb) SendAuthenticatedHTTPRequest(path string, params url.Values, r err = common.JSONDecode(intermediary, &errCapture) if err == nil { - if errCapture.Status != "" && errCapture.Status != "0000" { + if errCapture.Status != "" && errCapture.Status != noError { return fmt.Errorf("sendAuthenticatedAPIRequest error code: %s message:%s", errCapture.Status, errCode[errCapture.Status]) diff --git a/exchanges/bithumb/bithumb_types.go b/exchanges/bithumb/bithumb_types.go index 547829e2..c483c333 100644 --- a/exchanges/bithumb/bithumb_types.go +++ b/exchanges/bithumb/bithumb_types.go @@ -1,21 +1,25 @@ package bithumb -import "github.com/thrasher-corp/gocryptotrader/currency" +import ( + "encoding/json" + + "github.com/thrasher-corp/gocryptotrader/currency" +) // Ticker holds ticker data type Ticker struct { - OpeningPrice float64 `json:"opening_price,string"` - ClosingPrice float64 `json:"closing_price,string"` - MinPrice float64 `json:"min_price,string"` - MaxPrice float64 `json:"max_price,string"` - AveragePrice float64 `json:"average_price,string"` - UnitsTraded float64 `json:"units_traded,string"` - Volume1Day float64 `json:"volume_1day,string"` - Volume7Day float64 `json:"volume_7day,string"` - BuyPrice float64 `json:"buy_price,string"` - SellPrice float64 `json:"sell_price,string"` - ActionStatus - // Date int64 `json:"date,string"` + OpeningPrice float64 `json:"opening_price,string"` + ClosingPrice float64 `json:"closing_price,string"` + MinPrice float64 `json:"min_price,string"` + MaxPrice float64 `json:"max_price,string"` + UnitsTraded float64 `json:"units_traded,string"` + AccumulatedTradeValue float64 `json:"acc_trade_value,string"` + PreviousClosingPrice float64 `json:"prev_closing_price,string"` + UnitsTraded24Hr float64 `json:"units_traded_24H,string"` + AccumulatedTradeValue24hr float64 `json:"acc_trade_value_24H,string"` + Fluctate24Hr string `json:"fluctate_24H"` + FluctateRate24hr float64 `json:"fluctate_rate_24H,string"` + Date int64 `json:"date,string"` } // TickerResponse holds the standard ticker response @@ -27,9 +31,9 @@ type TickerResponse struct { // TickersResponse holds the standard ticker response type TickersResponse struct { - Status string `json:"status"` - Data map[string]Ticker `json:"data"` - Message string `json:"message"` + Status string `json:"status"` + Data map[string]json.RawMessage `json:"data"` + Message string `json:"message"` } // Orderbook holds full range of order book information diff --git a/exchanges/bithumb/bithumb_wrapper.go b/exchanges/bithumb/bithumb_wrapper.go index 3d4cfe49..a1ffc127 100644 --- a/exchanges/bithumb/bithumb_wrapper.go +++ b/exchanges/bithumb/bithumb_wrapper.go @@ -78,11 +78,9 @@ func (b *Bithumb) UpdateTicker(p currency.Pair, assetType string) (ticker.Price, currency := x.Base.String() var tp ticker.Price tp.Pair = x - tp.Ask = tickers[currency].SellPrice - tp.Bid = tickers[currency].BuyPrice tp.Low = tickers[currency].MinPrice tp.Last = tickers[currency].ClosingPrice - tp.Volume = tickers[currency].Volume1Day + tp.Volume = tickers[currency].UnitsTraded24Hr tp.High = tickers[currency].MaxPrice err = ticker.ProcessTicker(b.Name, &tp, assetType)