stock

package module
v0.0.0-...-9954bf7 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: MIT Imports: 16 Imported by: 0

README

Stock Project

Installation
  • Install
$ go get -u github.com/andrewlu0210/stock
  • Import
import "github.com/andrewlu0210/stock"
MongoDB Setup
  • Install MongoDB and get root account and passwordf
# assume the following codes in setup.go file
$ go run setup.go
package main

import (
	"github.com/andrewlu0210/stock"
)

var (
	dbHost     = "127.0.0.1"
	dbName     = "stockDB"
	dbAccount  = "account"
	dbPassword = "password"
)

func main() {
	root := "root"
	rootPasswd := "password"

	stock.SetMongo(dbHost, dbName, dbAccount, dbPassword)
	stock.ResetDb(root, rootPasswd)

}
快速下載股票資訊
# assume the following codes in sample.go file
$ go run sample.go
package main

import (
	"github.com/andrewlu0210/stock"
)

func main() {
	downloadDate := "20220615"
	dbHost := "127.0.0.1"
	dbName := "stockDB"
	dbAccount, dbPasswd := "account", "password"
	csvRoot := "/stock_csv/stock_price"
	stock.SetMongo(dbHost, dbName, dbAccount, dbPasswd)
	stock.ConnectDb()
	defer stock.DisconnectDb()

	downloader := stock.GetPriceService().GetDownloader(csvRoot)
	downloader.DownloadStockPrice(downloadDate)
    // file (20220615.csv) will save to /stock_csv/stock_price/2022/202206

}

Documentation

Index

Constants

View Source
const (
	STOCK_PRICE_COL = "stock_price"
)

Variables

This section is empty.

Functions

func ConnectDb

func ConnectDb()

Connect to Mongo DB

func DisconnectDb

func DisconnectDb()

Close Mongo Db connection

func RemoveFile

func RemoveFile(fileName string)

func ResetDb

func ResetDb(root, rootPasswd string)

Reset DB

func SetMongo

func SetMongo(dbHost, dbName, dbAccount, dbPassword string)

Types

type PriceDAO

type PriceDAO struct {
	// contains filtered or unexported fields
}

type PriceDownloader

type PriceDownloader struct {
	// contains filtered or unexported fields
}

func (*PriceDownloader) DownloadStockPrice

func (service *PriceDownloader) DownloadStockPrice(dateStr string) (bool, bool)

type PriceService

type PriceService struct {
	// contains filtered or unexported fields
}

func GetPriceService

func GetPriceService() *PriceService

Get Price Service Instance

func (*PriceService) GetDownloader

func (service *PriceService) GetDownloader(csvRoot string) *PriceDownloader

Get A Downloader Instance to download stock price CSV File

func (*PriceService) GetLatestDate

func (service *PriceService) GetLatestDate() string

Get latest stock price record date in mongodb

func (*PriceService) GetPriceByCodeDate

func (service *PriceService) GetPriceByCodeDate(dateStr, code string) *StockPrice

func (*PriceService) GetPricesByCode

func (service *PriceService) GetPricesByCode(code, fromDate, toDate string, oldToNew bool) []*StockPrice

func (*PriceService) GetPricesByDate

func (service *PriceService) GetPricesByDate(dateStr string) []*StockPrice

type StockPrice

type StockPrice struct {
	DateStr       string  `json:"dateStr" bson:"dateStr"`
	Code          string  `json:"code" bson:"code"` //stock code
	Name          string  `json:"name" bson:"name"`
	Qty           int     `json:"qty" bson:"qty"`     //成交股數
	Qty2          int     `json:"qty2" bson:"qty2"`   //成交筆數
	Total         int64   `json:"total" bson:"total"` //成交金額
	StartPrice    float64 `json:"startPrice" bson:"startPrice"`
	HighPrice     float64 `json:"highPrice" bson:"highPrice"`
	LowPrice      float64 `json:"lowPrice" bson:"lowPrice"`
	EndPrice      float64 `json:"endPrice" bson:"endPrice"`
	UpDown        string  `json:"upDown" bson:"upDown"` //漲跌(”平, '+'漲, '-'跌, 'X'除權息)
	Step          float64 `json:"step" bson:"step"`     //漲跌價差
	LastBuyPrice  float64 `json:"lastBuyPrice" bson:"lastBuyPrice"`
	LastBuyQty    int     `json:"lastBuyQty" bson:"lastBuyQty"`
	LastSellPrice float64 `json:"lastSellPrice" bson:"lastSellPrice"`
	LastSellQty   int     `json:"lastSellQty" bson:"lastSellQty"`
	PeRatio       float64 `json:"peRatio" bson:"peRatio"` //本益比
}

StockPrice StockPrice

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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