-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtickers.go
More file actions
44 lines (38 loc) · 1.17 KB
/
Copy pathtickers.go
File metadata and controls
44 lines (38 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package marketstack
import (
"context"
"fmt"
)
type TickersOptions struct {
Search string `url:"search,omitempty"`
Exchange string `url:"exchange,omitempty"`
Limit int `url:"limit,omitempty"`
Offset int `url:"offset,omitempty"`
}
type TickersResponse struct {
Pagination Pagination `json:"pagination"`
Data []Ticker `json:"data"`
}
type TickerResponse struct {
Name string `json:"name"`
Symbol string `json:"symbol"`
HasIntraday bool `json:"has_intraday"`
HasEOD bool `json:"has_eod"`
Country string `json:"country"`
StockExchange *StockExchange `json:"stock_exchange"`
}
func (c *Client) GetTickers(ctx context.Context, opts *TickersOptions) (*TickersResponse, error) {
var result TickersResponse
if err := c.doRequest(ctx, "/tickers", opts, &result); err != nil {
return nil, err
}
return &result, nil
}
func (c *Client) GetTicker(ctx context.Context, symbol string) (*TickerResponse, error) {
var result TickerResponse
endpoint := fmt.Sprintf("/tickers/%s", symbol)
if err := c.doRequest(ctx, endpoint, nil, &result); err != nil {
return nil, err
}
return &result, nil
}