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,10 +4,10 @@ import (
"errors"
"fmt"
"log"
"net/http"
"net/url"
"strconv"
"strings"
"time"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
@@ -42,8 +42,8 @@ const (
geminiHeartbeat = "heartbeat"
// gemini limit rates
geminiAuthRate = 100
geminiUnauthRate = 500
geminiAuthRate = 600
geminiUnauthRate = 120
// Too many requests returns this
geminiRateError = "429"
@@ -55,8 +55,7 @@ const (
var (
// Session manager
Session map[int]*Gemini
gHandler *request.Handler
Session map[int]*Gemini
)
// Gemini is the overarching type across the Gemini package, create multiple
@@ -68,7 +67,6 @@ type Gemini struct {
exchange.Base
Role string
RequiresHeartBeat bool
*request.Handler
}
// AddSession adds a new session to the gemini base
@@ -76,9 +74,6 @@ func AddSession(g *Gemini, sessionID int, apiKey, apiSecret, role string, needsH
if Session == nil {
Session = make(map[int]*Gemini)
}
if gHandler == nil {
gHandler = new(request.Handler)
}
_, ok := Session[sessionID]
if ok {
@@ -113,14 +108,8 @@ func (g *Gemini) SetDefaults() {
g.ConfigCurrencyPairFormat.Uppercase = true
g.AssetTypes = []string{ticker.Spot}
g.SupportsAutoPairUpdating = true
if gHandler != nil {
g.Handler = gHandler
} else {
g.Handler = new(request.Handler)
}
if g.Handler.Client == nil {
g.SetRequestHandler(g.Name, geminiAuthRate, geminiUnauthRate, new(http.Client))
}
g.SupportsRESTTickerBatching = false
g.Requester = request.New(g.Name, request.NewRateLimit(time.Minute, geminiAuthRate), request.NewRateLimit(time.Minute, geminiUnauthRate), common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
}
// Setup sets exchange configuration parameters
@@ -131,6 +120,7 @@ func (g *Gemini) Setup(exch config.ExchangeConfig) {
g.Enabled = true
g.AuthenticatedAPISupport = exch.AuthenticatedAPISupport
g.SetAPIKeys(exch.APIKey, exch.APISecret, "", false)
g.SetHTTPClientTimeout(exch.HTTPTimeout)
g.RESTPollingDelay = exch.RESTPollingDelay
g.Verbose = exch.Verbose
g.Websocket = exch.Websocket

View File

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