Skip to content

Commit

Permalink
个股检测中添加近40日主力资金净流入
Browse files Browse the repository at this point in the history
  • Loading branch information
axiaoxin committed Jul 24, 2021
1 parent 2eb7eaf commit 9277a43
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 137 deletions.
38 changes: 38 additions & 0 deletions datacenter/zszx/net_inflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,44 @@ type NetInflow struct {
// NetInflowList 净流入详情列表
type NetInflowList []NetInflow

func (n NetInflowList) String() string {
ctx := context.Background()
netInflowsLen := len(n)
netInflow3days := "--"
if netInflowsLen >= 3 {
netInflow3days = fmt.Sprintf("近3日主力资金净流入:%.2f万元", n[:3].SumMainNetIn(ctx))
}
netInflow5days := "--"
if netInflowsLen >= 5 {
netInflow5days = fmt.Sprintf("近5日主力资金净流入:%.2f万元", n[:5].SumMainNetIn(ctx))
}
netInflow10days := "--"
if netInflowsLen >= 10 {
netInflow10days = fmt.Sprintf("近10日主力资金净流入:%.2f万元", n[:10].SumMainNetIn(ctx))
}
netInflow20days := "--"
if netInflowsLen >= 20 {
netInflow20days = fmt.Sprintf("近20日主力资金净流入:%.2f万元", n[:20].SumMainNetIn(ctx))
}
netInflow30days := "--"
if netInflowsLen >= 30 {
netInflow30days = fmt.Sprintf("近30日主力资金净流入:%.2f万元", n[:30].SumMainNetIn(ctx))
}
netInflow40days := "--"
if netInflowsLen >= 40 {
netInflow40days = fmt.Sprintf("近40日主力资金净流入:%.2f万元", n[:40].SumMainNetIn(ctx))
}
return fmt.Sprintf(
"%s</br>%s</br>%s</br>%s</br>%s</br>%s",
netInflow3days,
netInflow5days,
netInflow10days,
netInflow20days,
netInflow30days,
netInflow40days,
)
}

// SumMainNetIn 主力净流入列表求和
func (n NetInflowList) SumMainNetIn(ctx context.Context) float64 {
var netFlowin float64 = 0.0
Expand Down
22 changes: 1 addition & 21 deletions models/exportor_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package models

import (
"context"
"fmt"
"sort"
"strings"

Expand Down Expand Up @@ -172,25 +171,6 @@ func NewExportorData(ctx context.Context, stock Stock) ExportorData {
return ExportorData{}
}

netInflowsLen := len(stock.MainMoneyNetInflows)
netInflow3days := "--"
if netInflowsLen >= 3 {
netInflow3days = fmt.Sprintf("近3日主力资金净流入:%.2f万元", stock.MainMoneyNetInflows[:3].SumMainNetIn(ctx))
}
netInflow5days := "--"
if netInflowsLen >= 5 {
netInflow5days = fmt.Sprintf("近5日主力资金净流入:%.2f万元", stock.MainMoneyNetInflows[:5].SumMainNetIn(ctx))
}
netInflow10days := "--"
if netInflowsLen >= 10 {
netInflow10days = fmt.Sprintf("近10日主力资金净流入:%.2f万元", stock.MainMoneyNetInflows[:10].SumMainNetIn(ctx))
}
netInflow20days := "--"
if netInflowsLen >= 20 {
netInflow20days = fmt.Sprintf("近20日主力资金净流入:%.2f万元", stock.MainMoneyNetInflows[:20].SumMainNetIn(ctx))
}
mainNetInflows := fmt.Sprintf("%s</br>%s</br>%s</br>%s", netInflow3days, netInflow5days, netInflow10days, netInflow20days)

fina := stock.HistoricalFinaMainData[0]
return ExportorData{
Name: stock.BaseInfo.SecurityNameAbbr,
Expand Down Expand Up @@ -266,7 +246,7 @@ func NewExportorData(ctx context.Context, stock Stock) ExportorData {
NetcashFinance: goutils.YiWanString(stock.NetcashFinance),
NetcashFree: goutils.YiWanString(stock.NetcashFree),
FreeHoldersTop10: stock.FreeHoldersTop10.String(),
MainMoneyNetInflows: mainNetInflows,
MainMoneyNetInflows: stock.MainMoneyNetInflows.String(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions models/stock.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,15 @@ func NewStock(ctx context.Context, baseInfo eastmoney.StockInfo) (Stock, error)
s.FreeHoldersTop10 = holders
}(ctx, s)

// 获取最近30日的主力资金净流入
// 获取最近60日的主力资金净流入
wg.Add(1)
go func(ctx context.Context, s *Stock) {
defer func() {
wg.Done()
}()
now := time.Now()
end := now.Format("2006-01-02")
d, _ := time.ParseDuration("-720h")
d, _ := time.ParseDuration("-1440h")
start := now.Add(d).Format("2006-01-02")
inflows, err := datacenter.Zszx.QueryMainMoneyNetInflows(ctx, s.BaseInfo.Secucode, start, end)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ func Routes(app *gin.Engine) {
app.GET("/", StockIndex)
app.POST("/selector", StockSelector)
app.POST("/checker", StockChecker)
app.POST("/chip", StockChip)
app.GET("/fund", FundIndex)
app.GET("/fund/filter", FundFilter)
app.POST("/fund/check", FundCheck)
Expand Down
44 changes: 3 additions & 41 deletions routes/stock.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func StockChecker(c *gin.Context) {
finaReportNames := []string{}
finaAppointPublishDates := []string{}
lines := [][]gin.H{}
mainInflows := []string{}

type dataset struct {
Label string `json:"label"`
Expand All @@ -131,6 +132,7 @@ func StockChecker(c *gin.Context) {
results = append(results, result)
stockName := fmt.Sprintf("%s-%s", stock.BaseInfo.SecurityNameAbbr, stock.BaseInfo.Secucode)
stockNames = append(stockNames, stockName)
mainInflows = append(mainInflows, stock.MainMoneyNetInflows.String())

finaReportName := ""
if len(stock.HistoricalFinaMainData) > 0 {
Expand Down Expand Up @@ -247,47 +249,7 @@ func StockChecker(c *gin.Context) {
data["FinaReportNames"] = finaReportNames
data["FinaAppointPublishDates"] = finaAppointPublishDates
data["Lines"] = lines
c.JSON(http.StatusOK, data)
return
}

// ParamStockChip StockChip 请求参数
type ParamStockChip struct {
Keyword string `json:"keyword" form:"keyword"`
}

// StockChip 筹码面
func StockChip(c *gin.Context) {
data := gin.H{
"Env": viper.GetString("env"),
"Version": version.Version,
"PageTitle": "X-STOCK | 股票 | 筹码面",
"Error": "",
}
param := ParamStockChip{}
if err := c.ShouldBind(&param); err != nil {
data["Error"] = err.Error()
c.JSON(http.StatusOK, data)
return
}
if param.Keyword == "" {
data["Error"] = "请填写股票代码或简称"
c.JSON(http.StatusOK, data)
return
}
keywords := goutils.SplitStringFields(param.Keyword)
searcher := core.NewSearcher(c)
stocks, err := searcher.SearchStocks(c, keywords)
if err != nil {
data["Error"] = err.Error()
c.JSON(http.StatusOK, data)
return
}
mainNetInflows := gin.H{}
for _, stock := range stocks {
mainNetInflows[stock.BaseInfo.Secucode] = stock.MainMoneyNetInflows
}
data["MainMoneyNetInflows"] = mainNetInflows
data["MainMoneyNetInflows"] = mainInflows
c.JSON(http.StatusOK, data)
return
}
19 changes: 0 additions & 19 deletions statics/html/stock_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<ul class="tabs">
<li class="tab col s6"><a class="active" href="#checker">个股检测</a></li>
<li class="tab col s6"><a href="#selector">基本面选股</a></li>
<li class="tab col s6"><a href="#chip">筹码面</a></li>
</ul>
</div>

Expand Down Expand Up @@ -261,24 +260,6 @@
</div>
</div>
<!--selector end-->

<!-- 筹码面 start -->
<div id="chip" class="col s12">
<div class="row">
<form class="col s12" id="chip_form">
<div class="row">
<div class="input-field col s12">
<textarea id="keyword" name="keyword" class="materialize-textarea validate" required></textarea>
<label for="keyword">输入股票代码或简称</label>
</div>
</div>
<div class="row">
<a class="btn waves-effect waves-light red lighten-2 col s12" id="chip_btn" >查询</a>
</div>
</form>
</div>
</div>
<!-- 筹码面 end -->
</div>

{{ template "modal" . }}
Expand Down
58 changes: 5 additions & 53 deletions statics/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ $(document).ready(function () {
"</td></tr>"
);
});
$("#checker_result_" + i + " tbody").append(
"<tr><td>主力资金净流入</td><td>" +
data.MainMoneyNetInflows[i] +
"</td><td>--</td></tr>"
);
$("#checker_result_" + i).append(
'<div class="row">' +
'</br><h5 class="center">年报数据趋势概览</h5>' +
Expand Down Expand Up @@ -373,59 +378,6 @@ $(document).ready(function () {
});
});

// 筹码面
$("#chip_submit_btn").click(function () {
if ($("#chip_keyword").val() == "") {
$("#err_msg").text("请填写股票代码或简称");
$("#error_modal").modal("open");
return;
}
$(this).addClass("disabled");
$("#model_header").text($(this).text() + "中,请稍候...");
$("#load_modal").modal()[0].M_Modal.options.dismissible = false;
$("#load_modal").modal("open");
$.ajax({
url: "/chip",
type: "post",
data: $("#chip_form").serialize(),
success: function (data) {
if (data.Error) {
$("#err_msg").text(data.Error);
$("#error_modal").modal("open");
$("#checker_submit_btn").removeClass("disabled");
$("#load_modal").modal("close");
return;
}
$("title").text(data.PageTitle);
$("#stock_forms").remove();
$("#chip_results").removeClass("hide");
$.each(data.MainMoneyNetInflows, function (code, inflows) {
$("#chip_result_" + code).append(
'<div class="row">' +
'</br><h5 class="center">年报数据趋势概览</h5>' +
'<div class="col s12 m12 l6">' +
'<svg id="line-chart-' +
i +
'-0"></svg>' +
"</div>" +
'<div class="col s12 m12 l6">' +
'<svg id="line-chart-' +
i +
'-1"></svg>' +
"</div>" +
"</div>"
);
for (let j = 0; j < 2; j++) {
const svg = document.querySelector(`#line-chart-${i}-${j}`);
new chartXkcd.Line(svg, data.Lines[i][j]);
}
});
$("html, body").animate({ scrollTop: 0 }, 0);
$("#load_modal").modal("close");
},
});
});

// 返回顶部按钮
$("#to-top").click(function () {
$("html, body").animate({ scrollTop: 0 }, 500);
Expand Down

0 comments on commit 9277a43

Please sign in to comment.