This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
forked from andrewstuart/go-robinhood
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quote.go
39 lines (35 loc) · 1.42 KB
/
quote.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
package robinhood
import (
"context"
"strings"
)
// A Quote is a representation of the data returned by the Robinhood API for
// current stock quotes
type Quote struct {
AdjustedPreviousClose float64 `json:"adjusted_previous_close,string"`
AskPrice float64 `json:"ask_price,string"`
AskSize int `json:"ask_size"`
BidPrice float64 `json:"bid_price,string"`
BidSize int `json:"bid_size"`
LastExtendedHoursTradePrice float64 `json:"last_extended_hours_trade_price,string"`
LastTradePrice float64 `json:"last_trade_price,string"`
PreviousClose float64 `json:"previous_close,string"`
PreviousCloseDate string `json:"previous_close_date"`
Symbol string `json:"symbol"`
TradingHalted bool `json:"trading_halted"`
UpdatedAt string `json:"updated_at"`
}
// GetQuote returns all the latest stock quotes for the list of stocks provided
func (c *Client) GetQuote(ctx context.Context, stocks ...string) ([]Quote, error) {
url := EPQuotes + "?symbols=" + strings.Join(stocks, ",")
var r struct{ Results []Quote }
err := c.GetAndDecode(ctx, url, &r)
return r.Results, err
}
// Price returns the proper stock price even after hours
func (q Quote) Price() float64 {
if IsRegularTradingTime() {
return q.LastTradePrice
}
return q.LastExtendedHoursTradePrice
}