-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexchanges.go
More file actions
54 lines (48 loc) · 1.39 KB
/
Copy pathexchanges.go
File metadata and controls
54 lines (48 loc) · 1.39 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
45
46
47
48
49
50
51
52
53
54
package marketstack
import (
"context"
"fmt"
)
type ExchangesOptions struct {
Search string `url:"search,omitempty"`
Limit int `url:"limit,omitempty"`
Offset int `url:"offset,omitempty"`
}
type ExchangesResponse struct {
Pagination Pagination `json:"pagination"`
Data []StockExchange `json:"data"`
}
type ExchangeResponse struct {
Name string `json:"name"`
Acronym string `json:"acronym"`
MIC string `json:"mic"`
Country string `json:"country"`
CountryCode string `json:"country_code"`
City string `json:"city"`
Website string `json:"website"`
Timezone struct {
Timezone string `json:"timezone"`
Abbr string `json:"abbr"`
AbbrDST string `json:"abbr_dst"`
} `json:"timezone"`
Currency struct {
Code string `json:"code"`
Symbol string `json:"symbol"`
Name string `json:"name"`
} `json:"currency"`
}
func (c *Client) GetExchanges(ctx context.Context, opts *ExchangesOptions) (*ExchangesResponse, error) {
var result ExchangesResponse
if err := c.doRequest(ctx, "/exchanges", opts, &result); err != nil {
return nil, err
}
return &result, nil
}
func (c *Client) GetExchange(ctx context.Context, mic string) (*ExchangeResponse, error) {
var result ExchangeResponse
endpoint := fmt.Sprintf("/exchanges/%s", mic)
if err := c.doRequest(ctx, endpoint, nil, &result); err != nil {
return nil, err
}
return &result, nil
}