nhplug

A set of coding rules for NH Investment & Securities Open API, a service for accessing Korean financial-market data and functions. It tells developers to use the nhplug SDK to handle login tokens, request formatting, and response checks.

In plain words
What is it for?
Use it when building applications that call NH Investment & Securities APIs for Korean or overseas stocks, futures, bonds, gold, quotes, or instrument lists. It also covers safe handling of API keys and practice-versus-live environments.
Why use it?
It avoids writing and maintaining error-prone login and HTTP request code by hand. It also reduces mistakes from guessing API paths, fields, or response types.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/plug-openapi/nhplug-sdk/nhplug
Clone the repo
git clone --depth 1 https://github.com/PLUG-OpenAPI/nhplug-sdk
Per session 1,328 This file is loaded in full into every session.
When invoked 1,328 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.01328 $0.01328
Opus 5 $0.00664 $0.00664
Sonnet 5 $0.00266 $0.00266
Haiku 4.5 $0.00133 $0.00133

Measured yesterday against content hash 7ec197ac9ab1, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

nhplug scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

templates/cursor/nhplug.mdc · 104 lines

How it starts

The opening of the file, as written. The whole thing — 104 lines — stays where its author put it; the contents beside it link to each section on GitHub.

NH투자증권 Open API 개발 규칙

SDK 를 쓴다 — 직접 HTTP 를 짜지 않는다

pip install nhplug                 # 인증·토큰캐시·에러판정·실시간·종목마스터 포함
pip install "nhplug[instruments]"  # 마스터를 DataFrame 으로 받을 때
from nhplug import call, NhplugError
call("/krstock/quote/v1/currentPrice", {"iem_cd": "005930", "market_cd": "KRX"})

토큰 발급·갱신·캐시, Input_0 봉투, 인증 헤더, rsp_cd 판정을 call() 이 처리한다. requests/oauth2/token 을 직접 부르는 코드를 새로 만들지 말 것.

명세 정본 — 도메인

설정 (.env)

NHPLUG_APP_KEY=...
NHPLUG_APP_SECRET=...
NHPLUG_BASE_URL=https://api.nhplug.com:8443    # 모의투자: moapi.nhplug.com:8443
NHPLUG_AUTH_URL=https://api.nhplug.com:8443    # 토큰은 운영 전용
NHPLUG_INSTRUMENTS_BASE=https://www.nhplug.com/instruments

키는 코드에 하드코딩 금지. .env.gitignore. N2 고객은 위 세 줄을 모두 n2plug 로 — 하나라도 빠지면 그 기능만 조용히 나무로 간다.

호출 규약

  • 요청 {"Input_0": {...}} / 응답 Output_0(+Output_1) + rsp_cd·rsp_msg
  • Output_0 은 객체일 수도 배열일 수도 있다. 타입을 추측하지 말고 openapi.json 확인.
  • 계좌목록 POST /n2/acctinfoOutput_0[].acct_no 를 이후 act_no 로 사용.

⚠️ 성공 판정 — HTTP 200 ≠ 업무 성공

  • 성공 코드: 00000·00166·00221·13578 (+ rsp_msg 에 "완료" 포함)
  • 00000/00166 만 성공으로 보지 말 것 — 매수가능수량 조회는 00221 로 응답한다.
  • 429(초당 5회 초과)는 자동 재시도하지 않는다. 429 재시도에 토큰을 재발급하지 말 것(재발급은 401 에만).

⚠️ 계좌구분(acct_type)

01·02 = 운영(api) · 03 = 모의투자(moapi). 계좌목록에 섞여 내려오므로 첫 계좌를 그대로 쓰지 말고 환경에 맞는 구분을 고른다.

종목마스터

from nhplug.instruments import load_master
df = load_master("m_new_stock")     # 자동 다운로드·캐시

전 종목 목록은 REST API 가 없고 마스터 파일 28종으로 제공된다. 다운로드는 인증 불필요.

Read the full file on GitHub · 104 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 104 lines · 1,328 tokens per session scan A 7ec197ac9ab1

Subscribe to this mod's changes

nhplug is a cursor rule published in the GitHub repository PLUG-OpenAPI/nhplug-sdk (8 stars, last pushed 4d ago), licensed MIT. It adds 1,328 tokens to every session, about $0.0066 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.