Documentation ¶
Overview ¶
Package utils - 套件所需的公用工具(總和、平均、序列差、持續天數、 民國日期解析、簡單亂數、標準差、簡單 net/http 快取).
Index ¶
- Constants
- Variables
- func AvgFloat64(data []float64) float64
- func AvgUint64(data []uint64) uint64
- func CalDiffFloat64(listA, listB []float64) []float64
- func CalDiffInt64(listA, listB []int64) []int64
- func CalLHPower(final, low, high []float64) []float64
- func CountCountineFloat64(data []float64) (int, bool)
- func DeltaFloat64(data []float64) []float64
- func DeltaInt64(data []int64) []int64
- func GetOSRamdiskPath(goos string) string
- func ParseDate(strDate string) time.Time
- func RandInt() int
- func SD(list []float64) float64
- func SDUint64(list []uint64) float64
- func SumFloat64(data []float64) float64
- func SumUint64(data []uint64) uint64
- func ThanPastFloat64(data []float64, days int, max bool) bool
- func ThanPastUint64(data []uint64, days int, max bool) bool
- func ThanSumPastFloat64(data []float64, days int, max bool) bool
- func ThanSumPastUint64(data []uint64, days int, max bool) bool
- type HTTPCache
Examples ¶
Constants ¶
View Source
const ( TWSEURL string = "http://mis.twse.com.tw" TWSEHOST string = "http://www.twse.com.tw" OTCHOST string = "http://www.tpex.org.tw" HOME string = "/stock/index.jsp" OTCCSV string = "/ch/stock/aftertrading/daily_trading_info/st43_download.php?d=%d/%02d&stkno=%s&r=%%d" // year, mon, stock, rand OTCLISTCSV string = "/web/stock/aftertrading/otc_quotes_no1430/stk_wn1430_download.php?l=zh-tw&d=%s&se=%s&s=0,asc,0" // date, cate TWSECSV string = "/exchangeReport/STOCK_DAY?response=csv&date=%d%02d%02d&stockNo=%s" TWSELISTCSV string = "/exchangeReport/MI_INDEX?response=csv&date=%d%02d%02d&type=%s" // year, mon, day, type TWSEREAL string = "/stock/api/getStockInfo.jsp?ex_ch=%s_%s.tw&json=1&delay=0&_=%d" QFIISTOP20 string = "/fund/MI_QFIIS_sort_20?response=csv&date=%d%02d%02d" // yyyymmdd BFI82U string = "/fund/BFI82U?response=csv&dayDate=%d%02d%02d&type=day" // yyyymmdd T86 string = "/fund/T86?response=csv&date=%d%02d%02d&selectType=ALL" TWTXXU string = "/fund/%s?response=csv&date=%d%02d%02d" S3CSV string = "https://s3-ap-northeast-1.amazonaws.com/toomore/gogrs/list.csv" )
TWSE base url.
View Source
const TempFolderName = ".gogrscache"
TempFolderName 快取資料夾名稱
Variables ¶
View Source
var ExchangeMap = map[string]bool{"tse": true, "otc": true}
ExchangeMap is simple to check tse or otc.
View Source
var HTTPClient = &http.Client{Transport: &http.Transport{ Proxy: http.ProxyFromEnvironment, Dial: (&net.Dialer{ Timeout: 0, KeepAlive: 0, }).Dial, TLSHandshakeTimeout: 1 * time.Second, }, }
HTTPClient is default func and fixed http too many open files.
View Source
var TaipeiTimeZone = time.FixedZone("Asia/Taipei", 8*3600)
TaipeiTimeZone is for time.Data() setting.
Functions ¶
func CountCountineFloat64 ¶
CountCountineFloat64 計算最後一個數值為正或負值的持續天數(float64)
Example ¶
Output: 3 true 3 false
func GetOSRamdiskPath ¶
GetOSRamdiskPath try to get RamDisk path.
func ParseDate ¶
ParseDate is to parse "104/01/13" format.
Example ¶
Output: 2015-09-29 00:00:00 +0800 Asia/Taipei 2015-09-29 00:00:00 +0800 Asia/Taipei 2015-09-02 00:00:00 +0800 Asia/Taipei
func ThanPastFloat64 ¶
ThanPastFloat64 計算最後一個數值是否為過去幾天最大或最小(float64)
func ThanPastUint64 ¶
ThanPastUint64 計算最後一個數值是否為過去幾天最大或最小(uint64)
func ThanSumPastFloat64 ¶
ThanSumPastFloat64 計算最後一個數值是否為過去幾天的總和大或小(float64)
Types ¶
type HTTPCache ¶
type HTTPCache struct { Dir string // contains filtered or unexported fields }
HTTPCache net/http 快取功能
Example ¶
目前可以支援 http.Get / http.PostForm 取得資料並儲存
Output:
Click to show internal directories.
Click to hide internal directories.