|
|
|
@ -22,7 +22,7 @@ const quotesURLv7QueryParts = `&range=1d&interval=5m&indicators=close&includeTim |
|
|
|
|
const noDataIndicator = `N/A` |
|
|
|
|
|
|
|
|
|
// Stock stores quote information for the particular stock ticker. The data
|
|
|
|
|
// for all the fields except 'Advancing' is fetched using Yahoo market API.
|
|
|
|
|
// for all the fields except 'Direction' is fetched using Yahoo market API.
|
|
|
|
|
type Stock struct { |
|
|
|
|
Ticker string `json:"symbol"` // Stock ticker.
|
|
|
|
|
LastTrade string `json:"regularMarketPrice"` // l1: last trade.
|
|
|
|
@ -42,7 +42,7 @@ type Stock struct { |
|
|
|
|
MarketCap string `json:"marketCap"` // j3: market cap real time.
|
|
|
|
|
MarketCapX string `json:"marketCap"` // j1: market cap (fallback when real time is N/A).
|
|
|
|
|
Currency string `json:"currency"` // String code for currency of stock.
|
|
|
|
|
Advancing bool // True when change is >= $0.
|
|
|
|
|
Direction int // -1 when change is < $0, 0 when change is = $0, 1 when change is > $0.
|
|
|
|
|
PreOpen string `json:"preMarketChangePercent,omitempty"` |
|
|
|
|
AfterHours string `json:"postMarketChangePercent,omitempty"` |
|
|
|
|
} |
|
|
|
@ -188,8 +188,13 @@ func (quotes *Quotes) parse2(body []byte) (*Quotes, error) { |
|
|
|
|
fmt.Println("-------------------") |
|
|
|
|
*/ |
|
|
|
|
adv, err := strconv.ParseFloat(quotes.stocks[i].Change, 64) |
|
|
|
|
quotes.stocks[i].Direction = 0 |
|
|
|
|
if err == nil { |
|
|
|
|
quotes.stocks[i].Advancing = adv >= 0.0 |
|
|
|
|
if adv < 0.0 { |
|
|
|
|
quotes.stocks[i].Direction = -1 |
|
|
|
|
} else if adv > 0.0 { |
|
|
|
|
quotes.stocks[i].Direction = 1 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return quotes, nil |
|
|
|
@ -202,7 +207,7 @@ func (quotes *Quotes) parse(body []byte) *Quotes { |
|
|
|
|
quotes.stocks = make([]Stock, len(lines)) |
|
|
|
|
//
|
|
|
|
|
// Get the total number of fields in the Stock struct. Skip the last
|
|
|
|
|
// Advanicing field which is not fetched.
|
|
|
|
|
// Advancing field which is not fetched.
|
|
|
|
|
//
|
|
|
|
|
fieldsCount := reflect.ValueOf(quotes.stocks[0]).NumField() - 1 |
|
|
|
|
//
|
|
|
|
@ -226,10 +231,17 @@ func (quotes *Quotes) parse(body []byte) *Quotes { |
|
|
|
|
quotes.stocks[i].MarketCap = quotes.stocks[i].MarketCapX |
|
|
|
|
} |
|
|
|
|
//
|
|
|
|
|
// Stock is advancing if the change is not negative (i.e. $0.00
|
|
|
|
|
// is also "advancing").
|
|
|
|
|
// Get the direction of the stock
|
|
|
|
|
//
|
|
|
|
|
quotes.stocks[i].Advancing = (quotes.stocks[i].Change[0:1] != `-`) |
|
|
|
|
adv, err := strconv.ParseFloat(quotes.stocks[i].Change, 64) |
|
|
|
|
quotes.stocks[i].Direction = 0 |
|
|
|
|
if err == nil { |
|
|
|
|
if adv < 0 { |
|
|
|
|
quotes.stocks[i].Direction = -1 |
|
|
|
|
} else if (adv > 0) { |
|
|
|
|
quotes.stocks[i].Direction = 1 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return quotes |
|
|
|
|