quanttick

package
v0.0.0-...-679100d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExchangeSymbolKey

func ExchangeSymbolKey(exchange string, symbol string) string

func RunExchanges

func RunExchanges(ctx context.Context, clients []Exchange, handler TradeHandler, errorHandler ErrorHandler) error

func ValidateStreams

func ValidateStreams(streams []Stream) error

Types

type Aggregator

type Aggregator[T any] interface {
	Add(trade TradeEvent) ([]T, error)
	Flush(key string) ([]T, error)
}

Aggregator accepts one normalized trade and emits zero or more derived events.

type BatchPublisher

type BatchPublisher[T any] interface {
	PublishBatch(context.Context, []T) error
}

type Decimal

type Decimal = decimal.Decimal

Decimal is the package-wide exact numeric type for prices and sizes.

func MustDecimal

func MustDecimal(value string) Decimal

func ParseDecimal

func ParseDecimal(value string) (Decimal, error)

type ErrorHandler

type ErrorHandler func(error)

type Exchange

type Exchange interface {
	Name() string
	// Trades starts one stateful stream. Adapter instances support one active call.
	// The error channel contains best-effort diagnostics and may drop errors.
	Trades(ctx context.Context) (<-chan TradeEvent, <-chan error)
}

Exchange streams normalized trade events from one market data source.

type JSONLine

type JSONLine[T any] struct {
	Stream  string `json:"stream,omitempty"`
	Payload T      `json:"payload"`
}

type JSONLinesPublisher

type JSONLinesPublisher[T any] struct {
	// contains filtered or unexported fields
}

func NewJSONLinesPublisher

func NewJSONLinesPublisher[T any](writer io.Writer, stream string, mu *sync.Mutex) *JSONLinesPublisher[T]

func (*JSONLinesPublisher[T]) Publish

func (p *JSONLinesPublisher[T]) Publish(ctx context.Context, payload T) error

type Publisher

type Publisher[T any] interface {
	Publish(ctx context.Context, payload T) error
}

Publisher writes one payload to an external sink.

type PublisherFunc

type PublisherFunc[T any] func(context.Context, T) error

func (PublisherFunc[T]) Publish

func (f PublisherFunc[T]) Publish(ctx context.Context, payload T) error

type SignificantTrade

type SignificantTrade struct {
	Exchange               string    `json:"exchange"`
	UID                    string    `json:"uid"`
	Symbol                 string    `json:"symbol"`
	Timestamp              time.Time `json:"timestamp"`
	Nanoseconds            int       `json:"nanoseconds"`
	Price                  Decimal   `json:"price"`
	Volume                 *Decimal  `json:"volume"`
	Notional               *Decimal  `json:"notional"`
	TickRule               *int      `json:"tickRule"`
	Ticks                  *int      `json:"ticks"`
	IsSequential           bool      `json:"isSequential"`
	High                   Decimal   `json:"high"`
	Low                    Decimal   `json:"low"`
	TotalBuyVolume         Decimal   `json:"totalBuyVolume"`
	TotalVolume            Decimal   `json:"totalVolume"`
	TotalBuyNotional       Decimal   `json:"totalBuyNotional"`
	TotalNotional          Decimal   `json:"totalNotional"`
	TotalBuyTicks          int       `json:"totalBuyTicks"`
	TotalTicks             int       `json:"totalTicks"`
	SignificantTradeFilter Decimal   `json:"-"`
	IsLate                 bool      `json:"isLate,omitempty"`
}

func (SignificantTrade) ExchangeSymbol

func (t SignificantTrade) ExchangeSymbol() (string, string)

type SignificantTradeAggregator

type SignificantTradeAggregator struct {
	// contains filtered or unexported fields
}

func NewSignificantTradeAggregator

func NewSignificantTradeAggregator(threshold Decimal, windowDuration time.Duration) *SignificantTradeAggregator

func NewSignificantTradeAggregatorWithThresholds

func NewSignificantTradeAggregatorWithThresholds(
	threshold Decimal,
	thresholds map[string]Decimal,
	windowDuration time.Duration,
) *SignificantTradeAggregator

func (*SignificantTradeAggregator) Add

func (*SignificantTradeAggregator) Flush

type Stream

type Stream string
const (
	RawTrades         Stream = "raw-trades"
	AggregatedTrades  Stream = "aggregated-trades"
	SignificantTrades Stream = "significant-trades"
)

type SymbolThresholds

type SymbolThresholds struct {
	Symbols    []string
	Thresholds map[string]Decimal
}

func ParseSymbolThresholds

func ParseSymbolThresholds(exchange string, values []string) (SymbolThresholds, error)

type TradeAggregator

type TradeAggregator struct {
	// contains filtered or unexported fields
}

