mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
* Added dispatch service * Added orderbook streaming capabilities * Assigned correct orderbook.base exchange name * Fixed Requested niterinos Add in cli orderbook QA tool to gctcli Add exchange orderbook streaming * Add ticker streaming support through dispatch package * Added in some more info on error returns for orderbook.go * fix linter issues * Fix some issues * Update * Fix requested * move dispatch out of exchanges folder to its own independant folder * Fix requested * change orderbook string to tickers * Limit orderbooks to 50 and made dispatch system more stateless in operation * lower cases for update/retrieve/sub exchange name * Adds in asset validation and lower case conversion on cli * Remove comment * Moved timer to a higher scope so its not constantly initialised just reset per instance and removed returning unused channel on error * Rm unused release function in dispatch.go Reset timer and bleed buffered timer chan if needed in dispatch.go Added in ticker.Stop() and timer.Stop() functions for worker routine return in dispatch.go Index aggregated bid and ask functions for orderbook.go Added in dummy slice for wsorderbook_test.go * Moved drain to above Reset so potential race would not occur in dispatch.go Fix various linter issues dispatch.go * Fix some issues * change to start/stop service, added in service state change via cli, updated logger * fix requested * Add worker amount init spawning * fix linter issues * Fix more linter issues * More fixes * Fix race issue on releasing pipe channel on a close after shutting down dispatcher system * Moved all types to dispatch_types.go && remove panic * Moved types into serperate file && improve test coverage * RM unnecessary select case for draining channel && fixed error string * Added orderbook_types file and improved code coverage * gofmt file * reinstated select cases on drain because I am silly * Remove error for drop worker * Added more test cases * not checking error issue fix * remove func causing race in test, this has required protection via an exported function * set Gemini websocket orderbook exchange name
78 lines
1.6 KiB
Go
78 lines
1.6 KiB
Go
package dispatch
|
|
|
|
import (
|
|
"errors"
|
|
"reflect"
|
|
|
|
"github.com/gofrs/uuid"
|
|
)
|
|
|
|
// GetNewMux returns a new multiplexor to track subsystem updates
|
|
func GetNewMux() *Mux {
|
|
return &Mux{d: dispatcher}
|
|
}
|
|
|
|
// Subscribe takes in a package defined signature element pointing to an ID set
|
|
// and returns the associated pipe
|
|
func (m *Mux) Subscribe(id uuid.UUID) (Pipe, error) {
|
|
if m == nil {
|
|
return Pipe{}, errors.New("mux is nil")
|
|
}
|
|
|
|
if id == (uuid.UUID{}) {
|
|
return Pipe{}, errors.New("id not set")
|
|
}
|
|
|
|
ch, err := m.d.subscribe(id)
|
|
if err != nil {
|
|
return Pipe{}, err
|
|
}
|
|
|
|
return Pipe{C: ch, id: id, m: m}, nil
|
|
}
|
|
|
|
// Unsubscribe returns channel to the pool for the full signature set
|
|
func (m *Mux) Unsubscribe(id uuid.UUID, ch chan interface{}) error {
|
|
if m == nil {
|
|
return errors.New("mux is nil")
|
|
}
|
|
return m.d.unsubscribe(id, ch)
|
|
}
|
|
|
|
// Publish takes in a persistent memory address and dispatches changes to
|
|
// required pipes. Data should be of *type.
|
|
func (m *Mux) Publish(ids []uuid.UUID, data interface{}) error {
|
|
if m == nil {
|
|
return errors.New("mux is nil")
|
|
}
|
|
|
|
if data == nil {
|
|
return errors.New("data payload is nil")
|
|
}
|
|
|
|
cpy := reflect.ValueOf(data).Elem().Interface()
|
|
|
|
for i := range ids {
|
|
// Create copy to not interfere with stored value
|
|
err := m.d.publish(ids[i], &cpy)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetID gets a lovely new ID
|
|
func (m *Mux) GetID() (uuid.UUID, error) {
|
|
if m == nil {
|
|
return uuid.UUID{}, errors.New("mux is nil")
|
|
}
|
|
|
|
return m.d.getNewID()
|
|
}
|
|
|
|
// Release returns the channel to the communications pool to be reused
|
|
func (p *Pipe) Release() error {
|
|
return p.m.Unsubscribe(p.id, p.C)
|
|
}
|