Skip to content

Commit

Permalink
Add symbol filters support for iex backfill
Browse files Browse the repository at this point in the history
  • Loading branch information
itsankoff committed Dec 18, 2018
1 parent 7a1e576 commit bd38c83
Showing 1 changed file with 13 additions and 4 deletions.
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", "SPY", "symbols filter")

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

0 comments on commit bd38c83

Please sign in to comment.