diff --git a/app_common.go b/app_common.go index 4f0f971..c6701d9 100644 --- a/app_common.go +++ b/app_common.go @@ -59,3 +59,6 @@ func (a App) ClsCalendar() []any { func (a App) SearchStock(words string) map[string]any { return data.NewSearchStockApi(words).SearchStock(5000) } +func (a App) GetHotStrategy() map[string]any { + return data.NewSearchStockApi("").HotStrategy() +} diff --git a/backend/data/search_stock_api.go b/backend/data/search_stock_api.go index a07e81d..41b5bfd 100644 --- a/backend/data/search_stock_api.go +++ b/backend/data/search_stock_api.go @@ -53,3 +53,20 @@ func (s SearchStockApi) SearchStock(pageSize int) map[string]any { //logger.SugaredLogger.Infof("resp:%+v", respMap["data"]) return respMap } + +func (s SearchStockApi) HotStrategy() map[string]any { + url := fmt.Sprintf("https://np-ipick.eastmoney.com/recommend/stock/heat/ranking?count=20&trace=%d&client=web&biz=web_smart_tag", time.Now().Unix()) + resp, err := resty.New().SetTimeout(time.Duration(30)*time.Second).R(). + SetHeader("Host", "np-ipick.eastmoney.com"). + SetHeader("Origin", "https://xuangu.eastmoney.com"). + SetHeader("Referer", "https://xuangu.eastmoney.com/"). + SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0"). + Get(url) + if err != nil { + logger.SugaredLogger.Errorf("HotStrategy-err:%+v", err) + return map[string]any{} + } + respMap := map[string]any{} + json.Unmarshal(resp.Body(), &respMap) + return respMap +} diff --git a/backend/data/search_stock_api_test.go b/backend/data/search_stock_api_test.go index 5102f3b..441c382 100644 --- a/backend/data/search_stock_api_test.go +++ b/backend/data/search_stock_api_test.go @@ -23,3 +23,14 @@ func TestSearchStock(t *testing.T) { //} } + +func TestSearchStockApi_HotStrategy(t *testing.T) { + db.Init("../../data/stock.db") + res := NewSearchStockApi("").HotStrategy() + logger.SugaredLogger.Infof("res:%+v", res) + dataList := res["data"].([]any) + for _, v := range dataList { + d := v.(map[string]any) + logger.SugaredLogger.Infof("v:%+v", d) + } +} diff --git a/frontend/src/components/SelectStock.vue b/frontend/src/components/SelectStock.vue index f52a0fa..80adc7b 100644 --- a/frontend/src/components/SelectStock.vue +++ b/frontend/src/components/SelectStock.vue @@ -1,11 +1,13 @@