Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IEX plugin improvements #170

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions contrib/iex/backfill/backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/alpacahq/marketstore/contrib/calendar"
"github.com/alpacahq/marketstore/contrib/iex/filter"
"github.com/alpacahq/marketstore/contrib/ondiskagg/aggtrigger"
"github.com/alpacahq/marketstore/executor"
"github.com/alpacahq/marketstore/plugins/trigger"
Expand All @@ -25,9 +26,11 @@ import (
)

var (
dir string
from string
to string
dir string
from string
to string
filterName string
symbolFilter filter.SymbolFilter

// NY timezone
NY, _ = time.LoadLocation("America/New_York")
Expand All @@ -38,6 +41,7 @@ func init() {
flag.StringVar(&dir, "dir", "/project/data", "mktsdb directory to backfill to")
flag.StringVar(&from, "from", time.Now().Add(-365*24*time.Hour).Format(format), "backfill from date (YYYY-MM-DD)")
flag.StringVar(&to, "to", time.Now().Format(format), "backfill from date (YYYY-MM-DD)")
flag.StringVar(&filterName, "filter", "", "symbols filter (SPY)")

flag.Parse()
}
Expand All @@ -55,6 +59,11 @@ func main() {
log.Fatal(err.Error())
}

sf, found := filter.Filters[filterName]
if found {
symbolFilter = sf
}

log.Info("backfilling from %v to %v", start.Format(format), end.Format(format))

sem := make(chan struct{}, runtime.NumCPU())
Expand Down Expand Up @@ -182,7 +191,7 @@ func writeBars(bars []*consolidator.Bar) error {
for i := range bars {
batch, index := nextBatch(bars, i)

if len(batch) > 0 {
if len(batch) > 0 && symbolFilter(batch[0].Symbol) {
tbk := NewTimeBucketKeyFromString(fmt.Sprintf("%s/1Min/OHLCV", batch[0].Symbol))

epoch := make([]int64, len(batch))
Expand Down
9 changes: 9 additions & 0 deletions contrib/iex/filter/filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Package filter serves as a utility for filtering IEX symbols
package filter

// SymbolFilter defines a function type for filtering symbols
type SymbolFilter func(string) bool

var Filters = map[string]SymbolFilter{
"SPY": SPY,
}
Loading