Documentation
¶
Index ¶
- type Bucket
- type KLineBuilder
- type KLineEmitter
- type TickKLineDriver
- func (t *TickKLineDriver) AddInterval(interval types.Interval) error
- func (t *TickKLineDriver) AddTrade(trade types.Trade)
- func (t *TickKLineDriver) Peek() map[types.Interval]types.KLine
- func (t *TickKLineDriver) ProcessTick(tickTime time.Time)
- func (t *TickKLineDriver) Run(ctx context.Context)
- func (t *TickKLineDriver) SetKLineEmitter(emitter KLineEmitter)
- func (t *TickKLineDriver) SetRunning(startTime time.Time)
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) FillGapKLines ¶
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 ¶
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 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.