diff --git a/shapeshift.go b/shapeshift.go index 65e9739..87fd51f 100644 --- a/shapeshift.go +++ b/shapeshift.go @@ -3,8 +3,8 @@ package shapeshift import ( "bytes" "encoding/json" + "errors" "io/ioutil" - "log" "net/http" "strconv" ) @@ -40,7 +40,7 @@ type LimitResponse struct { type MarketInfoResponse struct { Pair string `json:"pair,omitempty"` - Rate float64 `json:"rate,omitempty"` + Rate float64 `json:"rate,string,omitempty"` Limit float64 `json:"limit,omitempty"` Min float64 `json:"min,omitempty"` MinerFee float64 `json:"minerFee,omitempty"` @@ -205,6 +205,16 @@ func (p Pair) GetLimits() (float64, error) { return ToFloat(g.Limit), err } +func MarketInfo() ([]MarketInfoResponse, error) { + r, err := DoHttp("GET", "marketinfo", "") + if err != nil { + return nil, err + } + var arr []MarketInfoResponse + err = json.Unmarshal(r, &arr) + return arr, err +} + func (p Pair) GetInfo() (*MarketInfoResponse, error) { r, err := DoHttp("GET", "marketinfo", p.Name) if err != nil { @@ -262,7 +272,7 @@ func CoinsAsList() ([]Coin, error) { var c Coin err := json.Unmarshal([]byte(*coinJSON), &c) if err != nil { - log.Println("Error unmarshalling coin:", err) + //log.Println("Error unmarshalling coin:", err) continue } coins = append(coins, c) @@ -359,6 +369,9 @@ func DoPostHttp(method string, apimethod string, data interface{}) ([]byte, erro if err != nil { return nil, err } + if resp.StatusCode != 200 { + return nil, errors.New("There was an error creating your order, Please try again later") + } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) body = bytes.TrimPrefix(body, []byte("\xef\xbb\xbf"))