发送stock信息到自动评估系统

master
yg070520@sina.com 1 year ago
parent 45fd0aba2e
commit 590a97559e
  1. 35
      yahoo_quotes.go

@ -462,6 +462,32 @@ func (quotes *Quotes) Sendstockgraphreq(index interface{}, istime bool) {
token.Wait()
}
func (quotes *Quotes) sendstockforevaluation(selcode string, datestring string, buyp string, pcp string) {
topic := "astock/candistock"
itemsel := quotes.getitembyscode(selcode)
data := map[string]interface{}{
"scode": selcode,//quotes.totalstocks[index-1].Scode,
"tier": 0,
"daysback": itemsel.Daysback,
"stdprice": itemsel.Enterprice,
"name": quotes.res[selcode].Base.Name, //strings.TrimSpace(quotes.totalstocks[index-1].Sname),
"ed": itemsel.AnalyseDay,
}
data["time"] = datestring
data["buyp"] = buyp
data["pcp"] = pcp
jsonData, err := json.Marshal(data)
if err != nil {
fmt.Println(err)
}
message := string(jsonData)
token := quotes.client.Publish(topic, 0, false, message)
token.Wait()
}
func (quotes *Quotes) Getselectedinfo(index int) *Stock {
if index > len(quotes.stocks) || index < 1 {
return nil
@ -696,6 +722,7 @@ func (quotes *Quotes) parse2(body []byte, res map[string]*stock.Stock) (*Quotes,
quotes.stocks = make([]Stock, len(scodes))
//fmt.Println(res["sh600000"])
for i, scode := range scodes {
newadd := 0
q := res[scode].Market
b := res[scode].Base
//fmt.Println(q)
@ -704,6 +731,7 @@ func (quotes *Quotes) parse2(body []byte, res map[string]*stock.Stock) (*Quotes,
if isin == false {
quotes.totalstocks = append(quotes.totalstocks, stockinfo{scode, q.Name, q.Time, q.Time})
quotes.upstocks[scode] = q.Time
newadd = 1
}else {
//compare uptime and a string as time, if the diff is bigger than 1 hour, then change quotes.upstocks[scode] to q.Time
@ -766,12 +794,13 @@ func (quotes *Quotes) parse2(body []byte, res map[string]*stock.Stock) (*Quotes,
stdchange := q.LastPrice - strprice
quotes.stocks[i].Change = float2Str(stdchange)
//quotes.stocks[i].PreOpen = wamap[scode].Enterprice
//quotes.stocks[i].AfterHours = strconv.Itoa(wamap[scode].Daysback)
//quotes.stocks[i].Yield = wamap[scode].AnalyseDay
}
if inlist(quotes.profile.Tickers, scode) == true {
quotes.stocks[i].AvgVolume = "M"
} else if newadd == 1 {
strprice, _ := strconv.ParseFloat(wamap[scode].Enterprice, 64)
pcp := ((strprice - q.PreClose) / q.PreClose) * 100
quotes.sendstockforevaluation(scode, quotes.upstocks[scode], float2Str(q.LastPrice), float2Str(pcp))
}
}

Loading…
Cancel
Save