forked from zricethezav/go-tdameritrade
-
Notifications
You must be signed in to change notification settings - Fork 28
/
quotes.go
92 lines (80 loc) · 3.86 KB
/
quotes.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package tdameritrade
import (
"context"
"fmt"
)
// QuotesService handles communication with the marketdata related methods of
// the TDAmeritrade API.
//
// TDAmeritrade API docs: https://developer.tdameritrade.com/quotes/apis
type QuotesService struct {
client *Client
}
type Quotes map[string]*Quote
type Quote struct {
AssetType string `json:"assetType"`
AssetMainType string `json:"assetMainType"`
Cusip string `json:"cusip"`
AssetSubType string `json:"assetSubType"`
Symbol string `json:"symbol"`
Description string `json:"description"`
BidPrice float64 `json:"bidPrice"`
BidSize float64 `json:"bidSize"`
BidID string `json:"bidId"`
AskPrice float64 `json:"askPrice"`
AskSize float64 `json:"askSize"`
AskID string `json:"askId"`
LastPrice float64 `json:"lastPrice"`
LastSize float64 `json:"lastSize"`
LastID string `json:"lastId"`
OpenPrice float64 `json:"openPrice"`
HighPrice float64 `json:"highPrice"`
LowPrice float64 `json:"lowPrice"`
BidTick string `json:"bidTick"`
ClosePrice float64 `json:"closePrice"`
NetChange float64 `json:"netChange"`
TotalVolume float64 `json:"totalVolume"`
QuoteTimeInLong int64 `json:"quoteTimeInLong"`
TradeTimeInLong int64 `json:"tradeTimeInLong"`
Mark float64 `json:"mark"`
Exchange string `json:"exchange"`
ExchangeName string `json:"exchangeName"`
Marginable bool `json:"marginable"`
Shortable bool `json:"shortable"`
Volatility float64 `json:"volatility"`
Digits int `json:"digits"`
Five2WkHigh float64 `json:"52WkHigh"`
Five2WkLow float64 `json:"52WkLow"`
NAV float64 `json:"nAV"`
PeRatio float64 `json:"peRatio"`
DivAmount float64 `json:"divAmount"`
DivYield float64 `json:"divYield"`
DivDate string `json:"divDate"`
SecurityStatus string `json:"securityStatus"`
RegularMarketLastPrice float64 `json:"regularMarketLastPrice"`
RegularMarketLastSize int `json:"regularMarketLastSize"`
RegularMarketNetChange float64 `json:"regularMarketNetChange"`
RegularMarketTradeTimeInLong int64 `json:"regularMarketTradeTimeInLong"`
NetPercentChangeInDouble float64 `json:"netPercentChangeInDouble"`
MarkChangeInDouble float64 `json:"markChangeInDouble"`
MarkPercentChangeInDouble float64 `json:"markPercentChangeInDouble"`
RegularMarketPercentChangeInDouble float64 `json:"regularMarketPercentChangeInDouble"`
Delayed bool `json:"delayed"`
}
func (s *QuotesService) GetQuotes(ctx context.Context, symbols string) (*Quotes, *Response, error) {
u := fmt.Sprintf("marketdata/quotes")
if symbols == "" {
return nil, nil, fmt.Errorf("no symbols present")
}
u = fmt.Sprintf("%s?symbol=%s", u, symbols)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
quotes := new(Quotes)
resp, err := s.client.Do(ctx, req, quotes)
if err != nil {
return nil, resp, err
}
return quotes, resp, nil
}