yuebao

package module
v0.0.0-...-a1eeffb Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2016 License: MIT Imports: 9 Imported by: 0

README

go-yuebao

Build Status Go Report Card

go-yuebao is a Golang package which provides functions to get the latest yuebao(Tianhong Fund's "Zenglibao") data from Tianhong Fund's website.

Requirements
Install go-yuebao

The main method of installation is through "go get" (provided in $GOROOT/bin)

  • go get github.com/northbright/go-yuebao
Usage
  • Import package

To use the 'yuebao' package, you'll need the appropriate import statement:

    import (
        "github.com/northbright/go-yuebao"
    )
  • GrabLatestData()

      // Grab latest yuebao data from tianhong fund website and save into leveldb database.
      // It reads the "latest_url" and "latest_pattern" settings from config file(./config.json).
      func GrabLatestData() (err error)
    
  • GrabHistoryData()

      // Grab all history yuebao data from tianhong fund website and save into leveldb database.
      // It reads the "history_url" and "history_pattern" settings from config file(./config.json).
      func GrabHistoryData() (err error)
    
  • GetDataByRange()

      // Get data from day start to day end.
      // param: dateBegin, dayEnd in "yyyy-mm-dd" format.
      // return: json array if data exist or "" if no data found. Ex:
      // [
      //   {"d":"2013-07-22","y":1.1547,"r":4.447},
      //   {"d":"2013-07-21","y":1.1962,"r":4.471}
      // ]
      // d -> date, y -> yield(每万份收益), r -> yield rate(7天年化收益率)
      func GetDataByRange(dateBegin, dateEnd string) (jsonStr string)
    
  • GetData()

      // Get yuebao data by date.
      // param: date in "yyyy-mm-dd" format.
      // return: json string if data exist or "" if no data found. Ex:
      // {"d":"2013-07-22","y":1.1547,"r":4.447}
      // d -> date, y -> yield(每万份收益), r -> yield rate(7天年化收益率)
      func GetData(date string) string
    
Config File

Make sure the config file "config.json" exists under "./":

db_path: leveldb database path. Default is "./my.db".
latest_url: url to grab latest yuebao data.
latest_pattern: regexp pattern string to grab latest yuebao data.
history_url: url to grab all history yuebao data.
history_pattern: regexp pattern string to grab all history yuebao data.
Test
run `go test`.

Documentation

Overview

Package yuebao grabs the latest or history yuebao data from tianhong fund's web site and save them into a leveldb database. It also provides query methods to get yuebao data by date or date range.

Index

Constants

This section is empty.

Variables

View Source
var DEBUG = false

DEBUG is debug mode to output debug messages.

Functions

func CloseDB

func CloseDB()

CloseDB closes leveldb instance.

func GetData

func GetData(date string) string

GetData gets yuebao data by date. param: date in "yyyy-mm-dd" format. return: json string if data exist or "" if no data found. Ex: {"d":"2013-07-22","y":1.1547,"r":4.447} d -> date, y -> yield(每万份收益), r -> yield rate(7天年化收益率)

func GetDataByRange

func GetDataByRange(dateBegin, dateEnd string) (jsonStr string)

GetDataByRange gets data from day start to day end.

param: dateBegin, dayEnd in "yyyy-mm-dd" format.
return: json array if data exist or "" if no data found. Ex:
[
  {"d":"2013-07-22","y":1.1547,"r":4.447},
  {"d":"2013-07-21","y":1.1962,"r":4.471}
]
d: -> date, y -> yield(每万份收益), r -> yield rate(7天年化收益率)

func GrabHistoryData

func GrabHistoryData() (err error)

GrabHistoryData grabs all history yuebao data from tianhong fund website and save into leveldb database. It reads the "historyURL" and "historyPattern" settings from config file(./config.json).

func GrabLatestData

func GrabLatestData() (err error)

GrabLatestData grabs latest yuebao data from tianhong fund website and save into leveldb database. It reads the "latestURL" and "latestPattern" settings from config file(./config.json).

func IsDateValid

func IsDateValid(date string) bool

IsDateValid validates input date string. Date string must: 1. in yyyy-mm-dd format 2. > defMinDate(2013-05-30) 3. <= today

func LoadConfig

func LoadConfig()

LoadConfig loads settings from config file.

func LoadDefConfig

func LoadDefConfig()

LoadDefConfig loads default settings

func Lock

func Lock(ch chan int)

Lock locks goroutine to write into leveldb to make thread safe.

func OpenDB

func OpenDB() (err error)

OpenDB opens leveldb database. It reads "dbPath" in config file(./config.json). The default value is "./my.db".

func SaveFromRegexpMatches

func SaveFromRegexpMatches(matches []string) (err error)

SaveFromRegexpMatches saves into leveldb database from matched string slice by grabbing data from website.

func UnLock

func UnLock(ch chan int)

UnLock unlocks goroutine to write into leveldb to make thread safe.

Types

This section is empty.

Jump to

Keyboard shortcuts

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