TradeAggregator aggregates sequential trades that share exchange, symbol, timestamp, nanoseconds, and tick rule.

func NewTradeAggregator

func NewTradeAggregator() *TradeAggregator

func (*TradeAggregator) Add

func (a *TradeAggregator) Add(trade TradeEvent) ([]TradeEvent, error)

func (*TradeAggregator) Flush

func (a *TradeAggregator) Flush(key string) ([]TradeEvent, error)

type TradeEvent

type TradeEvent struct {
	Exchange     string    `json:"exchange"`
	UID          string    `json:"uid"`
	Symbol       string    `json:"symbol"`
	Timestamp    time.Time `json:"timestamp"`
	Nanoseconds  int       `json:"nanoseconds"`
	Price        Decimal   `json:"price"`
	Volume       Decimal   `json:"volume"`
	Notional     Decimal   `json:"notional"`
	TickRule     int       `json:"tickRule"`
	Ticks        int       `json:"ticks"`
	IsSequential bool      `json:"isSequential"`
	ReceivedAt   time.Time `json:"-"`
}

TradeEvent is the normalized exchange trade payload shared by exchanges, aggregators, and publishers.

func NewTradeEvent

func NewTradeEvent(input TradeEventInput) TradeEvent

NewTradeEvent builds a normalized trade and computes volume as price*notional.

func (TradeEvent) ExchangeSymbol

func (t TradeEvent) ExchangeSymbol() (string, string)

type TradeEventInput

type TradeEventInput struct {
	Exchange     string
	UID          string
	Symbol       string
	Timestamp    time.Time
	ReceivedAt   time.Time
	Price        Decimal
	Volume       *Decimal
	Notional     Decimal
	TickRule     int
	Nanoseconds  int
	Ticks        int
	IsSequential bool
}

type TradeHandler

type TradeHandler func(context.Context, TradeEvent) error

type TradePipeline

type TradePipeline struct {
	RawPublisher         Publisher[TradeEvent]
	AggregatedPublisher  Publisher[TradeEvent]
	SignificantPublisher Publisher[SignificantTrade]
	// contains filtered or unexported fields
}

TradePipeline derives and publishes trade streams. Calls must be serialized, and publishers must not call back into the pipeline.

func NewTradePipeline

func NewTradePipeline(config TradePipelineConfig) *TradePipeline

func (*TradePipeline) Flush

func (p *TradePipeline) Flush(ctx context.Context) error

func (*TradePipeline) FlushBefore

func (p *TradePipeline) FlushBefore(ctx context.Context, exchange string, symbol string, timestamp time.Time) error

func (*TradePipeline) Handle

func (p *TradePipeline) Handle(ctx context.Context, trade TradeEvent) error

type TradePipelineConfig

type TradePipelineConfig struct {
	RawPublisher          Publisher[TradeEvent]
	AggregatedPublisher   Publisher[TradeEvent]
	SignificantPublisher  Publisher[SignificantTrade]
	SignificantThreshold  Decimal
	SignificantThresholds map[string]Decimal
	WindowDuration        time.Duration
}

type WebSocketDataBucket

type WebSocketDataBucket struct {
	Exchange               string
	APISymbol              string
	SignificantTradeFilter int64
	Timestamp              time.Time
	RawTrades              []TradeEvent
	AggregatedTrades       []TradeEvent
	FilteredTrades         []SignificantTrade
	// contains filtered or unexported fields
}

type WebSocketDataBuffer

type WebSocketDataBuffer struct {
	// contains filtered or unexported fields
}

func (*WebSocketDataBuffer) AggregatedPublisher

func (b *WebSocketDataBuffer) AggregatedPublisher() Publisher[TradeEvent]

func (*WebSocketDataBuffer) Flush

func (b *WebSocketDataBuffer) Flush(ctx context.Context) (int, error)

func (*WebSocketDataBuffer) FlushBefore

func (b *WebSocketDataBuffer) FlushBefore(ctx context.Context, exchange string, symbol string, timestamp time.Time) (int, error)

func (*WebSocketDataBuffer) RawPublisher

func (b *WebSocketDataBuffer) RawPublisher() Publisher[TradeEvent]

type WebSocketDataBufferConfig

type WebSocketDataBufferConfig struct {
	DefaultSignificantTradeFilter Decimal
	SignificantThresholds         map[string]Decimal
}

type WebSocketDataStore

type WebSocketDataStore struct {
	// contains filtered or unexported fields
}

func NewWebSocketDataStore

func NewWebSocketDataStore(db *sql.DB) *WebSocketDataStore

func (*WebSocketDataStore) UpsertBuckets

func (s *WebSocketDataStore) UpsertBuckets(ctx context.Context, buckets []WebSocketDataBucket) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL