Skip to content

Commit

Permalink
fix(linter): revive linter issues (#571)
Browse files Browse the repository at this point in the history
* fix(linter): revive linter issues
  • Loading branch information
dakimura authored Mar 2, 2022
1 parent 2a79ac0 commit 9cabb7e
Show file tree
Hide file tree
Showing 31 changed files with 357 additions and 458 deletions.
13 changes: 6 additions & 7 deletions catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ func (d *Directory) GetTimeBucketInfoSlice() (tbinfolist []*io.TimeBucketInfo) {
return nil
}
tbinfolist = make([]*io.TimeBucketInfo, 0)
for _, finfo_p := range d.datafile {
tbinfolist = append(tbinfolist, finfo_p)
for _, finfoPtr := range d.datafile {
tbinfolist = append(tbinfolist, finfoPtr)
}
return tbinfolist
}
Expand Down Expand Up @@ -319,9 +319,8 @@ func (d *Directory) PathToTimeBucketInfo(path2 string) (*io.TimeBucketInfo, erro
d.recurse(tbinfo, findTimeBucketInfo)
if tbinfo == nil {
return nil, NotFoundError("")
} else {
return tbinfo, nil
}
return tbinfo, nil
}

func (d *Directory) GetDataShapes(key *io.TimeBucketKey) (dsv []io.DataShape, err error) {
Expand Down Expand Up @@ -558,9 +557,9 @@ func (d *Directory) String() string {

func (d *Directory) GatherDirectories() []string {
// Must be thread-safe for READ access
dirListFunc := func(d *Directory, i_list interface{}) {
p_list := i_list.(*[]string)
*p_list = append(*p_list, d.itemName)
dirListFunc := func(d *Directory, iList interface{}) {
pList := iList.(*[]string)
*pList = append(*pList, d.itemName)
}
dirList := make([]string, 0)
d.recurse(&dirList, dirListFunc)
Expand Down
4 changes: 2 additions & 2 deletions contrib/alpacabkfeeder/feed/backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type ListBarsAPIClient interface {
// 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 NewBackfill(symbolManager symbols.Manager, apiClient ListBarsAPIClient, barWriter writer.BarWriter, since time.Time,
maxBarsPerReq, maxSymbolsPerReq int,
func NewBackfill(symbolManager symbols.Manager, apiClient ListBarsAPIClient, barWriter writer.BarWriter,
since time.Time, maxBarsPerReq, maxSymbolsPerReq int,
) *Backfill {
return &Backfill{
symbolManager: symbolManager, apiClient: apiClient, barWriter: barWriter, since: since,
Expand Down
29 changes: 15 additions & 14 deletions contrib/alpacabkfeeder/feed/paginate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"github.com/stretchr/testify/require"
)

func date(year, month, day int) time.Time {
func date(month, day int) time.Time {
const year = 2021
return time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC)
}

Expand All @@ -23,33 +24,33 @@ func Test_datePageIndex(t *testing.T) {
}{
{
name: "ok/5 days paginated by pageSize=2",
start: date(2021, 12, 1),
end: date(2021, 12, 5),
start: date(12, 1),
end: date(12, 5),
pageDays: 2,
want: []dateRange{
{From: date(2021, 12, 1), To: date(2021, 12, 2)},
{From: date(2021, 12, 3), To: date(2021, 12, 4)},
{From: date(2021, 12, 5), To: date(2021, 12, 5)},
{From: date(12, 1), To: date(12, 2)},
{From: date(12, 3), To: date(12, 4)},
{From: date(12, 5), To: date(12, 5)},
},
},
{
name: "ok/3 days paginated by pageSize=5",
start: date(2021, 12, 1),
end: date(2021, 12, 3),
start: date(12, 1),
end: date(12, 3),
pageDays: 5,
want: []dateRange{
{From: date(2021, 12, 1), To: date(2021, 12, 3)},
{From: date(12, 1), To: date(12, 3)},
},
},
{
name: "ok/3 days paginated by pageSize=1",
start: date(2021, 12, 1),
end: date(2021, 12, 3),
start: date(12, 1),
end: date(12, 3),
pageDays: 1,
want: []dateRange{
{From: date(2021, 12, 1), To: date(2021, 12, 1)},
{From: date(2021, 12, 2), To: date(2021, 12, 2)},
{From: date(2021, 12, 3), To: date(2021, 12, 3)},
{From: date(12, 1), To: date(12, 1)},
{From: date(12, 2), To: date(12, 2)},
{From: date(12, 3), To: date(12, 3)},
},
},
}
Expand Down
12 changes: 6 additions & 6 deletions contrib/alpacabkfeeder/writer/bar_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ func (b *BarWriterImpl) convertToCSM(symbol string, bars []alpaca.Bar) io.Column

// Start time of each bar is used for "epoch"
// to align with the 1-day chart backfill. ("00:00:00"(starting time of a day) is used for epoch)
epochs = append(epochs, bars[i].Time)
opens = append(opens, bars[i].Open)
closes = append(closes, bars[i].Close)
highs = append(highs, bars[i].High)
lows = append(lows, bars[i].Low)
volumes = append(volumes, bars[i].Volume)
epochs[i] = bars[i].Time
opens[i] = bars[i].Open
closes[i] = bars[i].Close
highs[i] = bars[i].High
lows[i] = bars[i].Low
volumes[i] = bars[i].Volume
}

// to avoid that empty array is added to csm when all data are Volume=0 and there is no data to write
Expand Down
10 changes: 3 additions & 7 deletions contrib/alpacabkfeeder/writer/snapshot_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

v2 "github.com/alpacahq/alpaca-trade-api-go/v2"
"github.com/pkg/errors"

"github.com/alpacahq/marketstore/v4/utils/io"
"github.com/alpacahq/marketstore/v4/utils/log"
Expand All @@ -27,10 +26,7 @@ type SnapshotWriterImpl struct {
// Write converts the map(key:symbol, value:snapshot) to a ColumnSeriesMap and write it to the local marketstore server.
func (q SnapshotWriterImpl) Write(snapshots map[string]*v2.Snapshot) error {
// convert Snapshot Data to CSM (ColumnSeriesMap)
csm, err := q.convertToCSM(snapshots)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to create CSM from Snapshot Data. %v", snapshots))
}
csm := q.convertToCSM(snapshots)

// write CSM to marketstore
if err := q.MarketStoreWriter.Write(csm); err != nil {
Expand All @@ -41,7 +37,7 @@ func (q SnapshotWriterImpl) Write(snapshots map[string]*v2.Snapshot) error {
return nil
}

func (q *SnapshotWriterImpl) convertToCSM(snapshots map[string]*v2.Snapshot) (io.ColumnSeriesMap, error) {
func (q *SnapshotWriterImpl) convertToCSM(snapshots map[string]*v2.Snapshot) io.ColumnSeriesMap {
csm := io.NewColumnSeriesMap()

for symbol, snapshot := range snapshots {
Expand All @@ -57,7 +53,7 @@ func (q *SnapshotWriterImpl) convertToCSM(snapshots map[string]*v2.Snapshot) (io
csm.AddColumnSeries(*tbk, cs)
}

return csm, nil
return csm
}

func (q SnapshotWriterImpl) newColumnSeries(epoch int64, ss *v2.Snapshot) *io.ColumnSeries {
Expand Down
12 changes: 6 additions & 6 deletions contrib/calendar/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Calendar struct {
earlyCloseTime Time
}

type calendarJson struct {
type calendarJSON struct {
NonTradingDays []string `json:"non_trading_days"`
EarlyCloses []string `json:"early_closes"`
Timezone string `json:"timezone"`
Expand All @@ -45,7 +45,7 @@ type calendarJson struct {
}

// Nasdaq implements market calendar for the NASDAQ.
var Nasdaq = New(NasdaqJson)
var Nasdaq = New(NasdaqJSON)

func julianDate(t time.Time) int {
// Note: Date() is faster than calling Hour(), Month(), and Day() separately
Expand All @@ -64,12 +64,12 @@ func ParseTime(tstr string) Time {
return Time{h, m, s}
}

func New(calendarJSON string) *Calendar {
func New(calendarJSONStr string) *Calendar {
cal := Calendar{days: map[int]MarketState{}}
cmap := calendarJson{}
err := json.Unmarshal([]byte(calendarJSON), &cmap)
cmap := calendarJSON{}
err := json.Unmarshal([]byte(calendarJSONStr), &cmap)
if err != nil {
log.Error(fmt.Sprintf("failed to unmarshal calendarJson:%s", calendarJSON))
log.Error(fmt.Sprintf("failed to unmarshal calendarJson:%s", calendarJSONStr))
return nil
}
for _, dateString := range cmap.NonTradingDays {
Expand Down
2 changes: 1 addition & 1 deletion contrib/calendar/nasdaq.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package calendar

var NasdaqJson = `{
var NasdaqJSON = `{
"timezone": "America/New_York",
"open_time": "09:30:00",
"close_time": "16:00:00",
Expand Down
18 changes: 9 additions & 9 deletions contrib/candler/tickcandler/tickcandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ func (c TickCandler) New(argMap *functions.ArgumentMap, args ...interface{}) (ic
return &TickCandler{ca}, err
}

func (ca *TickCandler) GetRequiredArgs() []io.DataShape {
func (c *TickCandler) GetRequiredArgs() []io.DataShape {
return requiredColumns
}

func (ca *TickCandler) GetOptionalArgs() []io.DataShape {
func (c *TickCandler) GetOptionalArgs() []io.DataShape {
return optionalColumns
}

func (ca *TickCandler) GetInitArgs() []io.DataShape {
func (c *TickCandler) GetInitArgs() []io.DataShape {
return initArgs
}

/*
Accum() sends new data to the aggregate
*/
func (ca *TickCandler) Accum(_ io.TimeBucketKey, argMap *functions.ArgumentMap, cols io.ColumnInterface,
func (c *TickCandler) Accum(_ io.TimeBucketKey, argMap *functions.ArgumentMap, cols io.ColumnInterface,
) (*io.ColumnSeries, error) {
if cols.Len() == 0 {
return nil, fmt.Errorf("empty input to Accum")
Expand All @@ -80,9 +80,9 @@ func (ca *TickCandler) Accum(_ io.TimeBucketKey, argMap *functions.ArgumentMap,
Prepare a consolidated map of columns for use in updating sums
*/
var sumCols map[string][]float32
if len(ca.AccumSumNames) != 0 {
if len(c.AccumSumNames) != 0 {
sumCols = make(map[string][]float32)
for _, name := range ca.AccumSumNames {
for _, name := range c.AccumSumNames {
sumCols[name], err = uda.ColumnToFloat32(cols, name)
if err != nil {
return nil, err
Expand All @@ -91,15 +91,15 @@ func (ca *TickCandler) Accum(_ io.TimeBucketKey, argMap *functions.ArgumentMap,
}
var candle *candler.Candle
for i, t := range ts {
candle = ca.GetCandle(t, candle)
candle = c.GetCandle(t, candle)
candle.AddCandle(t, price[i])
/*
Iterate over the candle's named columns that need sums
*/
for _, name := range ca.AccumSumNames {
for _, name := range c.AccumSumNames {
candle.SumMap[name] += float64(sumCols[name][i])
}
candle.Count++
}
return ca.Output(), nil
return c.Output(), nil
}
57 changes: 29 additions & 28 deletions contrib/iex/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ func GetBars(symbols []string, barRange string, limit *int, retries int) (*GetBa

if len(symbols) == 0 {
return &GetBarsResponse{}, nil
} else {
var newsymbols []string
for _, sym := range symbols {
if !symbolsExcluded[sym] {
newsymbols = append(newsymbols, sym)
}
}

var newsymbols []string
for _, sym := range symbols {
if !symbolsExcluded[sym] {
newsymbols = append(newsymbols, sym)
}
symbols = newsymbols
}
symbols = newsymbols

q := u.Query()

Expand Down Expand Up @@ -174,31 +174,32 @@ func GetBars(symbols []string, barRange string, limit *int, retries int) (*GetBa
if len(symbols) == 1 { // Idenified an OTC symbol
symbolsExcluded[symbols[0]] = true
return nil, fmt.Errorf("OTC Error: %s: %s [Symbol: %s]", res.Status, string(body), symbols[0])
}

var resp0 *GetBarsResponse
var resp1 *GetBarsResponse
split := len(symbols) / 2

// fmt.Printf("Symbol groups: %v - %v\n", symbols[:split], symbols[split:])

resp = GetBarsResponse{}
resp0, err1 := GetBars(symbols[:split], barRange, limit, retries)
resp1, err2 := GetBars(symbols[split:], barRange, limit, retries)
if err1 != nil {
log.Error(err1.Error())
} else {
var resp0 *GetBarsResponse
var resp1 *GetBarsResponse
split := len(symbols) / 2

// fmt.Printf("Symbol groups: %v - %v\n", symbols[:split], symbols[split:])

resp = GetBarsResponse{}
resp0, err1 := GetBars(symbols[:split], barRange, limit, retries)
resp1, err2 := GetBars(symbols[split:], barRange, limit, retries)
if err1 != nil {
log.Error(err1.Error())
} else {
for k, v := range *resp0 {
resp[k] = v
}
for k, v := range *resp0 {
resp[k] = v
}
if err2 != nil {
log.Error(err2.Error())
} else {
for k, v := range *resp1 {
resp[k] = v
}
}
if err2 != nil {
log.Error(err2.Error())
} else {
for k, v := range *resp1 {
resp[k] = v
}
}

} else {
if err = json.Unmarshal(body, &resp); err != nil {
return nil, errors.New(res.Status + ": " + string(body))
Expand Down
Loading

0 comments on commit 9cabb7e

Please sign in to comment.