mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 23:16:53 +00:00
ProcessOrderbook: added a condition to check for existing orderbooks (#197)
* ProcessOrderbook: added a condition to check for existing orderbooks * ProcessOrderbook: simplified the logic by removing useless code * Covered orderbook read/write stability with tests * Fixes race condition writing to a test array
This commit is contained in:
committed by
Adrian Gallagher
parent
4a879bf1a1
commit
640a7e6a83
@@ -166,11 +166,6 @@ func ProcessOrderbook(exchangeName string, p pair.CurrencyPair, orderbookNew Bas
|
||||
orderbookNew.CurrencyPair = p.Pair().String()
|
||||
orderbookNew.LastUpdated = time.Now()
|
||||
|
||||
if len(Orderbooks) == 0 {
|
||||
CreateNewOrderbook(exchangeName, p, orderbookNew, orderbookType)
|
||||
return
|
||||
}
|
||||
|
||||
orderbook, err := GetOrderbookByExchange(exchangeName)
|
||||
if err != nil {
|
||||
CreateNewOrderbook(exchangeName, p, orderbookNew, orderbookType)
|
||||
@@ -178,16 +173,12 @@ func ProcessOrderbook(exchangeName string, p pair.CurrencyPair, orderbookNew Bas
|
||||
}
|
||||
|
||||
if FirstCurrencyExists(exchangeName, p.FirstCurrency) {
|
||||
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[string]Base)
|
||||
a[orderbookType] = orderbookNew
|
||||
orderbook.Orderbook[p.FirstCurrency][p.SecondCurrency] = a
|
||||
m.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
|
||||
Reference in New Issue
Block a user