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

@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"log"
"net/http"
"net/url"
"strconv"
"time"
@@ -24,7 +23,6 @@ type Binance struct {
// valid string list that a required by the exchange
validLimits []string
validIntervals []string
*request.Handler
}
const (
@@ -47,8 +45,9 @@ const (
queryOrder = "/api/v3/order"
// binance authenticated and unauthenticated limit rates
binanceAuthRate = 1000
binanceUnauthRate = 1000
// to-do
binanceAuthRate = 0
binanceUnauthRate = 0
)
// SetDefaults sets the basic defaults for Binance
@@ -64,9 +63,9 @@ func (b *Binance) SetDefaults() {
b.ConfigCurrencyPairFormat.Uppercase = true
b.AssetTypes = []string{ticker.Spot}
b.SupportsAutoPairUpdating = true
b.SupportsRESTTickerBatching = true
b.SetValues()
b.Handler = new(request.Handler)
b.SetRequestHandler(b.Name, binanceAuthRate, binanceUnauthRate, new(http.Client))
b.Requester = request.New(b.Name, request.NewRateLimit(time.Second, binanceAuthRate), request.NewRateLimit(time.Second, binanceUnauthRate), common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
}
// Setup takes in the supplied exchange configuration details and sets params
@@ -77,6 +76,7 @@ func (b *Binance) 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

@@ -3,6 +3,7 @@ package binance
import (
"errors"
"log"
"sync"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency/pair"
@@ -12,8 +13,12 @@ import (
)
// Start starts the OKEX go routine
func (b *Binance) Start() {
go b.Run()
func (b *Binance) Start(wg *sync.WaitGroup) {
wg.Add(1)
go func() {
b.Run()
wg.Done()
}()
}
// Run implements the OKEX wrapper
@@ -37,12 +42,12 @@ func (b *Binance) Run() {
enabledPairs := []string{"BTC-USDT"}
log.Println("WARNING: Available pairs for Binance reset due to config upgrade, please enable the ones you would like again")
err = b.UpdateEnabledCurrencies(enabledPairs, true)
err = b.UpdateCurrencies(enabledPairs, true, true)
if err != nil {
log.Printf("%s Failed to get config.\n", b.GetName())
}
}
err = b.UpdateAvailableCurrencies(symbols, forceUpgrade)
err = b.UpdateCurrencies(symbols, false, forceUpgrade)
if err != nil {
log.Printf("%s Failed to get config.\n", b.GetName())
}