Skip to content

Commit

Permalink
refactor(xignite): remove unnecessary comments and files (#531)
Browse files Browse the repository at this point in the history
* refactor(xignite): remove unnecessary comments and files

* fix(xignite): add GetQuotes API request log
  • Loading branch information
dakimura authored Dec 16, 2021
1 parent 0f59ea9 commit f7ff46c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 58 deletions.
12 changes: 6 additions & 6 deletions contrib/xignitefeeder/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ const (
// /QUICKEquityRealTime.json/ListSymbols : list symbols for a exchange
// /QUICKIndexHistorical.json/ListSymbols : list index symbols for an index group (ex. TOPIX)
ListIndexSymbolsURL = XigniteBaseURL + "/QUICKIndexHistorical.json/ListSymbols"
// GetQuotesRangeURL is the URL of Get Quotes Range endpoint
// (https://www.marketdata-cloud.quick-co.jp/Products/QUICKEquityHistorical/Overview/GetQuotesRange)
// GetBarsURL is the URL of Get Bars endpoint
// (https://www.marketdata-cloud.quick-co.jp/Products/QUICKEquityRealTime/Overview/GetBars)
GetBarsURL = XigniteBaseURL + "/QUICKEquityRealTime.json/GetBars"
// GetIndexBarsURL is the URL of QuickIndexRealTime/GetBars endpoint
// (https://www.marketdata-cloud.quick-co.jp/Products/QUICKIndexRealTime/Overview/GetBars)
GetIndexBarsURL = XigniteBaseURL + "/QUICKIndexRealTime.json/GetBars"
GetIndexBarsURL = XigniteBaseURL + "/QUICKIndexRealTime.json/GetBars"
// GetQuotesRangeURL is the URL of Get Quotes Range endpoint
// (https://www.marketdata-cloud.quick-co.jp/Products/QUICKEquityHistorical/Overview/GetQuotesRange)
GetQuotesRangeURL = XigniteBaseURL + "/QUICKEquityHistorical.json/GetQuotesRange"
// GetIndexQuotesRangeURL is the URL of Get Index Quotes Range endpoint
// (https://www.marketdata-cloud.quick-co.jp/Products/QUICKIndexHistorical/Overview/GetQuotesRange)
Expand All @@ -62,7 +62,7 @@ func NewDefaultAPIClient(token string, timeoutSec int) *DefaultClient {
}
}

// DefaultClient is the Xignite API client object.
// DefaultClient is the Xignite API client with a default http client.
type DefaultClient struct {
httpClient *http.Client
token string
Expand All @@ -84,11 +84,11 @@ func (c *DefaultClient) GetRealTimeQuotes(identifiers []string) (response GetQuo
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

log.Info("GetRealTimeQuotes API request: IdentifierType=Symbol, num_identifiers=%d",len(identifiers))
err = c.execute(req, &response)
if err != nil {
return response, err
}
log.Debug(fmt.Sprintf("[Xignite API] Delay(sec) in GetQuotes response= %f", response.DelaySec))

// log not-successful responses
if len(identifiers) != len(response.ArrayOfEquityQuote) {
Expand Down Expand Up @@ -125,7 +125,7 @@ func (c *DefaultClient) ListSymbols(exchange string) (response ListSymbolsRespon
}

if response.Outcome != "Success" {
return response, errors.Errorf("error response is returned from Xignite. %v", response)
return response, fmt.Errorf("error from Xignite API(ListSymbols) %v", response)
}

return response, nil
Expand Down
14 changes: 2 additions & 12 deletions contrib/xignitefeeder/api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,10 @@ func (cd *XigniteDateTime) UnmarshalJSON(input []byte) error {
return nil
}

// --------------------------

// XigniteDay is a date (yyyy/mm/dd) in XigniteDateTimeLayout format
type XigniteDay time.Time

// XigniteDay is a layout of Datetime string returned from Xignite GetQuotesRange API
// XigniteDayLayout is a layout of Datetime string returned from Xignite GetQuotesRange API
const XigniteDayLayout = "2006/01/02"

// UnmarshalJSON parses a string in the XigniteDay Layout
Expand All @@ -102,8 +100,6 @@ func (cd *XigniteDay) UnmarshalJSON(input []byte) error {
return nil
}

// --------------------------

// ListSymbolsResponse is a response model for the /QUICKEquityRealTime.json/ListSymbols endpoint
type ListSymbolsResponse struct {
Outcome string `json:"Outcome"`
Expand All @@ -116,7 +112,6 @@ type SecurityDescription struct {
Symbol string `json:"Symbol"`
}

// --------------------------
// ListIndexSymbolsResponse is a response model for the /QUICKIndexHistorical.json/ListSymbols endpoint
type ListIndexSymbolsResponse struct {
Outcome string `json:"Outcome"`
Expand All @@ -129,7 +124,6 @@ type Index struct {
Symbol string `json:"Symbol"`
}

// --------------------------
type GetBarsResponse struct {
Outcome string `json:"Outcome"`
DelaySec float32 `json:"Delay"`
Expand All @@ -149,7 +143,6 @@ type Bar struct {
Volume float32 `json:"Volume"` // Get Bars API returns a float value for Volume, not int
}

// --------------------------
type GetIndexBarsResponse struct {
Outcome string `json:"Outcome"`
DelaySec float32 `json:"Delay"`
Expand All @@ -158,7 +151,6 @@ type GetIndexBarsResponse struct {
ArrayOfBar []Bar `json:"ArrayOfBar"`
}

// --------------------------
// GetQuotesRangeResponse is a response model for the QUICKEquityHistorical/GetQuotesRange endpoint
type GetQuotesRangeResponse struct {
Outcome string `json:"Outcome"`
Expand All @@ -182,9 +174,7 @@ type EndOfDayQuote struct {
PercentChangeFromPreviousClose float32 `json:"PercentChangeFromPreviousClose"`
}

// --------------------------

// GetQuotesRangeResponse is a response model for the QuickIndexHistorical/GetQuotesRange endpoint
// GetIndexQuotesRangeResponse is a response model for the QuickIndexHistorical/GetQuotesRange endpoint
type GetIndexQuotesRangeResponse struct {
Outcome string `json:"Outcome"`
Message string `json:"Message"`
Expand Down
6 changes: 3 additions & 3 deletions contrib/xignitefeeder/configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"github.com/pkg/errors"
)

// json iter supports marshal/unmarshal of map[interface{}]interface{] type.
// when the config file contains (a) nested structure(s) like follows:
// Use json iter because it supports marshal/unmarshal of map[interface{}]interface{} type.
// When the config file contains (a) nested structure(s) like follows:
//
// backfill:
// enabled: true
//
// the standard "encoding/json" library cannot marshal the structure
// ,the standard "encoding/json" library cannot marshal the structure
// because the config is parsed from a yaml file (mkts.yaml) to map[string]interface{} and passed to this file,
// and config["backfill"] object has map[interface{}]interface{} type.
var json = jsoniter.ConfigCompatibleWithStandardLibrary
Expand Down
36 changes: 13 additions & 23 deletions contrib/xignitefeeder/internal/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"github.com/alpacahq/marketstore/v4/utils/io"
)

// ----------------

// MockSymbolsManager is a no-op SymbolsManager
type MockSymbolsManager struct {
Identifiers []string
Expand All @@ -20,88 +18,80 @@ func (msm MockSymbolsManager) GetAllIdentifiers() []string {
return msm.Identifiers
}

// GetAllIdentifiers returns the static index identifiers
// GetAllIndexIdentifiers returns the static index identifiers
func (msm MockSymbolsManager) GetAllIndexIdentifiers() []string {
return msm.IndexIdentifiers
}

// ----------------

// MockAPIClient is a no-op API client
type MockAPIClient struct{}

// GetRealTimeQuotes returns an empty api response
func (mac *MockAPIClient) GetRealTimeQuotes(identifiers []string) (api.GetQuotesResponse, error) {
func (mac *MockAPIClient) GetRealTimeQuotes(_ []string) (api.GetQuotesResponse, error) {
return api.GetQuotesResponse{}, nil
}

// ListSymbols returns an empty api response
func (mac *MockAPIClient) ListSymbols(exchange string) (api.ListSymbolsResponse, error) {
func (mac *MockAPIClient) ListSymbols(_ string) (api.ListSymbolsResponse, error) {
return api.ListSymbolsResponse{}, nil
}

// ListSymbols returns an empty api response
func (mac *MockAPIClient) ListIndexSymbols(indexGroup string) (api.ListIndexSymbolsResponse, error) {
// ListIndexSymbols returns an empty api response
func (mac *MockAPIClient) ListIndexSymbols(_ string) (api.ListIndexSymbolsResponse, error) {
return api.ListIndexSymbolsResponse{}, nil
}

// GetRealTimeBars returns an empty api response
func (mac *MockAPIClient) GetRealTimeBars(identifier string, start, end time.Time) (response api.GetBarsResponse, err error) {
func (mac *MockAPIClient) GetRealTimeBars(_ string, _, _ time.Time) (response api.GetBarsResponse, err error) {
return api.GetBarsResponse{
Security: &api.Security{Symbol: "123"},
ArrayOfBar: []api.Bar{},
}, nil
}

// GetIndexBars returns an empty api response
func (mac *MockAPIClient) GetIndexBars(identifier string, start, end time.Time) (response api.GetIndexBarsResponse, err error) {
func (mac *MockAPIClient) GetIndexBars(_ string, _, _ time.Time) (response api.GetIndexBarsResponse, err error) {
return api.GetIndexBarsResponse{}, nil
}

// GetQuotesRange returns an empty api response
func (mac *MockAPIClient) GetQuotesRange(i string, sd, ed time.Time) (resp api.GetQuotesRangeResponse, err error) {
func (mac *MockAPIClient) GetQuotesRange(_ string, _, _ time.Time) (resp api.GetQuotesRangeResponse, err error) {
return api.GetQuotesRangeResponse{
Security: &api.Security{Symbol: "123"},
ArrayOfEndOfDayQuote: []api.EndOfDayQuote{},
}, nil
}

// GetQuotesRange returns an empty api response
func (mac *MockAPIClient) GetIndexQuotesRange(i string, sd, ed time.Time,
// GetIndexQuotesRange returns an empty api response
func (mac *MockAPIClient) GetIndexQuotesRange(_ string, _, _ time.Time,
) (resp api.GetIndexQuotesRangeResponse, err error) {
return api.GetIndexQuotesRangeResponse{}, nil
}

// ----------------

// MockTimeChecker always returns Open
type MockTimeChecker struct{}

// IsOpen always returns Open
func (m *MockTimeChecker) IsOpen(t time.Time) bool {
func (m *MockTimeChecker) IsOpen(_ time.Time) bool {
return true
}

// Sub always returns a date provided at the first argument
func (m *MockTimeChecker) Sub(dateInJST time.Time, businessDay int) (time.Time, error) {
func (m *MockTimeChecker) Sub(dateInJST time.Time, _ int) (time.Time, error) {
return dateInJST, nil
}

// ----------------

// MockQuotesWriter is a no-op QuotesWriter
type MockQuotesWriter struct {
WriteCount int
}

// Write increments the counter so that a unit test could assert how many times this function is called
func (m *MockQuotesWriter) Write(resp api.GetQuotesResponse) error {
func (m *MockQuotesWriter) Write(_ api.GetQuotesResponse) error {
m.WriteCount++
return nil
}

// ----------------

// MockMarketStoreWriter is a no-op MarketStoreWriter.
type MockMarketStoreWriter struct {
WrittenCSM io.ColumnSeriesMap
Expand Down
2 changes: 1 addition & 1 deletion contrib/xignitefeeder/symbols/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (m ManagerImpl) UpdateIndexSymbols() {

// if ListSymbols API returns an error, don't update the target symbols
if err != nil || resp.Outcome != "Success" {
log.Warn("err=%v, API response=%v", err, resp)
log.Error("UpdateIndexSymbols err=%v, API response=%v", err, resp)
return
}

Expand Down
9 changes: 0 additions & 9 deletions contrib/xignitefeeder/test/integ/tests/text.py

This file was deleted.

4 changes: 0 additions & 4 deletions contrib/xignitefeeder/writer/quotes_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ func (q *QuotesWriterImpl) convertToCSM(response api.GetQuotesResponse) (io.Colu
UTCOffset := time.Duration(-1*eq.Quote.UTCOffSet) * time.Hour
latestDateTime = latestDateTime.Add(UTCOffset).In(q.Timezone)

//if !q.needToWrite(eq.Security.Symbol, dateTime) {
// continue
//}

cs := q.newColumnSeries(latestDateTime.Unix(), eq)
tbk := io.NewTimeBucketKey(eq.Security.Symbol + "/" + q.Timeframe + "/TICK")
csm.AddColumnSeries(*tbk, cs)
Expand Down

0 comments on commit f7ff46c

Please sign in to comment.