gitee.com/quant1x/engine@v1.8.4/factors/feature_f10_utils.go (about)

     1  package factors
     2  
     3  import (
     4  	"gitee.com/quant1x/engine/datasource/base"
     5  	"gitee.com/quant1x/exchange"
     6  	"gitee.com/quant1x/gotdx"
     7  	"gitee.com/quant1x/gotdx/quotes"
     8  	"gitee.com/quant1x/gox/logger"
     9  	"gitee.com/quant1x/num"
    10  	"strconv"
    11  	"time"
    12  )
    13  
    14  // 获取财务数据
    15  func getFinanceInfo(securityCode, featureDate string) (capital, totalCapital float64, ipoDate, updateDate string) {
    16  	basicDate := uint32(num.AnyToInt64(exchange.MARKET_CN_FIRST_DATE))
    17  	for i := 0; i < quotes.DefaultRetryTimes; i++ {
    18  		securityCode := exchange.CorrectSecurityCode(securityCode)
    19  		tdxApi := gotdx.GetTdxApi()
    20  		info, err := tdxApi.GetFinanceInfo(securityCode)
    21  		if err != nil {
    22  			logger.Error(err)
    23  			gotdx.ReOpen()
    24  		}
    25  		if info != nil {
    26  			if info.LiuTongGuBen > 0 && info.ZongGuBen > 0 {
    27  				capital = info.LiuTongGuBen
    28  				totalCapital = info.ZongGuBen
    29  			}
    30  			if info.IPODate >= basicDate {
    31  				ipoDate = strconv.FormatInt(int64(info.IPODate), 10)
    32  				ipoDate = exchange.FixTradeDate(ipoDate)
    33  			} else {
    34  				ipoDate = getIpoDate(securityCode, featureDate)
    35  			}
    36  			if info.UpdatedDate >= basicDate {
    37  				updateDate = strconv.FormatInt(int64(info.UpdatedDate), 10)
    38  				updateDate = exchange.FixTradeDate(updateDate)
    39  			}
    40  			break
    41  		} else if i+1 < quotes.DefaultRetryTimes {
    42  			time.Sleep(time.Millisecond * 10)
    43  		}
    44  	}
    45  	return
    46  }
    47  
    48  func getIpoDate(securityCode, featureDate string) (ipoDate string) {
    49  	// IPO日期不存在, 从日K线第一条记录获取
    50  	kls := base.CheckoutKLines(securityCode, featureDate)
    51  	if len(kls) > 0 {
    52  		ipoDate = kls[0].Date
    53  	}
    54  	return
    55  }