mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-05 15:10:59 +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:
@@ -2,6 +2,7 @@ package orderbook
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
@@ -19,6 +20,7 @@ const (
|
||||
// Vars for the orderbook package
|
||||
var (
|
||||
Orderbooks []Orderbook
|
||||
m sync.Mutex
|
||||
)
|
||||
|
||||
// Item stores the amount and price values
|
||||
@@ -94,6 +96,8 @@ func GetOrderbook(exchange string, p pair.CurrencyPair, orderbookType string) (B
|
||||
|
||||
// GetOrderbookByExchange returns an exchange orderbook
|
||||
func GetOrderbookByExchange(exchange string) (*Orderbook, error) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
for _, y := range Orderbooks {
|
||||
if y.ExchangeName == exchange {
|
||||
return &y, nil
|
||||
@@ -105,6 +109,8 @@ func GetOrderbookByExchange(exchange string) (*Orderbook, error) {
|
||||
// FirstCurrencyExists checks to see if the first currency of the orderbook map
|
||||
// exists
|
||||
func FirstCurrencyExists(exchange string, currency pair.CurrencyItem) bool {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
for _, y := range Orderbooks {
|
||||
if y.ExchangeName == exchange {
|
||||
if _, ok := y.Orderbook[currency]; ok {
|
||||
@@ -118,6 +124,8 @@ func FirstCurrencyExists(exchange string, currency pair.CurrencyItem) bool {
|
||||
// SecondCurrencyExists checks to see if the second currency of the orderbook
|
||||
// map exists
|
||||
func SecondCurrencyExists(exchange string, p pair.CurrencyPair) bool {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
for _, y := range Orderbooks {
|
||||
if y.ExchangeName == exchange {
|
||||
if _, ok := y.Orderbook[p.GetFirstCurrency()]; ok {
|
||||
@@ -132,6 +140,8 @@ func SecondCurrencyExists(exchange string, p pair.CurrencyPair) bool {
|
||||
|
||||
// CreateNewOrderbook creates a new orderbook
|
||||
func CreateNewOrderbook(exchangeName string, p pair.CurrencyPair, orderbookNew Base, orderbookType string) Orderbook {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
orderbook := Orderbook{}
|
||||
orderbook.ExchangeName = exchangeName
|
||||
orderbook.Orderbook = make(map[pair.CurrencyItem]map[pair.CurrencyItem]map[string]Base)
|
||||
@@ -163,18 +173,22 @@ func ProcessOrderbook(exchangeName string, p pair.CurrencyPair, orderbookNew Bas
|
||||
|
||||
if FirstCurrencyExists(exchangeName, p.GetFirstCurrency()) {
|
||||
if !SecondCurrencyExists(exchangeName, p) {
|
||||
m.Lock()
|
||||
a := orderbook.Orderbook[p.FirstCurrency]
|
||||
b := make(map[string]Base)
|
||||
b[orderbookType] = orderbookNew
|
||||
a[p.SecondCurrency] = b
|
||||
orderbook.Orderbook[p.FirstCurrency] = a
|
||||
m.Unlock()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
a := make(map[pair.CurrencyItem]map[string]Base)
|
||||
b := make(map[string]Base)
|
||||
b[orderbookType] = orderbookNew
|
||||
a[p.SecondCurrency] = b
|
||||
orderbook.Orderbook[p.FirstCurrency] = a
|
||||
m.Unlock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user