Пример #1
0
func TestBaseLists(t *testing.T) {
	otc := NewOTCLists(tradingdays.FindRecentlyOpened(time.Now()))
	twselist := NewLists(tradingdays.FindRecentlyOpened(time.Now()))
	for _, v := range []BaseLists{otc, twselist} {
		if data, err := v.Get("02"); err == nil {
			t.Log(len(data))
		} else {
			t.Error(err)
		}
	}
}
Пример #2
0
func ExampleStockRealTime_NewFRMSA() {
	farmsa := NewFRMSA(tradingdays.FindRecentlyOpened(time.Now()))
	data, _ := farmsa.Get()
	fmt.Printf("%+v", data.Info)
	// output:
	// {Exchange:tse FullName: Name:寶島股價指數 No:FRMSA Ticker:FRMSA.tw Category:tidx.tw}
}
Пример #3
0
func ExampleStockRealTime_NewWeight() {
	weight := NewWeight(tradingdays.FindRecentlyOpened(time.Now()))
	data, _ := weight.Get()
	fmt.Printf("%+v", data.Info)
	// output:
	// {Exchange:tse FullName: Name:發行量加權股價指數 No:t00 Ticker:t00.tw Category:tidx.tw}
}
Пример #4
0
func ExampleStockRealTime_NewOTCI() {
	otc := NewOTCI(tradingdays.FindRecentlyOpened(time.Now()))
	data, _ := otc.Get()
	fmt.Printf("%+v", data.Info)
	// output:
	// {Exchange:otc FullName: Name:櫃買指數 No:o00 Ticker:o00.tw Category:oidx.tw}
}
Пример #5
0
func ExampleStockRealTime_NewOTC() {
	otc := NewOTC("8446", tradingdays.FindRecentlyOpened(time.Now()))
	data, _ := otc.Get()
	fmt.Printf("%+v", data.Info)
	// output:
	// {Exchange:otc FullName:華研國際音樂股份有限公司 Name:華研 No:8446 Ticker:8446.tw Category:32}
}
Пример #6
0
func BenchmarkGet(b *testing.B) {
	r := NewTWSE("2618", tradingdays.FindRecentlyOpened(time.Now()))

	for i := 0; i <= b.N; i++ {
		r.Get()
	}
}
Пример #7
0
func TestStockRealTime(t *testing.T) {
	r := NewTWSE("2618", tradingdays.FindRecentlyOpened(time.Now()))

	t.Log(r.URL())
	r.Get()
	t.Logf("%+v", r)
}
Пример #8
0
func ExampleStockRealTime_NewTWSE() {
	twse := NewTWSE("2618", tradingdays.FindRecentlyOpened(time.Now()))
	data, _ := twse.Get()
	fmt.Printf("%+v", data.Info)
	// output:
	// {Exchange:tse FullName:長榮航空股份有限公司 Name:長榮航 No:2618 Ticker:2618.tw Category:15}
}
Пример #9
0
func TestStockRealTime_noData(t *testing.T) {
	r := NewTWSE("26188", tradingdays.FindRecentlyOpened(time.Now()))

	_, err := r.Get()
	if err != errorNotEnoughData {
		t.Error("Should be \"No Data.\"")
	}
}
Пример #10
0
func TestStockRealTimeIndexs(*testing.T) {
	var date = tradingdays.FindRecentlyOpened(time.Now())

	weight := NewWeight(date)
	otc := NewOTCI(date)
	farmsa := NewFRMSA(date)
	weight.Get()
	otc.Get()
	farmsa.Get()
}
Пример #11
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()
		}
	}
}
Пример #12
0
func TestOTCLists(t *testing.T) {
	o := NewOTCLists(tradingdays.FindRecentlyOpened(time.Now()))
	log.Println(o.GetCategoryList("04"))
	log.Println(o.Get("04"))
}
Пример #13
0
func main() {
	app := cli.NewApp()
	app.Name = "twsedaily"
	app.Usage = "Get daily data and into DB."
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "twsecate",
			Value: "",
			Usage: "twsecate no",
		},
		cli.StringFlag{
			Name:  "otccate",
			Value: "",
			Usage: "otccate no",
		},
		cli.BoolFlag{
			Name:  "flushcache",
			Usage: "clear cache",
		},
		cli.BoolFlag{
			Name:  "updatefilter",
			Usage: "update filter",
		},
	}
	app.Action = func(c *cli.Context) {
		if c.NumFlags() == 0 {
			cli.ShowAppHelp(c)
			os.Exit(0)
		}
		flushcache = c.Bool("flushcache")
		otccate = c.String("otccate")
		twsecate = c.String("twsecate")
		updateFilter = c.Bool("updatefilter")
	}
	app.Run(os.Args)

	if flushcache {
		temppath := utils.GetOSRamdiskPath()
		utils.NewHTTPCache(temppath, "utf8").FlushAll()
		log.Println("Clear cache", temppath)
	}

	if updateFilter {
		updateFilterInfo()
	}

	recentlyOpened := tradingdays.FindRecentlyOpened(time.Now())
	dailyreportdb := tdb.NewDailyReportDB()
	defer dailyreportdb.Close()

	stockList := makeStockList(twsecate, otccate, recentlyOpened)

	wg.Add(len(stockList))
	for _, stock := range stockList {
		go func(stock *twse.Data, recentlyOpened time.Time) {
			defer wg.Done()
			runtime.Gosched()
			for i, result := range doCheck(stock) {
				if result {
					lastdateList := stock.GetDateList()
					if _, err := dailyreportdb.InsertRecode(stock.No, filter.AllList[i].No(), lastdateList[len(lastdateList)-1].Add(time.Duration(8)*time.Hour)); err == nil {
						log.Println(stock.No, filter.AllList[i])
					} else {
						log.Println("InsertRecode Error", stock.No, i, err)
					}
				}
			}
		}(stock, recentlyOpened)
	}
	wg.Wait()
}
Пример #14
0
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)
	}
}
Пример #15
0
func TestStockRealTimeOTC(t *testing.T) {
	r := NewOTC("8446", tradingdays.FindRecentlyOpened(time.Now()))
	r.URL()
	t.Log(r.Get())
}