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 }
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() } } }
gogrs_example */ package main import ( "fmt" "time" "github.com/toomore/gogrs/tradingdays" "github.com/toomore/gogrs/twse" "github.com/toomore/gogrs/utils" ) var stock = twse.NewTWSE("2329", time.Date(2015, 3, 20, 0, 0, 0, 0, time.Local)) // ShowAll is lazy to show all XD. func ShowAll(stock *twse.Data) { fmt.Println(stock.RawData) fmt.Println(stock.MA(6)) fmt.Println(stock.MAV(6)) fmt.Println(stock.GetPriceList()) fmt.Println(utils.ThanPastFloat64(stock.GetPriceList(), 3, true)) fmt.Println(utils.ThanPastFloat64(stock.GetPriceList(), 3, false)) fmt.Println(stock.GetVolumeList()) fmt.Println(utils.ThanPastUint64(stock.GetVolumeList(), 3, true)) fmt.Println(utils.ThanPastUint64(stock.GetVolumeList(), 3, false)) fmt.Println(stock.GetRangeList()) fmt.Println(stock.IsRed()) }
package filter import ( "testing" "time" "github.com/toomore/gogrs/tradingdays" "github.com/toomore/gogrs/twse" ) var stock = twse.NewTWSE("2618", tradingdays.FindRecentlyOpened(time.Now())) func TestCheckGroup(t *testing.T) { for i, v := range AllList { t.Log(i, v.No(), v.String(), v.Mindata(), v.CheckFunc(stock)) } } func TestCheckGroup_String(t *testing.T) { for i, v := range AllList { t.Log(i, v.No(), v) } }