From 046b4dc34827f83cbc0bc5ed04dda4e068ca3a0f Mon Sep 17 00:00:00 2001 From: Adrian Gallagher Date: Thu, 1 Mar 2018 16:05:28 +1100 Subject: [PATCH] Add Bitstamp dynamic currency updater --- exchanges/bitstamp/bitstamp.go | 9 +++++++++ exchanges/bitstamp/bitstamp_test.go | 9 +++++++++ exchanges/bitstamp/bitstamp_types.go | 11 +++++++++++ exchanges/bitstamp/bitstamp_wrapper.go | 19 +++++++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/exchanges/bitstamp/bitstamp.go b/exchanges/bitstamp/bitstamp.go index e391ec53..7328871c 100644 --- a/exchanges/bitstamp/bitstamp.go +++ b/exchanges/bitstamp/bitstamp.go @@ -46,6 +46,7 @@ const ( bitstampAPIXrpWithdrawal = "xrp_withdrawal" bitstampAPIXrpDeposit = "xrp_address" bitstampAPIReturnType = "string" + bitstampAPITradingPairsInfo = "trading-pairs-info" ) // Bitstamp is the overarching type across the bitstamp package @@ -188,6 +189,14 @@ func (b *Bitstamp) GetOrderbook(currency string) (Orderbook, error) { return orderbook, nil } +// GetTradingPairs returns a list of trading pairs which Bitstamp +// currently supports +func (b *Bitstamp) GetTradingPairs() ([]TradingPair, error) { + var result []TradingPair + path := fmt.Sprintf("%s/v%s/%s", bitstampAPIURL, bitstampAPIVersion, bitstampAPITradingPairsInfo) + return result, common.SendHTTPGetRequest(path, true, b.Verbose, &result) +} + // GetTransactions returns transaction information // value paramater ["time"] = "minute", "hour", "day" will collate your // response into time intervals. Implementation of value in test code. diff --git a/exchanges/bitstamp/bitstamp_test.go b/exchanges/bitstamp/bitstamp_test.go index 3eb2ad3d..8911c6d5 100644 --- a/exchanges/bitstamp/bitstamp_test.go +++ b/exchanges/bitstamp/bitstamp_test.go @@ -110,6 +110,15 @@ func TestGetOrderbook(t *testing.T) { } } +func TestGetTradingPairs(t *testing.T) { + t.Parallel() + b := Bitstamp{} + _, err := b.GetTradingPairs() + if err != nil { + t.Error("Test Failed - GetTradingPairs() error", err) + } +} + func TestGetTransactions(t *testing.T) { t.Parallel() b := Bitstamp{} diff --git a/exchanges/bitstamp/bitstamp_types.go b/exchanges/bitstamp/bitstamp_types.go index d029b62f..af376d78 100644 --- a/exchanges/bitstamp/bitstamp_types.go +++ b/exchanges/bitstamp/bitstamp_types.go @@ -26,6 +26,17 @@ type Orderbook struct { Asks []OrderbookBase } +// TradingPair holds trading pair information +type TradingPair struct { + Name string `json:"name"` + URLSymbol string `json:"url_symbol"` + BaseDecimals int `json:"base_decimals"` + CounterDecimals int `json:"counter_decimals"` + MinimumOrder string `json:"minimum_order"` + Trading string `json:"trading"` + Description string `json:"description"` +} + // Transactions holds transaction data type Transactions struct { Date int64 `json:"date,string"` diff --git a/exchanges/bitstamp/bitstamp_wrapper.go b/exchanges/bitstamp/bitstamp_wrapper.go index 4798226d..66178326 100644 --- a/exchanges/bitstamp/bitstamp_wrapper.go +++ b/exchanges/bitstamp/bitstamp_wrapper.go @@ -3,6 +3,7 @@ package bitstamp import ( "errors" "log" + "strings" "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/currency/pair" @@ -27,6 +28,24 @@ func (b *Bitstamp) Run() { if b.Websocket { go b.PusherClient() } + + pairs, err := b.GetTradingPairs() + if err != nil { + log.Printf("%s failed to get trading pairs. Err: %s", b.Name, err) + } else { + var currencies []string + for x := range pairs { + if pairs[x].Trading != "Enabled" { + continue + } + pair := strings.Split(pairs[x].Name, "/") + currencies = append(currencies, pair[0]+pair[1]) + } + err = b.UpdateAvailableCurrencies(currencies, false) + if err != nil { + log.Printf("%s Failed to update available currencies.\n", b.Name) + } + } } // UpdateTicker updates and returns the ticker for a currency pair