klinedriver

package
v1.63.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	// StartTime is inclusive, EndTime is exclusive
	// e.g. [StartTime, EndTime)
	StartTime, EndTime types.Time
	Interval           types.Interval
	KLine              *types.KLine
	Exposed            bool
}

func (*Bucket) Contains

func (bucket *Bucket) Contains(currentTime types.Time) bool

check if the currentTime is in [startTime, startTime + interval)

func (*Bucket) FillGapKLines

func (bucket *Bucket) FillGapKLines(numShifts uint64) (kLines []*types.KLine)

FillGapKLines returns the kline slices that are used to fill the gap between the bucket and the next bucket. Note that it will also update the bucket's status including the start/end time and the kline.

type KLineBuilder

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

KLineBuilder builds klines from trades and trades only

func NewKLineBuilder

func NewKLineBuilder(symbol string) *KLineBuilder

NewKLineBuilder creates a new KLineBuilder. IMPORTANT: The klines built by this builder are in UTC timezone.

func (*KLineBuilder) AddInterval

func (kb *KLineBuilder) AddInterval(interval types.Interval, initTime types.Time)

AddInterval adds an interval to the KLineBuilder. AddInterval should be called before any operations on the KLineBuilder.

func (*KLineBuilder) AddTrade

func (kb *KLineBuilder) AddTrade(trade types.Trade)

AddTrade adds a trade to the KLineBuilder. The semantics of the AddTrade is to notify the current time to the KLineBuilder with the trade. The builder will accumulate the kline according to the trade time and update its state if needed. The builder assumes the trades are passed monotonically.

func (*KLineBuilder) Update

func (kb *KLineBuilder) Update(updateTime types.Time) (kLinesMap map[types.Interval][]*types.KLine)

Update updates the KLineBuilder with the given update time. The semantics of the Update is to notify the current timestamp to the KLineBuilder. Note that the start/end time of the klines are in UTC timezone. In addition to that, the end time will be (start time + interval) instead of (start time + interval - 1ms). The rationale is that we want to keep the logic as simple as possible and let the driver/caller to handle subtle adjustments, such as adjusting the end time to be 1ms before the next start time. Also, it will make it easier to write test for the KLineBuilder.

type KLineEmitter

type KLineEmitter interface {
	EmitKLine(types.KLine)
	EmitKLineClosed(types.KLine)
}

type TickKLineDriver

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

func NewTickKLineDriver

func NewTickKLineDriver(symbol string, tickDuration time.Duration) *TickKLineDriver

func (*TickKLineDriver) AddInterval

func (t *TickKLineDriver) AddInterval(interval types.Interval) error

func (*TickKLineDriver) AddTrade

func (t *TickKLineDriver) AddTrade(trade types.Trade)

AddTrade adds a trade to the kline driver.

func (*TickKLineDriver) Peek

func (t *TickKLineDriver) Peek() map[types.Interval]types.KLine

Peek returns the current kline for all intervals. Useful for replay klines or backtesting

func (*TickKLineDriver) ProcessTick

func (t *TickKLineDriver) ProcessTick(tickTime time.Time)

ProcessTick processes the tick time and emits kline events.

func (*TickKLineDriver) Run

func (t *TickKLineDriver) Run(ctx context.Context)

Run starts the kline driver. The driver can be only run once. Panic otherwise.

func (*TickKLineDriver) SetKLineEmitter

func (t *TickKLineDriver) SetKLineEmitter(emitter KLineEmitter)

func (*TickKLineDriver) SetRunning

func (t *TickKLineDriver) SetRunning(startTime time.Time)

SetRunning sets the running state of the driver. As for backtesting, use this method to set the start time of the driver.

Jump to

Keyboard shortcuts

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