feed

package
v4.1.23 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseSchedule

func ParseSchedule(s string) ([]int, error)

ParseSchedule checks comma-separated numbers in a string format and returns the list of minutes that data feeding is executed. Examples: "0,15,30,45" -> [0,15,30,45] (the data feeding must be executed every 15 minutes) "50,10" -> [10, 50] " 20, 40 " -> [20, 40] (whitespaces are ignored) "20" -> [20] (00:10, 01:10, ..., 23:10) "100" -> error (minute must be between 0 and 59) "One" -> error (numbers must be used) "0-10" -> error (range is not supported).

Types

type Backfill

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

Backfill aggregates daily chart data using Alpava v2 API and store it to marketstore.

func NewBackfill

func NewBackfill(symbolManager symbols.Manager, apiClient GetMultiBarsAPIClient, barWriter writer.BarWriter,
	since time.Time, maxBarsPerReq, maxSymbolsPerReq int,
) *Backfill

NewBackfill initializes the module to backfill the historical daily chart data to marketstore. Alpaca API spec: maxBarsPerRequest: 1000 bars per symbol per request at maximum Alpaca API spec: maxSymbolsPerRequest: 100 symbols per request at maximum.

func (*Backfill) UpdateSymbols

func (b *Backfill) UpdateSymbols()

UpdateSymbols aggregates daily chart data since the specified date and store it to "{symbol}/{timeframe}/OHLCV" bucket in marketstore.

type DefaultMarketTimeChecker

type DefaultMarketTimeChecker struct {
	// i.e. []string{"Saturday", "Sunday"}
	ClosedDaysOfTheWeek        []time.Weekday
	ClosedDays                 []time.Time
	OpenHourNY, OpenMinuteNY   int
	CloseHourNY, CloseMinuteNY int
}

DefaultMarketTimeChecker is an implementation for MarketTimeChecker object. this checker checks the followings: - the market is open at this days of the week - the market is open at this time - the market is open today (= check if today is a holiday or not) all those settings should be defined in this object.

func NewDefaultMarketTimeChecker

func NewDefaultMarketTimeChecker(
	closedDaysOfTheWeek []time.Weekday,
	closedDays []time.Time,
	openHourNY, openMinuteNY int,
	closeHourNY, closeMinuteNY int,
) *DefaultMarketTimeChecker

NewDefaultMarketTimeChecker initializes the DefaultMarketTimeChecker object with the specifier parameters.s.

func (*DefaultMarketTimeChecker) IsOpen

func (m *DefaultMarketTimeChecker) IsOpen(t time.Time) bool

IsOpen returns true on weekdays from 08:55 to 15:10. if closedDates are defined, return false on those days.

func (*DefaultMarketTimeChecker) Sub

func (m *DefaultMarketTimeChecker) Sub(dateInJST time.Time, businessDay int) (time.Time, error)

Sub returns a date before X business days (= days which market is open). businessDay should be a positive value.

type GetMultiBarsAPIClient added in v4.1.16

type GetMultiBarsAPIClient interface {
	GetMultiBars(symbols []string, params api.GetBarsParams) (map[string][]api.Bar, error)
}

type GetSnapShotsAPIClient

type GetSnapShotsAPIClient interface {
	GetSnapshots(symbols []string) (map[string]*api.Snapshot, error)
}

type MarketTimeChecker

type MarketTimeChecker interface {
	IsOpen(t time.Time) bool
	// Sub returns a date after X business day (= day which market is open). businessDay can be a negative value.
	Sub(date time.Time, businessDay int) (time.Time, error)
}

MarketTimeChecker is an interface to check if the market is open at the specified time or not.

type ScheduledMarketTimeChecker

type ScheduledMarketTimeChecker struct {
	MarketTimeChecker
	// LastTime holds the last time that IntervalTimeChceker.IsOpen returned true.
	LastTime    time.Time
	ScheduleMin []int
}

ScheduledMarketTimeChecker is used where periodic processing is needed to run even when the market is closed.

func NewScheduledMarketTimeChecker

func NewScheduledMarketTimeChecker(
	mtc MarketTimeChecker,
	scheduleMin []int,
) *ScheduledMarketTimeChecker

func (*ScheduledMarketTimeChecker) IsOpen

IsOpen returns true when the market is open or the interval elapsed since LastTime.

type Worker

type Worker struct {
	MarketTimeChecker MarketTimeChecker
	APIClient         GetSnapShotsAPIClient
	SymbolManager     symbols.Manager
	SnapshotWriter    writer.SnapshotWriter
	BarWriter         writer.BarWriter
	Interval          int
}

Worker is the main worker instance. It implements bgworker.Run().

func (*Worker) Run

func (w *Worker) Run()

Run runs forever to get quotes data for each symbol in the target exchanges using Alpaca API periodically, and writes the data to the local marketstore server.

Jump to

Keyboard shortcuts

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