mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-17 23:16:52 +00:00
* orderbook: export orderbook nodes for external strategy inspection * orderbook: Add in methods for locking and unlocking multiple books at the same time e.g. book1.LockWith(book2); defer book1.UnlockWith(book2) * include waiting functionality for depth change alert * backtester: add word. * log: include logger changes to impl with downstream integration * engine: reduce params for loading exchange * assort: rm verbose in tests, change wording in ob, expose sync.waitgroup for ext. sync options * ticker: reduce map look ups and contention when using RW mutex when there are over 80% writes adds find last function to get the latest rate * engine/syncmanager: add in waitgroup for step over for external package calls * cleaup * engine: linter fix * currency/fx: include all references to fiat currencies to default * orderbook: Add in fields to Unsafe type for strategies to detect potential out of sync book operations * syncmanager: changed config variable to display correct time * ordermanager: Add time when none provided * currency/manager: update getasset param to get enabled assets for minor optimizations * ftx: use get all wallet balances for a better accounts breakdown * orderbook: unlock in reverse order * bithumb: fixes bug on market buy and sell orders * bithumb: fix bug for nonce is also time window sensitive * bithumb: get orders add required parameter * bithumb: Add asset type to account struct * currency: improve log output when checking currency and it fails * bithumb: Add error return on incomplete pair * ticker:unexport all service related methods * ticker/currency: fixes * orderbook: fix comment * engine: revert variable name in LoadExchange method * sync_manager: fix panic when enabling disabling manager * engine: fix naming convention of exported function and comments * engine: update comment * orderbook: fix comment for unsafe type
63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
package orderbook
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
// Unsafe is an exported linked list reference to the current bid/ask heads and
|
|
// a reference to the underlying depth mutex. This allows for the exposure of
|
|
// the internal list to an external strategy or subsystem. The bid and ask
|
|
// fields point to the actual head fields contained on both linked list structs,
|
|
// so that this struct can be reusable and not needed to be called on each
|
|
// inspection.
|
|
type Unsafe struct {
|
|
BidHead **Node
|
|
AskHead **Node
|
|
m *sync.Mutex
|
|
|
|
// UpdatedViaREST defines if sync manager is updating this book via the REST
|
|
// protocol then this book is not considered live and cannot be trusted.
|
|
UpdatedViaREST *bool
|
|
LastUpdated *time.Time
|
|
*Alert
|
|
}
|
|
|
|
// Lock locks down the underlying linked list which inhibits all pending updates
|
|
// for strategy inspection.
|
|
func (src *Unsafe) Lock() {
|
|
src.m.Lock()
|
|
}
|
|
|
|
// Unlock unlocks the underlying linked list after inspection by a strategy to
|
|
// resume normal operations
|
|
func (src *Unsafe) Unlock() {
|
|
src.m.Unlock()
|
|
}
|
|
|
|
// LockWith locks both books for the context of cross orderbook inspection.
|
|
// WARNING: When inspecting diametrically opposed books a higher order mutex
|
|
// MUST be used or a dead lock will occur.
|
|
func (src *Unsafe) LockWith(dst sync.Locker) {
|
|
src.m.Lock()
|
|
dst.Lock()
|
|
}
|
|
|
|
// UnlockWith unlocks both books for the context of cross orderbook inspection
|
|
func (src *Unsafe) UnlockWith(dst sync.Locker) {
|
|
dst.Unlock() // Unlock in reverse order
|
|
src.m.Unlock()
|
|
}
|
|
|
|
// GetUnsafe returns an unsafe orderbook with pointers to the linked list heads.
|
|
func (d *Depth) GetUnsafe() Unsafe {
|
|
return Unsafe{
|
|
BidHead: &d.bids.linkedList.head,
|
|
AskHead: &d.asks.linkedList.head,
|
|
m: &d.m,
|
|
Alert: &d.Alert,
|
|
UpdatedViaREST: &d.options.restSnapshot,
|
|
LastUpdated: &d.options.lastUpdated,
|
|
}
|
|
}
|