Reorganized structure, seperating implementations from core logic

This commit is contained in:
2025-11-28 00:53:37 +08:00
parent f1e5937978
commit 9b9d9e2156
24 changed files with 4 additions and 108 deletions

View File

@@ -0,0 +1,2 @@
// Package coordinator ...
package coordinator

9
pkg/data/descriptor.go Normal file
View File

@@ -0,0 +1,9 @@
package data
type Descriptor struct {
Type string
Key string
Schema string
Attributes map[string]string
Tags []string
}

18
pkg/data/egress.go Normal file
View File

@@ -0,0 +1,18 @@
package data
import (
"context"
"github.com/google/uuid"
)
type Egress interface {
Name() string
Configure(cfg map[string]any) error
Connect(ctx context.Context, actions EgresActions) error
Disconnect(ctx context.Context) error
}
type EgresActions interface {
Subscribe(ctx context.Context, namespace string, id uuid.UUID) (<-chan Envelope, func(), error)
}

13
pkg/data/envelope.go Normal file
View File

@@ -0,0 +1,13 @@
// Package data ...
package data
import (
"time"
)
type Envelope struct {
SendTime time.Time
Descriptor Descriptor
Payload any
}

12
pkg/data/events/bar.go Normal file
View File

@@ -0,0 +1,12 @@
package events
import "time"
type Bar struct {
Open float64
High float64
Low float64
Close float64
Volume float64
Interval time.Duration
}

View File

@@ -0,0 +1,6 @@
package events
type Custom struct {
Bytes []byte
ContentType string
}

22
pkg/data/events/domain.go Normal file
View File

@@ -0,0 +1,22 @@
// Package events ...
package events
type DataType uint8
const (
TradeType DataType = iota
QuoteType
BarType
MBPDeltaType
MBPSnapshotType
MBODeltaType
MBOSnapshotType
CustomType
)
type Side uint8
const (
Bid Side = iota
Ask
)

View File

@@ -0,0 +1,20 @@
package events
type MBODelta struct {
Operation MBOOrderOp
OrderID string
Side Side
Price float64
Size float64
IsMaker bool
Seq uint64
ParentID string
}
type MBOOrderOp uint8
const (
OrderAdd MBOOrderOp = iota
OrderMod
OrderDel
)

View File

@@ -0,0 +1,14 @@
package events
type MBOSnapshot struct {
Orders []OrderEntry
Seq uint64
}
type OrderEntry struct {
OrderID string
Side Side
Price float64
Size float64
IsMaker bool
}

View File

@@ -0,0 +1,8 @@
package events
type MBPDelta struct {
Side Side
Price float64
Size float64
Seq uint64
}

View File

@@ -0,0 +1,13 @@
package events
type MBPSnapshot struct {
Bids []PriceLevel
Asks []PriceLevel
Depth int
Seq uint64
}
type PriceLevel struct {
Price float64
Size float64
}

8
pkg/data/events/quote.go Normal file
View File

@@ -0,0 +1,8 @@
package events
type Quote struct {
BidPrice float64
BidSize float64
AskPrice float64
AskSize float64
}

16
pkg/data/events/trade.go Normal file
View File

@@ -0,0 +1,16 @@
package events
type Trade struct {
Price float64
Qty float64
Aggressor AggressorSide
TradeID string
}
type AggressorSide uint8
const (
AggUnknown AggressorSide = iota
AggBuy
AggSell
)

34
pkg/data/ingress.go Normal file
View File

@@ -0,0 +1,34 @@
package data
import (
"context"
"time"
"github.com/google/uuid"
)
type Ingress interface {
Name() string
Configure(cfg map[string]any) error
Connect(ctx context.Context, actions IngressActions) error
Disconnect(ctx context.Context) error
}
type IngressActions interface {
Emit(namespace string, id uuid.UUID, envelope Envelope) error
EmitBatch(namespace string, id uuid.UUID, envelopes []Envelope) error
}
type LiveIngress interface {
Subscribe(ctx context.Context, key ...string) error
Unsubscribe(ctx context.Context, key ...string) error
ListAvailableKeys(ctx context.Context) []string
IsValidKey(ctx context.Context, key string) bool
}
type HistoricalIngress interface {
Fetch(ctx context.Context, key string, start time.Time, end time.Time) ([]Envelope, error)
ListAvailableKeys(ctx context.Context) []string
IsValidKey(ctx context.Context, key string) bool
// some other method that gives the avalible time period for a key
}

14
pkg/data/processor.go Normal file
View File

@@ -0,0 +1,14 @@
package data
import "context"
type Processor interface {
Name() string
Configure(cfg map[string]any) error
Run(ctx context.Context, actions ProcessorActions) error
}
type ProcessorActions interface {
IngressActions
EgresActions
}

1
pkg/data/registry.go Normal file
View File

@@ -0,0 +1 @@
package data

View File

@@ -0,0 +1,2 @@
// Package router ...
package router