diff --git a/contrib/xignitefeeder/api/client.go b/contrib/xignitefeeder/api/client.go index 0469cab56..44560af49 100644 --- a/contrib/xignitefeeder/api/client.go +++ b/contrib/xignitefeeder/api/client.go @@ -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) @@ -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 @@ -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) { @@ -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 diff --git a/contrib/xignitefeeder/api/model.go b/contrib/xignitefeeder/api/model.go index 6fb5c17a6..ab80ffd4e 100644 --- a/contrib/xignitefeeder/api/model.go +++ b/contrib/xignitefeeder/api/model.go @@ -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 @@ -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"` @@ -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"` @@ -129,7 +124,6 @@ type Index struct { Symbol string `json:"Symbol"` } -// -------------------------- type GetBarsResponse struct { Outcome string `json:"Outcome"` DelaySec float32 `json:"Delay"` @@ -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"` @@ -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"` @@ -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"` diff --git a/contrib/xignitefeeder/configs/config.go b/contrib/xignitefeeder/configs/config.go index 2e61c3936..a8a348e97 100644 --- a/contrib/xignitefeeder/configs/config.go +++ b/contrib/xignitefeeder/configs/config.go @@ -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 diff --git a/contrib/xignitefeeder/internal/mocks.go b/contrib/xignitefeeder/internal/mocks.go index faf0b6ad2..1ba52d118 100644 --- a/contrib/xignitefeeder/internal/mocks.go +++ b/contrib/xignitefeeder/internal/mocks.go @@ -7,8 +7,6 @@ import ( "github.com/alpacahq/marketstore/v4/utils/io" ) -// ---------------- - // MockSymbolsManager is a no-op SymbolsManager type MockSymbolsManager struct { Identifiers []string @@ -20,33 +18,31 @@ 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{}, @@ -54,54 +50,48 @@ func (mac *MockAPIClient) GetRealTimeBars(identifier string, start, end time.Tim } // 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 diff --git a/contrib/xignitefeeder/symbols/manager.go b/contrib/xignitefeeder/symbols/manager.go index 68a86d143..fa6518563 100644 --- a/contrib/xignitefeeder/symbols/manager.go +++ b/contrib/xignitefeeder/symbols/manager.go @@ -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 } diff --git a/contrib/xignitefeeder/test/integ/tests/text.py b/contrib/xignitefeeder/test/integ/tests/text.py deleted file mode 100644 index 168af0f9b..000000000 --- a/contrib/xignitefeeder/test/integ/tests/text.py +++ /dev/null @@ -1,9 +0,0 @@ -#-*- coding:utf-8 -*- - -if __name__ == "__main__": - g = open("/Users/dakimura/go/src/github.com/dakimura/marketstore/contrib/xignitefeeder/test/integ/tests/historical_stocks_20190606.txt", "w") - with open("/Users/dakimura/go/src/github.com/dakimura/marketstore/contrib/xignitefeeder/test/integ/tests/st.txt", "r") as f: - for line in f: - sym = line.split("/")[9] - g.write(sym +"\n") - g.close() \ No newline at end of file diff --git a/contrib/xignitefeeder/writer/quotes_writer.go b/contrib/xignitefeeder/writer/quotes_writer.go index 7485f0539..b0aff2b3e 100644 --- a/contrib/xignitefeeder/writer/quotes_writer.go +++ b/contrib/xignitefeeder/writer/quotes_writer.go @@ -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)