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"
"strconv"
"time"
@@ -67,9 +66,9 @@ const (
bitfinexActiveCredits = "credits"
bitfinexPlatformStatus = "platform/status"
// stable times in millisecond per request
bitfinexAuthRate = 2750
bitfinexUnauthRate = 2750
// requests per minute
bitfinexAuthRate = 10
bitfinexUnauthRate = 10
// Bitfinex platform status values
// When the platform is marked in maintenance mode bots should stop trading
@@ -86,7 +85,6 @@ type Bitfinex struct {
exchange.Base
WebsocketConn *websocket.Conn
WebsocketSubdChannels map[int]WebsocketChanInfo
*request.Handler
}
// SetDefaults sets the basic defaults for bitfinex
@@ -103,8 +101,8 @@ func (b *Bitfinex) SetDefaults() {
b.ConfigCurrencyPairFormat.Uppercase = true
b.AssetTypes = []string{ticker.Spot}
b.SupportsAutoPairUpdating = true
b.Handler = new(request.Handler)
b.SetRequestHandler(b.Name, bitfinexAuthRate, bitfinexUnauthRate, new(http.Client))
b.SupportsRESTTickerBatching = true
b.Requester = request.New(b.Name, request.NewRateLimit(time.Second*60, bitfinexAuthRate), request.NewRateLimit(time.Second*60, bitfinexUnauthRate), common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
}
// Setup takes in the supplied exchange configuration details and sets params
@@ -115,6 +113,7 @@ func (b *Bitfinex) Setup(exch config.ExchangeConfig) {
b.Enabled = true
b.AuthenticatedAPISupport = exch.AuthenticatedAPISupport
b.SetAPIKeys(exch.APIKey, exch.APISecret, "", false)
b.SetHTTPClientTimeout(exch.HTTPTimeout)
b.RESTPollingDelay = exch.RESTPollingDelay
b.Verbose = exch.Verbose
b.Websocket = exch.Websocket

View File

@@ -34,8 +34,9 @@ func TestSetup(t *testing.T) {
t.Error("Test Failed - Bitfinex Setup values not set correctly")
}
b.AuthenticatedAPISupport = true
// not worried about rate limit on test
b.SetRateLimit(0, 0)
// custom rate limit for testing
b.Requester.SetRateLimit(true, time.Second*30, 3)
b.Requester.SetRateLimit(false, time.Second*30, 3)
}
func TestGetPlatformStatus(t *testing.T) {

View File

@@ -4,6 +4,7 @@ import (
"errors"
"log"
"net/url"
"sync"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency/pair"
@@ -13,8 +14,12 @@ import (
)
// Start starts the Bitfinex go routine
func (b *Bitfinex) Start() {
go b.Run()
func (b *Bitfinex) Start(wg *sync.WaitGroup) {
wg.Add(1)
go func() {
b.Run()
wg.Done()
}()
}
// Run implements the Bitfinex wrapper
@@ -33,9 +38,9 @@ func (b *Bitfinex) Run() {
if err != nil {
log.Printf("%s Failed to get available symbols.\n", b.GetName())
} else {
err = b.UpdateAvailableCurrencies(exchangeProducts, false)
err = b.UpdateCurrencies(exchangeProducts, false, false)
if err != nil {
log.Printf("%s Failed to get config.\n", b.GetName())
log.Printf("%s Failed to update available symbols.\n", b.GetName())
}
}
}

View File

@@ -2,7 +2,7 @@ package bitfinex
// func TestStart(t *testing.T) {
// start := Bitfinex{}
// start.Start()
// start.Start(wg *sync.WaitGroup)
// }
//
// func TestRun(t *testing.T) {