From 590a97559eeab48d44bb71e251369a7785a1bb80 Mon Sep 17 00:00:00 2001 From: "yg070520@sina.com" Date: Fri, 21 Jul 2023 16:27:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E9=80=81stock=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=88=B0=E8=87=AA=E5=8A=A8=E8=AF=84=E4=BC=B0=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yahoo_quotes.go | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/yahoo_quotes.go b/yahoo_quotes.go index 60892c0..2a9894f 100644 --- a/yahoo_quotes.go +++ b/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)) } }