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

     1  package market
     2  
     3  import (
     4  	"fmt"
     5  	"gitee.com/quant1x/exchange"
     6  	"gitee.com/quant1x/gotdx/securities"
     7  	"gitee.com/quant1x/num"
     8  )
     9  
    10  func GetStockCodeList() []string {
    11  	var allCodes []string
    12  	// 上海
    13  	// sh600000-sh609999
    14  	{
    15  		var (
    16  			codeBegin = 600000
    17  			codeEnd   = 609999
    18  		)
    19  		for i := codeBegin; i <= codeEnd; i++ {
    20  			fc := fmt.Sprintf("sh%d", i)
    21  			if IsNeedIgnore(fc) {
    22  				continue
    23  			}
    24  			allCodes = append(allCodes, fc)
    25  		}
    26  	}
    27  	// 科创板
    28  	// sh688000-sh688999
    29  	{
    30  		var (
    31  			codeBegin = 688000
    32  			codeEnd   = 689999
    33  		)
    34  		for i := codeBegin; i <= codeEnd; i++ {
    35  			fc := fmt.Sprintf("sh%d", i)
    36  			if IsNeedIgnore(fc) {
    37  				continue
    38  			}
    39  			allCodes = append(allCodes, fc)
    40  		}
    41  	}
    42  	// 深圳证券交易所
    43  	// 深圳主板: sz000000-sz000999
    44  	{
    45  		var (
    46  			codeBegin = 0
    47  			codeEnd   = 999
    48  		)
    49  		for i := codeBegin; i <= codeEnd; i++ {
    50  			fc := fmt.Sprintf("sz000%03d", i)
    51  			if IsNeedIgnore(fc) {
    52  				continue
    53  			}
    54  			allCodes = append(allCodes, fc)
    55  		}
    56  	}
    57  	// 中小板: sz001000-sz009999
    58  	{
    59  		var (
    60  			codeBegin = 1000
    61  			codeEnd   = 9999
    62  		)
    63  		for i := codeBegin; i <= codeEnd; i++ {
    64  			fc := fmt.Sprintf("sz00%04d", i)
    65  			if IsNeedIgnore(fc) {
    66  				continue
    67  			}
    68  			allCodes = append(allCodes, fc)
    69  		}
    70  	}
    71  	// 创业板: sz300000-sz300999
    72  	{
    73  		var (
    74  			codeBegin = 300000
    75  			codeEnd   = 309999
    76  		)
    77  		for i := codeBegin; i <= codeEnd; i++ {
    78  			fc := fmt.Sprintf("sz%06d", i)
    79  			if IsNeedIgnore(fc) {
    80  				continue
    81  			}
    82  			allCodes = append(allCodes, fc)
    83  		}
    84  	}
    85  	//allCodes = allCodes[0:0]
    86  	// 港股: hk00001-hk09999
    87  	//{
    88  	//	var (
    89  	//		codeBegin = 1
    90  	//		codeEnd   = 9999
    91  	//	)
    92  	//	for i := codeBegin; i <= codeEnd; i++ {
    93  	//		fc := fmt.Sprintf("hk%05d", i)
    94  	//		allCodes = append(allCodes, fc)
    95  	//	}
    96  	//}
    97  
    98  	return allCodes
    99  }
   100  
   101  // GetCodeList 加载全部股票代码
   102  func GetCodeList() []string {
   103  	allCodes := make([]string, 0)
   104  	// 添加指数代码
   105  	allCodes = append(allCodes, exchange.IndexList()...)
   106  
   107  	// 板块信息
   108  	blocks := securities.BlockList()
   109  	for _, v := range blocks {
   110  		allCodes = append(allCodes, v.Code)
   111  	}
   112  	stockCodes := GetStockCodeList()
   113  	allCodes = append(allCodes, stockCodes...)
   114  	return allCodes
   115  }
   116  
   117  // PriceLimit 计算涨停板和跌停板的价格
   118  func PriceLimit(securityCode string, lastClose float64) (limitUp, limitDown float64) {
   119  	limitRate := exchange.MarketLimit(securityCode)
   120  	priceLimitUp := num.Decimal(lastClose * (1.000 + limitRate))
   121  	priceLimitDown := num.Decimal(lastClose * (1.000 - limitRate))
   122  	return priceLimitUp, priceLimitDown
   123  }