Beispiel #1
0
func makeStockList(twsecae string, otccate string, recentlyOpened time.Time) []*twse.Data {
	var stockList = make([]*twse.Data, 0)
	if twsecate != "" {
		for _, twsecateno := range strings.Split(twsecate, ",") {
			for _, sno := range gettwsecate(true, twsecateno, recentlyOpened) {
				stockList = append(stockList, twse.NewTWSE(sno, recentlyOpened))
			}
		}
	}

	if otccate != "" {
		for _, otccateno := range strings.Split(otccate, ",") {
			for _, sno := range gettwsecate(false, otccateno, recentlyOpened) {
				stockList = append(stockList, twse.NewOTC(sno, recentlyOpened))
			}
		}
	}
	return stockList
}
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()
		}
	}
}