forked from yonch/go-tdameritrade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstruments.go
54 lines (41 loc) · 1.1 KB
/
instruments.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
package tdameritrade
import (
"context"
"fmt"
)
func (s *InstrumentService) GetInstrument(ctx context.Context, cusip string) (*Instruments, *Response, error) {
if cusip == "" {
return nil, nil, fmt.Errorf("no cusip present")
}
u := fmt.Sprintf("instruments/%s", cusip)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
instruments := new(Instruments)
resp, err := s.client.Do(ctx, req, instruments)
if err != nil {
return nil, resp, err
}
return nil, nil, nil
}
func (s *InstrumentService) SearchInstruments(ctx context.Context, symbol, projection string) (*Instruments, *Response, error) {
u := "instruments"
if symbol == "" {
return nil, nil, fmt.Errorf("no symbol present")
}
if projection == "" {
projection = "symbol-search"
}
u = fmt.Sprintf("%s?symbol=%s&projection=%s", u, symbol, projection)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
instruments := new(Instruments)
resp, err := s.client.Do(ctx, req, instruments)
if err != nil {
return nil, resp, err
}
return instruments, resp, nil
}