mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
twap: split doneSignal into a single file
This commit is contained in:
parent
2392fddc3c
commit
9a2b792ed1
39
pkg/twap/v2/done.go
Normal file
39
pkg/twap/v2/done.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package twap
|
||||
|
||||
import "sync"
|
||||
|
||||
type DoneSignal struct {
|
||||
doneC chan struct{}
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func NewDoneSignal() *DoneSignal {
|
||||
return &DoneSignal{
|
||||
doneC: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (e *DoneSignal) Emit() {
|
||||
e.mu.Lock()
|
||||
if e.doneC == nil {
|
||||
e.doneC = make(chan struct{})
|
||||
}
|
||||
|
||||
close(e.doneC)
|
||||
e.mu.Unlock()
|
||||
}
|
||||
|
||||
// Chan returns a channel that emits a signal when the execution is done.
|
||||
func (e *DoneSignal) Chan() (c <-chan struct{}) {
|
||||
// if the channel is not allocated, it means it's not started yet, we need to return a closed channel
|
||||
e.mu.Lock()
|
||||
if e.doneC == nil {
|
||||
e.doneC = make(chan struct{})
|
||||
c = e.doneC
|
||||
} else {
|
||||
c = e.doneC
|
||||
}
|
||||
e.mu.Unlock()
|
||||
|
||||
return c
|
||||
}
|
|
@ -18,42 +18,6 @@ import (
|
|||
|
||||
var defaultUpdateInterval = time.Minute
|
||||
|
||||
type DoneSignal struct {
|
||||
doneC chan struct{}
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func NewDoneSignal() *DoneSignal {
|
||||
return &DoneSignal{
|
||||
doneC: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (e *DoneSignal) Emit() {
|
||||
e.mu.Lock()
|
||||
if e.doneC == nil {
|
||||
e.doneC = make(chan struct{})
|
||||
}
|
||||
|
||||
close(e.doneC)
|
||||
e.mu.Unlock()
|
||||
}
|
||||
|
||||
// Chan returns a channel that emits a signal when the execution is done.
|
||||
func (e *DoneSignal) Chan() (c <-chan struct{}) {
|
||||
// if the channel is not allocated, it means it's not started yet, we need to return a closed channel
|
||||
e.mu.Lock()
|
||||
if e.doneC == nil {
|
||||
e.doneC = make(chan struct{})
|
||||
c = e.doneC
|
||||
} else {
|
||||
c = e.doneC
|
||||
}
|
||||
e.mu.Unlock()
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
// FixedQuantityExecutor is a TWAP executor that places orders on the exchange using the exchange's stream API.
|
||||
// It uses a fixed target quantity to place orders.
|
||||
type FixedQuantityExecutor struct {
|
||||
|
|
Loading…
Reference in New Issue
Block a user