@@ -15,36 +15,17 @@ import (
15
15
"github.com/alpacahq/marketstore/v4/utils/log"
16
16
)
17
17
18
- const (
19
- // XigniteBaseURL is a Base URL for Quick Xignite API
20
- // (https://www.marketdata-cloud.quick-co.jp/Products/)
21
- XigniteBaseURL = "https://api.marketdata-cloud.quick-co.jp"
22
- // GetQuotesURL is the URL of Get Quotes endpoint
23
- // (https://www.marketdata-cloud.quick-co.jp/Products/QUICKEquityRealTime/Overview/GetQuotes)
24
- GetQuotesURL = XigniteBaseURL + "/QUICKEquityRealTime.json/GetQuotes"
25
- // ListSymbolsURL is the URL of List symbols endpoint
26
- // (https://www.marketdata-cloud.quick-co.jp/Products/QUICKEquityRealTime/Overview/ListSymbols)
27
- ListSymbolsURL = XigniteBaseURL + "/QUICKEquityRealTime.json/ListSymbols"
28
- // ListIndexSymbolsURL is the URL of List symbols endpoint
29
- // (https://www.marketdata-cloud.quick-co.jp/Products/QUICKIndexHistorical/Overview/ListSymbols)
30
- // /QUICKEquityRealTime.json/ListSymbols : list symbols for a exchange
31
- // /QUICKIndexHistorical.json/ListSymbols : list index symbols for an index group (ex. TOPIX).
32
- ListIndexSymbolsURL = XigniteBaseURL + "/QUICKIndexHistorical.json/ListSymbols"
33
- // GetBarsURL is the URL of Get Bars endpoint
34
- // (https://www.marketdata-cloud.quick-co.jp/Products/QUICKEquityRealTime/Overview/GetBars)
35
- GetBarsURL = XigniteBaseURL + "/QUICKEquityRealTime.json/GetBars"
36
- // GetIndexBarsURL is the URL of QuickIndexRealTime/GetBars endpoint
37
- // (https://www.marketdata-cloud.quick-co.jp/Products/QUICKIndexRealTime/Overview/GetBars)
38
- GetIndexBarsURL = XigniteBaseURL + "/QUICKIndexRealTime.json/GetBars"
39
- // GetQuotesRangeURL is the URL of Get Quotes Range endpoint
40
- // (https://www.marketdata-cloud.quick-co.jp/Products/QUICKEquityHistorical/Overview/GetQuotesRange)
41
- GetQuotesRangeURL = XigniteBaseURL + "/QUICKEquityHistorical.json/GetQuotesRange"
42
- // GetIndexQuotesRangeURL is the URL of Get Index Quotes Range endpoint
43
- // (https://www.marketdata-cloud.quick-co.jp/Products/QUICKIndexHistorical/Overview/GetQuotesRange)
44
- GetIndexQuotesRangeURL = XigniteBaseURL + "/QUICKIndexHistorical.json/GetQuotesRange"
45
-
46
- SuccessOutcome = "Success"
47
- )
18
+ const SuccessOutcome = "Success"
19
+
20
+ type Endpoints struct {
21
+ EquityRealTimeGetQuotes string
22
+ EquityRealTimeListSymbols string
23
+ EquityRealTimeGetBars string
24
+ EquityHistoricalGetQuotesRange string
25
+ IndexRealTimeGetBars string
26
+ IndexHistoricalListSymbols string
27
+ IndexHistoricalGetQuotesRange string
28
+ }
48
29
49
30
// Client calls an endpoint and returns the parsed response.
50
31
type Client interface {
@@ -62,17 +43,21 @@ type Client interface {
62
43
}
63
44
64
45
// NewDefaultAPIClient initializes Xignite API client with the specified API token and HTTP timeout[sec].
65
- func NewDefaultAPIClient (token string , timeoutSec int ) * DefaultClient {
46
+ func NewDefaultAPIClient (token string , timeoutSec int , baseURL string , endpoints Endpoints ) * DefaultClient {
66
47
return & DefaultClient {
67
48
httpClient : & http.Client {Timeout : time .Duration (timeoutSec ) * time .Second },
68
49
token : token ,
50
+ baseURL : baseURL ,
51
+ endpoints : endpoints ,
69
52
}
70
53
}
71
54
72
55
// DefaultClient is the Xignite API client with a default http client.
73
56
type DefaultClient struct {
74
57
httpClient * http.Client
75
58
token string
59
+ baseURL string
60
+ endpoints Endpoints
76
61
}
77
62
78
63
// GetRealTimeQuotes calls GetQuotes endpoint of Xignite API with specified identifiers
@@ -86,7 +71,8 @@ func (c *DefaultClient) GetRealTimeQuotes(ctx context.Context, identifiers []str
86
71
"Identifiers" : {strings .Join (identifiers , "," )},
87
72
}
88
73
req , err := http .NewRequestWithContext (ctx ,
89
- "POST" , GetQuotesURL , strings .NewReader (form .Encode ()))
74
+ "POST" , fmt .Sprintf ("%s%s" , c .baseURL , c .endpoints .EquityRealTimeGetQuotes ),
75
+ strings .NewReader (form .Encode ()))
90
76
if err != nil {
91
77
return response , errors .Wrap (err , "failed to create an http request" )
92
78
}
@@ -121,7 +107,8 @@ func (c *DefaultClient) GetRealTimeQuotes(ctx context.Context, identifiers []str
121
107
// https://www.marketdata-cloud.quick-co.jp/Products/QUICKEquityRealTime/Overview/ListSymbols
122
108
// exchange: XTKS, XNGO, XSAP, XFKA, XJAS, XTAM
123
109
func (c * DefaultClient ) ListSymbols (ctx context.Context , exchange string ) (response ListSymbolsResponse , err error ) {
124
- apiURL := ListSymbolsURL + fmt .Sprintf ("?_token=%s&Exchange=%s" , c .token , exchange )
110
+ apiURL := fmt .Sprintf ("%s%s?_token=%s&Exchange=%s" ,
111
+ c .baseURL , c .endpoints .EquityRealTimeListSymbols , c .token , exchange )
125
112
req , err := http .NewRequestWithContext (ctx , "GET" , apiURL , http .NoBody )
126
113
if err != nil {
127
114
return response , errors .Wrap (err , "failed to create an http request" )
@@ -145,7 +132,8 @@ func (c *DefaultClient) ListSymbols(ctx context.Context, exchange string) (respo
145
132
// indexGroup: INDXJPX, IND_NIKKEI.
146
133
func (c * DefaultClient ) ListIndexSymbols (ctx context.Context , indexGroup string ,
147
134
) (response ListIndexSymbolsResponse , err error ) {
148
- apiURL := ListIndexSymbolsURL + fmt .Sprintf ("?_token=%s&GroupName=%s" , c .token , indexGroup )
135
+ apiURL := fmt .Sprintf ("%s%s?_token=%s&GroupName=%s" ,
136
+ c .baseURL , c .endpoints .IndexHistoricalListSymbols , c .token , indexGroup )
149
137
req , err := http .NewRequestWithContext (ctx , "GET" , apiURL , http .NoBody )
150
138
if err != nil {
151
139
return response , errors .Wrap (err , "failed to create an http request" )
@@ -182,7 +170,8 @@ func getBarsURLValues(token, identifier string, start, end time.Time) url.Values
182
170
func (c * DefaultClient ) GetRealTimeBars (ctx context.Context , identifier string , start , end time.Time ,
183
171
) (response GetBarsResponse , err error ) {
184
172
form := getBarsURLValues (c .token , identifier , start , end )
185
- req , err := getBarsRequest (ctx , GetBarsURL , form .Encode ())
173
+ req , err := getBarsRequest (ctx , fmt .Sprintf ("%s%s" , c .baseURL , c .endpoints .EquityRealTimeGetBars ),
174
+ form .Encode ())
186
175
if err != nil {
187
176
return response , err
188
177
}
@@ -202,7 +191,8 @@ func (c *DefaultClient) GetRealTimeBars(ctx context.Context, identifier string,
202
191
func (c * DefaultClient ) GetIndexBars (ctx context.Context , identifier string , start , end time.Time ,
203
192
) (response GetIndexBarsResponse , err error ) {
204
193
form := getBarsURLValues (c .token , identifier , start , end )
205
- req , err := getBarsRequest (ctx , GetIndexBarsURL , form .Encode ())
194
+ req , err := getBarsRequest (ctx , fmt .Sprintf ("%s%s" , c .baseURL , c .endpoints .IndexRealTimeGetBars ),
195
+ form .Encode ())
206
196
if err != nil {
207
197
return response , err
208
198
}
@@ -233,7 +223,8 @@ func getBarsRequest(ctx context.Context, url, body string) (*http.Request, error
233
223
func (c * DefaultClient ) GetQuotesRange (ctx context.Context , identifier string , startDate , endDate time.Time ,
234
224
) (response GetQuotesRangeResponse , err error ) {
235
225
formValues := quotesRangeFormValues (c .token , identifier , startDate , endDate )
236
- req , err := quotesRangeReq (ctx , GetQuotesRangeURL , formValues .Encode ())
226
+ req , err := quotesRangeReq (ctx , fmt .Sprintf ("%s%s" , c .baseURL , c .endpoints .EquityHistoricalGetQuotesRange ),
227
+ formValues .Encode ())
237
228
if err != nil {
238
229
return response , err
239
230
}
@@ -257,7 +248,8 @@ func (c *DefaultClient) GetQuotesRange(ctx context.Context, identifier string, s
257
248
func (c * DefaultClient ) GetIndexQuotesRange (ctx context.Context , identifier string , startDate , endDate time.Time ,
258
249
) (response GetIndexQuotesRangeResponse , err error ) {
259
250
formValues := quotesRangeFormValues (c .token , identifier , startDate , endDate )
260
- req , err := quotesRangeReq (ctx , GetIndexQuotesRangeURL , formValues .Encode ())
251
+ req , err := quotesRangeReq (ctx , fmt .Sprintf ("%s%s" , c .baseURL , c .endpoints .IndexHistoricalGetQuotesRange ),
252
+ formValues .Encode ())
261
253
if err != nil {
262
254
return response , err
263
255
}
0 commit comments