opendart

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 13 Imported by: 0

README

opendart

DART 전자공시시스템 OpenAPI 의 Go 클라이언트 라이브러리.

설치

go get github.com/kenshin579/opendart@v0.1.1

사용

client, _ := opendart.NewClientFromEnv() // OPENDART_API_KEY
ctx := context.Background()

corp, _ := client.ResolveCorpCode(ctx, "005930")        // 종목코드 → corp_code
company, _ := client.Disclosure.GetCompany(ctx, corp)   // 기업개황 (DS001)
res, _ := client.Disclosure.SearchDisclosures(ctx, disclosure.SearchParams{CorpCode: corp})
zip, _ := client.Disclosure.DownloadDocument(ctx, "20240131000326") // 원본 ZIP

// 재무정보(DS003)는 client.Report 로 접근
acnt, _ := client.Report.SingleAccount(ctx, report.ReportParams{
    CorpCode: corp, BsnsYear: "2023", ReprtCode: report.AnnualReport,
}) // 단일회사 주요계정

인증

발급받은 API 키를 OPENDART_API_KEY 환경변수로 두거나 opendart.NewClient(apiKey) 로 전달한다.

커버리지

구분 영역 서비스
DS001 공시정보 client.Disclosure
DS002 정기보고서 주요정보 client.Report
DS003 정기보고서 재무정보 client.Report
DS004 지분공시 종합정보 client.Ownership
DS005 주요사항보고서 주요정보 client.Material
DS006 증권신고서 주요정보 client.Registration

DS001~DS006 의 세부 엔드포인트를 거의 모두 제공한다. 각 항목별 요청·응답 명세는 아래 문서를 참고한다.

(예정) DS002 개인별 보수 Ver2.0

에러 처리

  • errors.Is(err, opendart.ErrNoData) — 조회 데이터 없음(013)
  • errors.As(err, &apiErr) — 그 외 OpenDART status (*opendart.APIError)

예제

실행 가능한 예제: examples/disclosure · examples/report

OPENDART_API_KEY=... go run ./examples/disclosure

License

Released under the MIT License.

Documentation

Overview

Package opendart 는 DART 전자공시 OpenAPI 의 Go 클라이언트다.

Index

Constants

This section is empty.

Variables

View Source
var ErrCorpCodeNotFound = errors.New("opendart: corp_code not found")

ErrCorpCodeNotFound 는 종목코드/고유번호 매핑 실패.

View Source
var ErrNoData = httpclient.ErrNoData

ErrNoData 는 status 013 (조회된 데이터 없음).

Functions

This section is empty.

Types

type APIError

type APIError = httpclient.APIError

APIError 는 OpenDART status != "000" 응답. errors.As 로 Status/Message 접근.

type Client

type Client struct {
	Disclosure   *disclosure.Client   // DS001 공시정보
	Report       *report.Client       // DS002 정기보고서 주요정보
	Ownership    *ownership.Client    // DS004 지분공시 종합정보
	Material     *material.Client     // DS005 주요사항보고서 주요정보
	Registration *registration.Client // DS006 증권신고서 주요정보
	// contains filtered or unexported fields
}

Client 는 opendart 라이브러리의 단일 진입점.

func NewClient

func NewClient(apiKey string, opts ...Option) (*Client, error)

NewClient 는 API 키로 Client 를 만든다.

func NewClientFromEnv

func NewClientFromEnv(opts ...Option) (*Client, error)

NewClientFromEnv 는 OPENDART_API_KEY 환경변수로 Client 를 만든다.

func (*Client) CorpCodes

func (c *Client) CorpCodes(ctx context.Context) ([]CorpCodeEntry, error)

CorpCodes 는 전체 회사 엔트리를 반환한다 (사용자 직접 필터용).

func (*Client) LookupCorpCode

func (c *Client) LookupCorpCode(ctx context.Context, corpCode string) (CorpCodeEntry, error)

LookupCorpCode 는 corp_code(8자리)로 회사 엔트리를 조회한다.

func (*Client) RefreshCorpCodes

func (c *Client) RefreshCorpCodes(ctx context.Context) error

RefreshCorpCodes 는 TTL 을 무시하고 corp_code 매핑을 강제 재다운로드한다.

func (*Client) ResolveCorpCode

func (c *Client) ResolveCorpCode(ctx context.Context, stockCode string) (string, error)

ResolveCorpCode 는 종목코드(6자리)를 corp_code(8자리)로 변환한다. 매핑이 없으면 ErrCorpCodeNotFound.

type CorpCodeEntry

type CorpCodeEntry = corpcode.Entry

CorpCodeEntry 는 corp_code 매핑의 한 회사. (internal 타입 별칭 — 외부에서 opendart.CorpCodeEntry 로 사용)

type Option

type Option func(*clientOptions)

Option 은 functional option.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL 은 API 베이스 URL 을 지정한다 (테스트/프록시용).

func WithCorpCodeCacheDir

func WithCorpCodeCacheDir(dir string) Option

WithCorpCodeCacheDir 는 corp_code 캐시 디렉토리를 지정한다.

func WithCorpCodeCacheTTL

func WithCorpCodeCacheTTL(d time.Duration) Option

WithCorpCodeCacheTTL 은 corp_code 재다운로드 주기를 지정한다 (기본 24h).

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient 는 사용자 정의 *http.Client 를 주입한다 (기본: TLS RSA cipher 내장).

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout 은 HTTP 타임아웃을 지정한다 (기본 30s).

Directories

Path Synopsis
Package disclosure 는 OpenDART DS001 공시정보 API sub-client 다.
Package disclosure 는 OpenDART DS001 공시정보 API sub-client 다.
examples
disclosure command
examples/disclosure — DS001 공시정보 사용 예제.
examples/disclosure — DS001 공시정보 사용 예제.
report command
examples/report — DS002 정기보고서 주요정보(지분·주식·배당) 사용 예제.
examples/report — DS002 정기보고서 주요정보(지분·주식·배당) 사용 예제.
internal
corpcode
Package corpcode 는 OpenDART 고유번호(corpCode.xml) 의 디스크 캐시 + 인덱스다.
Package corpcode 는 OpenDART 고유번호(corpCode.xml) 의 디스크 캐시 + 인덱스다.
httpclient
Package httpclient 는 OpenDART REST 호출의 단일 GET 통로다.
Package httpclient 는 OpenDART REST 호출의 단일 GET 통로다.
Package material 는 OpenDART DS005 주요사항보고서 주요정보 API sub-client 다.
Package material 는 OpenDART DS005 주요사항보고서 주요정보 API sub-client 다.
Package ownership 는 OpenDART DS004 지분공시 종합정보 API sub-client 다.
Package ownership 는 OpenDART DS004 지분공시 종합정보 API sub-client 다.
Package report 는 OpenDART DS002 정기보고서 주요정보 API sub-client 다.
Package report 는 OpenDART DS002 정기보고서 주요정보 API sub-client 다.
scripts
crawl command

Jump to

Keyboard shortcuts

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