Beispiel #1
0
func gettwsecate(isTwse bool, cate string, date time.Time) []string {
	var l twse.BaseLists
	switch isTwse {
	case true:
		l = twse.NewLists(date)
	default:
		l = twse.NewOTCLists(date)
	}
	var result []string
	for _, s := range l.GetCategoryList(cate) {
		result = append(result, s.No)
	}
	return result
}
Beispiel #2
0
func main() {
	flag.Parse()

	if flag.NFlag() == 0 {
		flag.PrintDefaults()
		os.Exit(0)
	}

	var (
		datalist     []*twse.Data
		l            *twse.Lists
		o            *twse.OTCLists
		otccatelist  []string
		otcdelta     int
		otclist      []string
		twsecatelist []string
		twselist     []string
	)

	color.NoColor = !*showcolor

	if *showcatelist {
		var (
			cateTitle    = []string{"The same with TWSE/OTC", "OnlyTWSE", "OnlyOTC"}
			categoryList = twse.NewCategoryList()
			index        int
		)

		for i, cate := range []map[string]string{
			categoryList.Same(), categoryList.OnlyTWSE(), categoryList.OnlyOTC(),
		} {
			index = 1
			fmt.Println(white("---------- %s ----------", cateTitle[i]))
			for cateNo, cateName := range cate {
				fmt.Printf("%s\t", fmt.Sprintf("%s%s", green("%s", cateName), yellowBold("(%s)", cateNo)))
				if index%3 == 0 {
					fmt.Println("")
				}
				index++
			}
			fmt.Println("")
		}
	}

	if *twseCate != "" {
		l = twse.NewLists(tradingdays.FindRecentlyOpened(time.Now()))
		for _, v := range strings.Split(*twseCate, ",") {
			for _, s := range l.GetCategoryList(v) {
				twsecatelist = append(twsecatelist, s.No)
			}
		}
	}

	if *otcCate != "" {
		o = twse.NewOTCLists(tradingdays.FindRecentlyOpened(time.Now()))
		for _, v := range strings.Split(*otcCate, ",") {
			for _, s := range o.GetCategoryList(v) {
				otccatelist = append(otccatelist, s.No)
			}
		}
	}

	if *twseNo != "" {
		twselist = strings.Split(*twseNo, ",")
	}
	if *otcNo != "" {
		otclist = strings.Split(*otcNo, ",")
	}
	datalist = make([]*twse.Data, len(twselist)+len(twsecatelist)+len(otclist)+len(otccatelist))

	for i, no := range append(twselist, twsecatelist...) {
		datalist[i] = twse.NewTWSE(no, tradingdays.FindRecentlyOpened(time.Now()))
	}
	otcdelta = len(twselist) + len(twsecatelist)
	for i, no := range append(otclist, otccatelist...) {
		datalist[i+otcdelta] = twse.NewOTC(no, tradingdays.FindRecentlyOpened(time.Now()))
	}

	if len(datalist) > 0 {
		for _, check := range filter.AllList {
			fmt.Println(yellowBold("----- %v -----", check))
			wg.Add(len(datalist))
			for _, stock := range datalist {
				go func(check filter.CheckGroup, stock *twse.Data) {
					defer wg.Done()
					runtime.Gosched()
					if check.CheckFunc(stock) {
						fmt.Println(prettyprint(stock, check))
					}
				}(check, stock)
			}
			wg.Wait()
		}
	}
}