tshakutshai

module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2021 License: MIT

README

tshá-kú-tshài

ci codecov Go Reference

This library provides simple HTTP clients to get basic information from the Taiwan Stock Exchange (TWSE) and Taipei Exchange (TPEx).

Examples

Fetch the daily quotes of TSMC on March, 2021:

package main

import (
	"fmt"
	"time"

	"github.com/chehsunliu/tshakutshai/pkg/client/twse"
)

func main() {
	// The interval between each query is set to 2 seconds. The TWSE
	// server is unlikely to ban you at this query frequency.
	var client = twse.NewClient(time.Second * 2)
	quotes, _ := client.FetchDailyQuotes("2330", 2021, time.March)
	
	for _, quote := range quotes {
		fmt.Printf("%v\n", quote)
    }
}

Fetch the monthly quotes of PChome in 2020:

package main

import (
	"fmt"
	"time"

	"github.com/chehsunliu/tshakutshai/pkg/client/tpex"
)

func main() {
	// It seems the TPEx server never bans crawlers, so no need to
	// sleep between each query.
	var client = tpex.NewClient(0)
	quotes, _ := client.FetchMonthlyQuotes("8044", 2020)
	
	for _, quote := range quotes {
		fmt.Printf("%v\n", quote)
    }
}

You can also use your own HTTP clients:

import (
	"net/http"
	
	"github.com/chehsunliu/tshakutshai/pkg/client/twse"
	"github.com/chehsunliu/tshakutshai/pkg/client/tpex"
)

var (
	twseClient = &twse.Client{HttpClient: &http.Client{}}
	tpexClient = &tpex.Client{HttpClient: &http.Client{}}
)

Please refer to the online document for more details.

Directories

Path Synopsis
pkg
client/twse
Package twse provides HTTP client to interact with the Taiwan Stock Exchange Corporation (TWSE) server.
Package twse provides HTTP client to interact with the Taiwan Stock Exchange Corporation (TWSE) server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL