New features and bug fixes

- Modifications made to the request package. Planned improvements will be
sending requests on intervals, rate limiter back off support, dynamic tuning
and requests packaged into a request job group.
- Can modify each exchanges individual HTTP client (e.g timeout and
transport settings).
- Bot now uses an exchange config HTTP timeout value.
- Bot now uses a global HTTP timeout (configurable).
- Batched ticker request support for exchanges.
- Ticker and Orderbook fetching now are spanned accross multiple
go routines and regulated by a sync wait group.
- Fixes hack used to load exchanges, now uses a sync wait group.
- Ticker and Orderbook storage and fetching now uses mutex locks.
- New pair function for finding different pairs between two supplied
 pair arrays. This is used for currency pair updates for exchange which
support dynamic updating.
- Shows removal/additions of dynamic updates currencies.
This commit is contained in:
Adrian Gallagher
2018-05-04 13:20:19 +10:00
parent 8eef67339d
commit ac41a7cfad
73 changed files with 1327 additions and 742 deletions

View File

@@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"log"
"net/http"
"net/url"
"reflect"
"strconv"
@@ -50,15 +49,14 @@ const (
bitstampAPIReturnType = "string"
bitstampAPITradingPairsInfo = "trading-pairs-info"
bitstampAuthRate = 0
bitstampUnauthRate = 0
bitstampAuthRate = 600
bitstampUnauthRate = 600
)
// Bitstamp is the overarching type across the bitstamp package
type Bitstamp struct {
exchange.Base
Balance Balances
*request.Handler
}
// SetDefaults sets default for Bitstamp
@@ -74,8 +72,8 @@ func (b *Bitstamp) SetDefaults() {
b.ConfigCurrencyPairFormat.Uppercase = true
b.AssetTypes = []string{ticker.Spot}
b.SupportsAutoPairUpdating = true
b.Handler = new(request.Handler)
b.SetRequestHandler(b.Name, bitstampAuthRate, bitstampUnauthRate, new(http.Client))
b.SupportsRESTTickerBatching = false
b.Requester = request.New(b.Name, request.NewRateLimit(time.Minute*10, bitstampAuthRate), request.NewRateLimit(time.Minute*10, bitstampUnauthRate), common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
}
// Setup sets configuration values to bitstamp
@@ -86,6 +84,7 @@ func (b *Bitstamp) Setup(exch config.ExchangeConfig) {
b.Enabled = true
b.AuthenticatedAPISupport = exch.AuthenticatedAPISupport
b.SetAPIKeys(exch.APIKey, exch.APISecret, exch.ClientID, false)
b.SetHTTPClientTimeout(exch.HTTPTimeout)
b.RESTPollingDelay = exch.RESTPollingDelay
b.Verbose = exch.Verbose
b.Websocket = exch.Websocket
@@ -207,7 +206,7 @@ func (b *Bitstamp) GetOrderbook(currency string) (Orderbook, error) {
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)
return result, b.SendHTTPRequest(path, &result)
}
// GetTransactions returns transaction information

View File

@@ -85,7 +85,6 @@ 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)

View File

@@ -4,6 +4,7 @@ import (
"errors"
"log"
"strings"
"sync"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency/pair"
@@ -13,8 +14,12 @@ import (
)
// Start starts the Bitstamp go routine
func (b *Bitstamp) Start() {
go b.Run()
func (b *Bitstamp) Start(wg *sync.WaitGroup) {
wg.Add(1)
go func() {
b.Run()
wg.Done()
}()
}
// Run implements the Bitstamp wrapper
@@ -41,7 +46,7 @@ func (b *Bitstamp) Run() {
pair := strings.Split(pairs[x].Name, "/")
currencies = append(currencies, pair[0]+pair[1])
}
err = b.UpdateAvailableCurrencies(currencies, false)
err = b.UpdateCurrencies(currencies, false, false)
if err != nil {
log.Printf("%s Failed to update available currencies.\n", b.Name)
}