Documentation
¶
Index ¶
- func ExchangeSymbolKey(exchange string, symbol string) string
- func RunExchanges(ctx context.Context, clients []Exchange, handler TradeHandler, ...) error
- func ValidateStreams(streams []Stream) error
- type Aggregator
- type BatchPublisher
- type Decimal
- type ErrorHandler
- type Exchange
- type JSONLine
- type JSONLinesPublisher
- type Publisher
- type PublisherFunc
- type SignificantTrade
- type SignificantTradeAggregator
- type Stream
- type SymbolThresholds
- type TradeAggregator
- type TradeEvent
- type TradeEventInput
- type TradeHandler
- type TradePipeline
- type TradePipelineConfig
- type WebSocketDataBucket
- type WebSocketDataBuffer
- func (b *WebSocketDataBuffer) AggregatedPublisher() Publisher[TradeEvent]
- func (b *WebSocketDataBuffer) Flush(ctx context.Context) (int, error)
- func (b *WebSocketDataBuffer) FlushBefore(ctx context.Context, exchange string, symbol string, timestamp time.Time) (int, error)
- func (b *WebSocketDataBuffer) RawPublisher() Publisher[TradeEvent]
- type WebSocketDataBufferConfig
- type WebSocketDataStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExchangeSymbolKey ¶
func RunExchanges ¶
func RunExchanges(ctx context.Context, clients []Exchange, handler TradeHandler, errorHandler ErrorHandler) error
func ValidateStreams ¶
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 Decimal ¶
Decimal is the package-wide exact numeric type for prices and sizes.
func MustDecimal ¶
func ParseDecimal ¶
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 JSONLinesPublisher ¶
type JSONLinesPublisher[T any] struct { // contains filtered or unexported fields }
func NewJSONLinesPublisher ¶
type PublisherFunc ¶
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 (*SignificantTradeAggregator) Add ¶
func (a *SignificantTradeAggregator) Add(trade TradeEvent) ([]SignificantTrade, error)
func (*SignificantTradeAggregator) Flush ¶
func (a *SignificantTradeAggregator) Flush(key string) ([]SignificantTrade, error)
type SymbolThresholds ¶
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 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) FlushBefore ¶
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 NewWebSocketDataBuffer ¶
func NewWebSocketDataBuffer(store *WebSocketDataStore, config WebSocketDataBufferConfig) *WebSocketDataBuffer
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 (*WebSocketDataBuffer) RawPublisher ¶
func (b *WebSocketDataBuffer) RawPublisher() Publisher[TradeEvent]
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