mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-01 07:26:48 +00:00
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:
@@ -3,6 +3,7 @@ package ticker
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
@@ -20,6 +21,7 @@ const (
|
||||
// Vars for the ticker package
|
||||
var (
|
||||
Tickers []Ticker
|
||||
m sync.Mutex
|
||||
)
|
||||
|
||||
// Price struct stores the currency pair and pricing information
|
||||
@@ -85,6 +87,8 @@ func GetTicker(exchange string, p pair.CurrencyPair, tickerType string) (Price,
|
||||
|
||||
// GetTickerByExchange returns an exchange Ticker
|
||||
func GetTickerByExchange(exchange string) (*Ticker, error) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
for _, y := range Tickers {
|
||||
if y.ExchangeName == exchange {
|
||||
return &y, nil
|
||||
@@ -96,6 +100,8 @@ func GetTickerByExchange(exchange string) (*Ticker, error) {
|
||||
// FirstCurrencyExists checks to see if the first currency of the Price map
|
||||
// exists
|
||||
func FirstCurrencyExists(exchange string, currency pair.CurrencyItem) bool {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
for _, y := range Tickers {
|
||||
if y.ExchangeName == exchange {
|
||||
if _, ok := y.Price[currency]; ok {
|
||||
@@ -109,6 +115,8 @@ func FirstCurrencyExists(exchange string, currency pair.CurrencyItem) bool {
|
||||
// SecondCurrencyExists checks to see if the second currency of the Price map
|
||||
// exists
|
||||
func SecondCurrencyExists(exchange string, p pair.CurrencyPair) bool {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
for _, y := range Tickers {
|
||||
if y.ExchangeName == exchange {
|
||||
if _, ok := y.Price[p.GetFirstCurrency()]; ok {
|
||||
@@ -123,6 +131,8 @@ func SecondCurrencyExists(exchange string, p pair.CurrencyPair) bool {
|
||||
|
||||
// CreateNewTicker creates a new Ticker
|
||||
func CreateNewTicker(exchangeName string, p pair.CurrencyPair, tickerNew Price, tickerType string) Ticker {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
ticker := Ticker{}
|
||||
ticker.ExchangeName = exchangeName
|
||||
ticker.Price = make(map[pair.CurrencyItem]map[pair.CurrencyItem]map[string]Price)
|
||||
@@ -152,18 +162,22 @@ func ProcessTicker(exchangeName string, p pair.CurrencyPair, tickerNew Price, ti
|
||||
|
||||
if FirstCurrencyExists(exchangeName, p.FirstCurrency) {
|
||||
if !SecondCurrencyExists(exchangeName, p) {
|
||||
m.Lock()
|
||||
a := ticker.Price[p.FirstCurrency]
|
||||
b := make(map[string]Price)
|
||||
b[tickerType] = tickerNew
|
||||
a[p.SecondCurrency] = b
|
||||
ticker.Price[p.FirstCurrency] = a
|
||||
m.Unlock()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
a := make(map[pair.CurrencyItem]map[string]Price)
|
||||
b := make(map[string]Price)
|
||||
b[tickerType] = tickerNew
|
||||
a[p.SecondCurrency] = b
|
||||
ticker.Price[p.FirstCurrency] = a
|
||||
m.Unlock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user