koreasecurities

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

README

krsec

CI Go Reference

한국 증권사 REST API 통합 게이트웨이. 증권사마다 다른 인증, 파라미터, 응답 구조를 broker.Broker 인터페이스 하나로 통일합니다.

지원 증권사

증권사 상태
한국투자증권 (KIS)
키움증권
LS증권 예정

설치

go install github.com/smallfish06/krsec/cmd/krsec@latest

바이너리: Releases

설정

cp config.example.yaml config.yaml
server:
  port: 8080

accounts:
  - name: "main"
    broker: kis
    sandbox: true
    app_key: "YOUR_APP_KEY"
    app_secret: "YOUR_APP_SECRET"
    account_id: "12345678-01"

실행

krsec -config config.yaml

API

Method Path 설명
POST /kis/{path...} KIS 엔드포인트 호출 (/uapi 경로를 구현된 함수로 매핑)
POST /kiwoom/{path...} Kiwoom 엔드포인트 호출 (/api 경로 + api_id를 구현/문서 등록(비웹소켓 REST) 함수로 명시 매핑)
GET /quotes/{market}/{symbol} 현재가
GET /quotes/{market}/{symbol}/ohlcv 일봉
GET /instruments/{market}/{symbol} 종목 정보
GET /accounts/{id}/balance 잔고
GET /accounts/{id}/positions 포지션
GET /accounts/summary 멀티계좌 통합 잔고
POST /accounts/{account_id}/orders 주문
GET /accounts/{account_id}/orders/{id} 주문 상태
GET /accounts/{account_id}/orders/{id}/fills 체결내역
PUT /accounts/{account_id}/orders/{id} 주문 정정
DELETE /accounts/{account_id}/orders/{id} 주문 취소
GET /swagger/ Swagger UI
curl http://localhost:8080/quotes/KRX/005930
{"ok": true, "data": {"symbol": "005930", "price": 70000, ...}, "broker": "KIS"}
curl -X POST http://localhost:8080/kis/overseas-price/v1/quotations/price \
  -H "Content-Type: application/json" \
  -d '{
    "tr_id": "HHDFS00000300",
    "params": {
      "AUTH": "",
      "EXCD": "NAS",
      "SYMB": "AAPL"
    }
  }'

라이브러리로 사용

import (
    "github.com/smallfish06/krsec/pkg/broker"
    apiserver "github.com/smallfish06/krsec/pkg/server"
)

srv := apiserver.New(apiserver.Options{
    Port: 8080,
    Accounts: []apiserver.Account{{ID: "acc-1", Name: "Main", Broker: "custom"}},
    Brokers:  map[string]broker.Broker{"acc-1": myBroker},
})
srv.Run()

구조

cmd/krsec/        서버
pkg/broker/           공개 인터페이스
pkg/server/           임베드 가능한 HTTP 서버
internal/kis/         KIS 클라이언트 + 어댑터
internal/kiwoom/      키움 클라이언트 + 어댑터
internal/server/      HTTP 핸들러
examples/             사용 예시

범위

REST API만 지원합니다. WebSocket(실시간 시세, 실시간 체결 등)은 지원 범위에 포함되지 않습니다.

개발

make test      # 테스트
make build     # 빌드
make lint      # lint
make mock      # mock 재생성
make kis-spec-check    # KIS generated spec/type 동기화 확인
make kis-spec-refresh  # KIS 포털 snapshot 갱신 + generated 파일 재생성
KIS spec 관리
  • KIS 문서 스펙은 internal/kis/specs/documented_endpoints.json snapshot으로 버전 관리합니다.
  • 런타임은 웹사이트를 조회하지 않고, snapshot에서 생성된 코드만 사용합니다.
  • CI는 make kis-spec-check로 generated 파일 drift를 차단합니다.

License

Apache 2.0

Documentation

Overview

Package koreasecurities provides a unified gateway for Korean securities broker APIs.

This module abstracts away the differences between Korean broker REST APIs (KIS, Kiwoom, LS, etc.) behind a single github.com/smallfish06/krsec/pkg/broker.Broker interface.

Most users will import one of the sub-packages:

Or run the standalone server:

krsec -config config.yaml

Directories

Path Synopsis
cmd
kis-specgen command
krsec command
live-api-smoke command
examples
all-balances command
kis-balance command
kiwoom-balance command
internal
kis
ratelimit
Package ratelimit provides a shared rate limiter for broker API clients.
Package ratelimit provides a shared rate limiter for broker API clients.
pkg
broker
Package broker defines the common interface and types shared across all broker adapters.
Package broker defines the common interface and types shared across all broker adapters.
server
Package server provides a ready-to-use HTTP API server that can be wired with any github.com/smallfish06/krsec/pkg/broker.Broker implementation.
Package server provides a ready-to-use HTTP API server that can be wired with any github.com/smallfish06/krsec/pkg/broker.Broker implementation.

Jump to

Keyboard shortcuts

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