From 4acbd5f865c06a7670bdb6e6d4c2b48a54ddc7d6 Mon Sep 17 00:00:00 2001 From: solipsis Date: Fri, 12 Jan 2018 15:08:15 -0700 Subject: [PATCH 1/5] Update coin list --- shapeshift_coins.go | 118 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 104 insertions(+), 14 deletions(-) diff --git a/shapeshift_coins.go b/shapeshift_coins.go index 04ef9fb..630f461 100644 --- a/shapeshift_coins.go +++ b/shapeshift_coins.go @@ -14,51 +14,96 @@ type Coin struct { } type CoinsResponse struct { - BTC struct { + FIRST struct { Coin - } `json:"BTC"` + } `json:"1ST"` + ANT struct { + Coin + } `json:"ANT"` + BAT struct { + Coin + } `json:"BAT"` + BCH struct { + Coin + } `json:"BCH"` BCY struct { Coin } `json:"BCY"` BLK struct { Coin } `json:"BLK"` + BNT struct { + Coin + } `json:"BNT"` + BTC struct { + Coin + } `json:"BTC"` BTCD struct { Coin } `json:"BTCD"` + BTG struct { + Coin + } `json:"BTG"` BTS struct { Coin } `json:"BTS"` CLAM struct { Coin } `json:"CLAM"` + CVC struct { + Coin + } `json:"CVC"` DASH struct { Coin } `json:"DASH"` + DCR struct { + Coin + } `json:"DCR"` DGB struct { Coin } `json:"DGB"` - DGD struct { + DNT struct { Coin - } `json:"DGD"` + } `json:"DNT"` DOGE struct { Coin } `json:"DOGE"` + EDG struct { + Coin + } `json:"EDG"` EMC struct { Coin } `json:"EMC"` - ETH struct { + EOS struct { Coin - } `json:"ETH"` + } `json:"EOS"` ETC struct { Coin } `json:"ETC"` + ETH struct { + Coin + } `json:"ETH"` FCT struct { Coin } `json:"FCT"` + FUN struct { + Coin + } `json:"FUN"` + GAME struct { + Coin + } `json:"GAME"` + GNO struct { + Coin + } `json:"GNO"` GNT struct { Coin } `json:"GNT"` + GUP struct { + Coin + } `json:"GUP"` + KMD struct { + Coin + } `json:"KMD"` LBC struct { Coin } `json:"LBC"` @@ -71,54 +116,87 @@ type CoinsResponse struct { MAID struct { Coin } `json:"MAID"` + MLN struct { + Coin + } `json:"MLN"` MONA struct { Coin } `json:"MONA"` MSC struct { Coin } `json:"MSC"` + MTL struct { + Coin + } `json:"MTL"` NBT struct { Coin } `json:"NBT"` + NEO struct { + Coin + } `json:"NEO"` NMC struct { Coin } `json:"NMC"` + NMR struct { + Coin + } `json:"NMR"` NVC struct { Coin } `json:"NVC"` NXT struct { Coin } `json:"NXT"` + OMG struct { + Coin + } `json:"OMG"` POT struct { Coin } `json:"POT"` PPC struct { Coin } `json:"PPC"` - REP struct { + QTUM struct { Coin - } `json:"REP"` + } `json:"QTUM"` + RCN struct { + Coin + } `json:"RCN"` RDD struct { Coin } `json:"RDD"` - SDC struct { + REP struct { + Coin + } `json:"REP"` + RLC struct { + Coin + } `json:"RLC"` + SALT struct { Coin - } `json:"SDC"` + } `json:"SALT"` SC struct { Coin } `json:"SC"` - SJCX struct { + SNGLS struct { + Coin + } `json:"SNGLS"` + SNT struct { Coin - } `json:"SJCX"` + } `json:"SNT"` START struct { Coin } `json:"START"` STEEM struct { Coin } `json:"STEEM"` - SNGLS struct { + STORJ struct { Coin - } `json:"SNGLS"` + } `json:"STORJ"` + SWT struct { + Coin + } `json:"SWT"` + TRST struct { + Coin + } `json:"TRST"` USDT struct { Coin } `json:"USDT"` @@ -131,9 +209,18 @@ type CoinsResponse struct { VTC struct { Coin } `json:"VTC"` + WAVES struct { + Coin + } `json:"WAVES"` + WINGS struct { + Coin + } `json:"WINGS"` XCP struct { Coin } `json:"XCP"` + XEM struct { + Coin + } `json:"XEM"` XMR struct { Coin } `json:"XMR"` @@ -143,4 +230,7 @@ type CoinsResponse struct { ZEC struct { Coin } `json:"ZEC"` + ZRX struct { + Coin + } `json:"ZRX"` } From 98991ea64bbe83f31538674a8a288a17eb803155 Mon Sep 17 00:00:00 2001 From: solipsis Date: Wed, 17 Jan 2018 12:29:53 -0700 Subject: [PATCH 2/5] method for fetching the coins as a list --- shapeshift.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/shapeshift.go b/shapeshift.go index c522d25..d67531b 100644 --- a/shapeshift.go +++ b/shapeshift.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "io/ioutil" + "log" "net/http" "strconv" ) @@ -244,6 +245,32 @@ func TimeRemaining(addr string) (*TimeRemainingResponse, error) { return &g, err } +func CoinsAsList() ([]Coin, error) { + var coins []Coin + r, err := DoHttp("GET", "getcoins", "") + if err != nil { + return nil, err + } + + // User json.RawMessage to delay marshalling to support arbitrary top level keys + var coinmap map[string]*json.RawMessage + if err := json.Unmarshal(r, &coinmap); err != nil { + return coins, err + } + + for _, coinJSON := range coinmap { + var c Coin + err := json.Unmarshal([]byte(*coinJSON), &c) + if err != nil { + log.Println("Error unmarshalling coin:", err) + continue + } + coins = append(coins, c) + } + + return coins, nil +} + func Coins() (*CoinsResponse, error) { r, err := DoHttp("GET", "getcoins", "") if err != nil { From 786d2b5e89d996f6ae74db7487c8d79247fb2191 Mon Sep 17 00:00:00 2001 From: solipsis Date: Wed, 17 Jan 2018 12:45:17 -0700 Subject: [PATCH 3/5] simple tests for CoinsAsList endpoint --- shapeshift_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/shapeshift_test.go b/shapeshift_test.go index e6a819d..3342776 100644 --- a/shapeshift_test.go +++ b/shapeshift_test.go @@ -132,6 +132,18 @@ func TestDepositStatus(t *testing.T) { } +func TestGetCoinsAsList(t *testing.T) { + + coins, err := CoinsAsList() + if err != nil || len(coins) == 0 { + t.Fail() + } + + t.Log("Coin: ", coins[0].Name) + t.Log("Status: ", coins[0].Status) + +} + func TestGetSupportedCoins(t *testing.T) { coins, err := Coins() From 5719d7a3cf9d2e96c9f4854e77b8e094970abd2f Mon Sep 17 00:00:00 2001 From: solipsis Date: Wed, 17 Jan 2018 12:45:17 -0700 Subject: [PATCH 4/5] simple tests for CoinsAsList endpoint --- shapeshift.go | 2 +- shapeshift_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/shapeshift.go b/shapeshift.go index d67531b..65e9739 100644 --- a/shapeshift.go +++ b/shapeshift.go @@ -252,7 +252,7 @@ func CoinsAsList() ([]Coin, error) { return nil, err } - // User json.RawMessage to delay marshalling to support arbitrary top level keys + // Use json.RawMessage to delay marshalling to support arbitrary top level keys var coinmap map[string]*json.RawMessage if err := json.Unmarshal(r, &coinmap); err != nil { return coins, err diff --git a/shapeshift_test.go b/shapeshift_test.go index e6a819d..3342776 100644 --- a/shapeshift_test.go +++ b/shapeshift_test.go @@ -132,6 +132,18 @@ func TestDepositStatus(t *testing.T) { } +func TestGetCoinsAsList(t *testing.T) { + + coins, err := CoinsAsList() + if err != nil || len(coins) == 0 { + t.Fail() + } + + t.Log("Coin: ", coins[0].Name) + t.Log("Status: ", coins[0].Status) + +} + func TestGetSupportedCoins(t *testing.T) { coins, err := Coins() From 24207d0677d34ba2232488cb123b6b4fe4ff0117 Mon Sep 17 00:00:00 2001 From: solipsis Date: Mon, 20 Aug 2018 19:59:13 -0600 Subject: [PATCH 5/5] various tweaks to make team-jacob happier --- shapeshift.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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"))