krx

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: MIT Imports: 11 Imported by: 0

README

krx

From download to entity

Usage

package main

import (
	"time"
	
	"github.com/hodlgap/krx"
)

func main() {
	// KRX only provides data up to the previous business day.
	yesterday := time.Now().AddDate(0, 0, -1)

	// Issuing temporary tokens for download
	code, err := krx.GetDownloadCode(yesterday)
	if err != nil {
		panic(err)
	}

	buf, err := krx.GetStockFile(code)
	if err != nil {
		panic(err)
	}

	// Parse to entity
	stocks, err := krx.ParseStockBuf(buf)
	if err != nil {
		panic(err)
	}
	
	for _, stock := range stocks {
        println(stock.StockName)
    }
}

CSV

http://data.krx.co.kr/contents/MDC/MDI/mdiLoader/index.cmd?menuId=MDC0201020101

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDownloadCode

func GetDownloadCode(when time.Time) (string, error)

func GetStockFile

func GetStockFile(downloadCode string) ([]byte, error)

Types

type Stock

type Stock struct {
	StockCode            string  `csv:"종목코드"`  // 종목코드
	StockName            string  `csv:"종목명"`   // 종목명
	MarketType           string  `csv:"시장구분"`  // E.g) KOSDAQ, KOSPI
	OrgName              string  `csv:"소속부"`   // E.g) 중견기업부, 우량기업부
	ClosingPrice         int64   `csv:"종가"`    // 종가
	DayOverDay           int64   `csv:"대비"`    // 전일 대비 상승가
	DayOverDayRate       float32 `csv:"등락률"`   // 전일 대비 상승률
	OpeningPrice         int64   `csv:"시가"`    // 시가
	MostExpensivePrice   int64   `csv:"고가"`    // 고가
	MostCheapestPrice    int64   `csv:"저가"`    // 저가
	TradingVolume        int64   `csv:"거래량"`   // 거래량
	TradingValue         int64   `csv:"거래대금"`  // 거래대금
	MarketCapitalization int64   `csv:"시가총액"`  // 시가총액
	TotalShares          int64   `csv:"상장주식수"` // 상장주식수
}

func ParseStockBuf

func ParseStockBuf(buf []byte) ([]*Stock, error)

Jump to

Keyboard shortcuts

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