|
|
|
@ -128,6 +128,10 @@ type Watchlist struct { |
|
|
|
|
Watchlist []WatchlistItem `json:"watchlist"` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (quotes *Quotes) Setquotes(){ |
|
|
|
|
quotes.market.quotes = quotes |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Fetch the latest stock quotes and parse raw fetched data into array of
|
|
|
|
|
// []Stock structs.
|
|
|
|
|
func (quotes *Quotes) Fetch() (self *Quotes) { |
|
|
|
@ -618,6 +622,42 @@ func (quotes* Quotes) ResetforNewday(watchlist *Watchlist) { |
|
|
|
|
quotes.totalstocks = quotes.totalstocks[:0] |
|
|
|
|
quotes.watchlist = watchlist |
|
|
|
|
quotes.upstocks = map[string]string{} |
|
|
|
|
log.Println("here we retrieve data :", quotes.watchlist.Baseon) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (quotes* Quotes) getemotionindex(res map[string]*stock.Stock) (float64, int) { |
|
|
|
|
avgpercent := 100.0 |
|
|
|
|
avgcount := 0 |
|
|
|
|
array_percent := []float64{} |
|
|
|
|
|
|
|
|
|
wamap := make(map[string]WatchlistItem, len(quotes.watchlist.Watchlist)) |
|
|
|
|
for _, item := range quotes.watchlist.Watchlist { |
|
|
|
|
if _, ok := res[item.Scode]; ok { |
|
|
|
|
wamap[item.Scode] = item |
|
|
|
|
} |
|
|
|
|
//fmt.Println(scodes)
|
|
|
|
|
} |
|
|
|
|
for _, sitem := range quotes.totalstocks { |
|
|
|
|
if inlist(quotes.profile.Tickers, sitem.Scode) == false { |
|
|
|
|
scode := sitem.Scode |
|
|
|
|
q := res[scode].Market |
|
|
|
|
|
|
|
|
|
if _, ok := wamap[scode]; ok { |
|
|
|
|
strprice, _ := strconv.ParseFloat(wamap[scode].Enterprice, 64) |
|
|
|
|
stdchangepercent := q.LastPrice*100 / strprice |
|
|
|
|
avgcount++ |
|
|
|
|
avgpercent += stdchangepercent |
|
|
|
|
array_percent = append(array_percent, stdchangepercent) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if avgcount > 0 { |
|
|
|
|
log.Println(avgpercent, avgcount) |
|
|
|
|
//log.Println(array_percent)
|
|
|
|
|
avgpercent = avgpercent / float64(avgcount) |
|
|
|
|
//quotes.stocks[0].High52 = float2Str(avgpercent)
|
|
|
|
|
} |
|
|
|
|
return avgpercent, avgcount |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// this will parse the json objects
|
|
|
|
@ -646,23 +686,12 @@ func (quotes *Quotes) parse2(body []byte, res map[string]*stock.Stock) (*Quotes, |
|
|
|
|
//fmt.Println(scodes)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, item := range quotes.addedstocks {//special stock to trace
|
|
|
|
|
if _, ok := res[item]; ok { |
|
|
|
|
q := res[item].Market |
|
|
|
|
if q.LastPrice>=q.PreClose*1.02 || q.LastPrice<=q.PreClose*0.98 { |
|
|
|
|
scodes = append(scodes, item) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, item := range quotes.profile.Tickers {//profile stock to trace
|
|
|
|
|
if _, ok := res[item]; ok { |
|
|
|
|
scodes = append(scodes, item) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//scodes = append(scodes, quotes.profile.Tickers...)
|
|
|
|
|
//fmt.Println(scodes)
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
var snames []string |
|
|
|
|
quotes.stocks = make([]Stock, len(scodes))
|
|
|
|
|
//fmt.Println(res["sh600000"])
|
|
|
|
@ -746,21 +775,6 @@ func (quotes *Quotes) parse2(body []byte, res map[string]*stock.Stock) (*Quotes, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//quotes.stocks[0].PeRatio = result["trailingPE"]
|
|
|
|
|
/* |
|
|
|
|
// TODO calculate rt
|
|
|
|
|
quotes.stocks[0].PeRatioX = result["trailingPE"] |
|
|
|
|
quotes.stocks[0].Dividend = result["trailingAnnualDividendRate"] |
|
|
|
|
quotes.stocks[0].Yield = result["trailingAnnualDividendYield"] |
|
|
|
|
quotes.stocks[0].MarketCap = result["marketCap"] |
|
|
|
|
// TODO calculate rt?
|
|
|
|
|
quotes.stocks[0].MarketCapX = result["marketCap"] |
|
|
|
|
quotes.stocks[0].Currency = result["currency"] |
|
|
|
|
quotes.stocks[0].PreOpen = result["preMarketChangePercent"] |
|
|
|
|
quotes.stocks[0].AfterHours = result["postMarketChangePercent"] |
|
|
|
|
*/ |
|
|
|
|
//fmt.Println(quotes)
|
|
|
|
|
|
|
|
|
|
return quotes, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|