forked from yonch/go-tdameritrade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhours.go
56 lines (42 loc) · 1.14 KB
/
hours.go
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
55
56
package tdameritrade
import (
"context"
"fmt"
"time"
)
func (s *MarketHoursService) GetMarketHoursMulti(ctx context.Context, markets string, date time.Time) (*MarketHours, *Response, error) {
u := "marketdata/hours"
if markets == "" {
return nil, nil, fmt.Errorf("no markets present")
}
u = fmt.Sprintf("%s?markets=%s", u, markets)
if !date.IsZero() {
u = fmt.Sprintf("%s&date=%s", u, date.Format("2006-01-02"))
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
hours := new(MarketHours)
resp, err := s.client.Do(ctx, req, hours)
if err != nil {
return nil, resp, err
}
return hours, resp, nil
}
func (s *MarketHoursService) GetMarketHours(ctx context.Context, market string, date time.Time) (*MarketHours, *Response, error) {
u := fmt.Sprintf("marketdata/%s/hours", market)
if !date.IsZero() {
u = fmt.Sprintf("%s?date=%s", u, date.Format("2006-01-02"))
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
hours := new(MarketHours)
resp, err := s.client.Do(ctx, req, hours)
if err != nil {
return nil, resp, err
}
return hours, resp, nil
}