키움증권 OpenAPI REST API를 위한 현대적이고 직관적인 .NET Wrapper 라이브러리
주식 거래, 계좌 조회, 실시간 데이터, 차트 분석 등 키움증권의 모든 REST API 기능을 간편하게 사용할 수 있습니다.
# NuGet 패키지 설치
dotnet add package KiwoomRestApi.Netusing KiwoomRestApi.Net.Clients;
// 1. 클라이언트 생성 및 초기화
var client = await KiwoomRestApiClient.CreateAsync("YOUR_APP_KEY", "YOUR_SECRET_KEY", isMock: true);
// 2. 삼성전자 주식 정보 조회
var stockInfo = await client.StockInfo.GetStockInfoAsync("005930", DateTime.Today, KiwoomStockInfoMarginLoanType.Loan);
Console.WriteLine($"삼성전자 현재가: {stockInfo.Data.CurrentPrice}원");
// 3. 당일 삼성전자 실현손익 조회
var todayRealizedProfitLoss = await client.Account.GetTodayRealizedProfitLossAsync("005930");
Console.WriteLine($"평가금액: {todayRealizedProfitLoss.ProfitLossRate}%");// CancellationToken 지원
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
var result = await client.Account.GetDailyStatusAsync(cts.Token);// Startup.cs 또는 Program.cs
services.AddKiwoomRestApi(config => {
config.AppKey = "your-app-key";
config.SecretKey = "your-secret-key";
config.IsMock = true;
config.RequestTimeout = TimeSpan.FromSeconds(30);
});
// 컨트롤러에서 사용
[ApiController]
public class TradingController : ControllerBase
{
private readonly KiwoomRestApiClient _client;
public TradingController(KiwoomRestApiClient client)
{
_client = client;
}
}| 기능 | 설명 | 상세 기능 | 상태 |
|---|---|---|---|
| 🔐 OAuth 인증 | 토큰 발급/갱신 | 액세스 토큰, 리프레시 토큰 관리 | ✅ |
| 💰 계좌 관리 | 잔고조회, 주문내역 | 예수금, 평가잔고, 실현손익, 미체결주문 | ✅ |
| 📈 주식 정보 | 현재가, 호가, 체결 | 주식기본정보, 호가정보, 체결정보 | ✅ |
| 📊 차트 데이터 | 일/분봉 데이터 | 일봉, 분봉, 기간별 차트 | ✅ |
| 🛒 주문 관리 | 매수/매도 주문 | 신규주문, 정정주문, 취소주문 | ✅ |
| 📊 시장 정보 | 업종, 테마, 순위 | 업종지수, 테마정보, 순위정보 | ✅ |
| 📡 실시간 데이터 | WebSocket 연결 | 실시간 주식체결, 호가, 체결강도 | ✅ |
| 🔍 종목 검색 | 종목 정보 조회 | ETF, ELW, 외국인/기관 정보 | ✅ |
using KiwoomRestApi.Net.Clients;
var client = KiwoomRestApiClient.Create(appKey, secretKey, true);// 현재가 조회
var stockInfo = await client.StockInfo.GetStockInfoAsync("005930", DateTime.Today, KiwoomStockInfoMarginLoanType.Loan);
Console.WriteLine($"삼성전자 현재가: {stockInfo.Data.CurrentPrice}원");
// 호가 조회
var orderBook = await client.MarketCondition.GetOrderBookAsync("005930");
Console.WriteLine($"매수1호가: {orderBook.Data.BidLevel1Price}원");
// 차트 데이터 조회
var chartData = await client.Chart.GetDailyChartsAsync("005930", DateTime.Today, KiwoomChartUseOption.Use);
Console.WriteLine($"삼성전자 전일종가: {chartData.Data.Items.ElementAt(1).CurrentPrice}원");// 💰 예수금 및 자금 관리
var deposits = await client.Account.GetDepositsAsync(KiwoomAccountDepositQueryType.Normal);
Console.WriteLine($"예수금: {deposits.Data.DepositAmount:N0}원");
var dailyEstimatedAssets = await client.Account.GetDailyEstimatedDepositAssetsAsync(
DateTime.Today.AddDays(-7), DateTime.Today);
Console.WriteLine($"추정예탁자산: {dailyEstimatedAssets.Data.TotalEstimatedDepositAsset:N0}원");
var estimatedAsset = await client.Account.GetEstimatedDepositAssetAsync(isExcludeDelisted: false);
Console.WriteLine($"평가자산 총액: {estimatedAsset.Data.TotalAssetAmount:N0}원");
// 📊 잔고 및 평가
var evaluations = await client.Account.GetEvaluationsAsync(
isExcludeDelisted: false, KiwoomAccountStockExchangeType.KRX);
Console.WriteLine($"총평가금액: {evaluations.Data.TotalAssetAmount:N0}원");
var tradeBalances = await client.Account.GetTradeBalancesAsync(KiwoomAccountStockExchangeType.KRX);
Console.WriteLine($"매입금액: {tradeBalances.Data.TotalBuyAmount:N0}원");
var evaluationBalances = await client.Account.GetEvaluationBalancesAsync(
KiwoomAccountEvaluationBalanceQueryType.TotalProfitLoss,
KiwoomAccountDomesticStockExchangeType.All);
Console.WriteLine($"총평가손익: {evaluationBalances.Data.TotalProfitLossAmount:N0}원");
// 📈 수익률 및 손익 분석
var dailyBalanceProfitRates = await client.Account.GetDailyBalanceProfitRatesAsync(DateTime.Today);
Console.WriteLine($"일별잔고수익률: {dailyBalanceProfitRates.Data.TotalProfitLossRate:F2}%");
var todayRealizedProfitLoss = await client.Account.GetTodayRealizedProfitLossAsync("005930");
Console.WriteLine($"금일 실현손익률: {todayRealizedProfitLoss.ProfitLossRate:F2}%");
var dailyRealizedProfitLosses = await client.Account.GetDailyRealizedProfitLossesAsync(
DateTime.Today.AddDays(-30), DateTime.Today);
Console.WriteLine($"30일간 실현손익: {dailyRealizedProfitLosses.Data.TotalProfitLossAmount:N0}원");
var profitRates = await client.Account.GetProfitRatesAsync(KiwoomAccountStockExchangeType.KRX);
Console.WriteLine($"계좌 수익률: {profitRates.Data.TotalProfitLossRate:F2}%");
// 🔄 주문 관리
var unfilledOrders = await client.Account.GetUnfilledOrdersAsync(
KiwoomAccountQueryType.All,
KiwoomAccountTransactionType.All,
KiwoomAccountStockExchangeType.Unified);
Console.WriteLine($"미체결 주문 수: {unfilledOrders.Data.Count}");
var filledOrders = await client.Account.GetFilledOrdersAsync(
KiwoomAccountQueryType.Today,
KiwoomAccountTransactionType.All,
KiwoomAccountStockExchangeType.Unified);
Console.WriteLine($"체결 주문 수: {filledOrders.Data.Count}");
// 📋 거래 내역 조회
var todayTransactionJournals = await client.Account.GetTodayTransactionJournalsAsync(
KiwoomAccountOddLotType.IncludeOddLot,
KiwoomAccountCashCreditType.All);
Console.WriteLine($"금일 거래 내역 수: {todayTransactionJournals.Data.Count}");
var orderTradeDetails = await client.Account.GetOrderTradeDetailsAsync(
KiwoomAccountOrderQueryType.Today,
KiwoomAccountStockBondType.Stock,
KiwoomAccountTransactionType.All,
KiwoomAccountDomesticStockExchangeType.KRX);
Console.WriteLine($"주문 거래 상세 수: {orderTradeDetails.Data.Count}");
// 💳 신용 거래
var marginOrders = await client.Account.GetMarginOrdersAsync("005930");
Console.WriteLine($"융자 주문 가능 수량: {marginOrders.Data.MarginBuyableQuantity:N0}주");
var creditDepositOrders = await client.Account.GetCreditDepositOrdersAsync("005930");
Console.WriteLine($"신용보증금율: {creditDepositOrders.Data.StockDepositRate:F2}%");
var marginDetails = await client.Account.GetMarginDetailsAsync();
Console.WriteLine($"융자비율: {marginDetails.Data.MarginRate:F2}%");
// 🎯 주문 가능량 조회
var availableWithdrawalAmounts = await client.Account.GetAvailableWithdrawalAmountsAsync(
"005930", KiwoomAccountTransactionType.Buy, 85000);
Console.WriteLine($"출금가능금액: {availableWithdrawalAmounts.Data.AvailableWithdrawalAmount:N0}원");
// 📅 정산 및 상태
var nextDaySettlements = await client.Account.GetNextDaySettlementsAsync();
Console.WriteLine($"D+1 정산 금액: {nextDaySettlements.Data.TotalBuyAmount:N0}원");
var dailyStatus = await client.Account.GetDailyStatusAsync();
Console.WriteLine($"계좌 상태: {dailyStatus.Data.AccountStatus}");
// 📊 종목별 실현손익
var dailyStockRealizedProfitLosses = await client.Account.GetDailyStockRealizedProfitLossesAsync(
"005930", DateTime.Today.AddDays(-30));
Console.WriteLine($"종목별 실현손익: {dailyStockRealizedProfitLosses.Data.TotalProfitLossAmount:N0}원");
var dailyStockRealizedProfitLossPeriods = await client.Account.GetDailyStockRealizedProfitLossPeriodsAsync(
"005930", DateTime.Today.AddDays(-30), DateTime.Today);
Console.WriteLine($"기간별 실현손익: {dailyStockRealizedProfitLossPeriods.Data.TotalProfitLossAmount:N0}원");
// 🏦 위탁 및 예수
var consignedTransactions = await client.Account.GetConsignedTransactionsAsync(
KiwoomAccountTransactionType2.All,
KiwoomAccountGoodsType.Stock,
KiwoomAccountDomesticStockExchangeType.KRX,
DateTime.Today.AddDays(-7), DateTime.Today);
Console.WriteLine($"위탁 매매 수량: {consignedTransactions.Data.TotalOrderQuantity:N0}주");
// 📈 주문 분할 정보
var unfilledSplitOrders = await client.Account.GetUnfilledSplitOrdersAsync("주문번호");
Console.WriteLine($"분할 미체결 수량: {unfilledSplitOrders.Data.RemainQuantity:N0}주");
// 📊 일별 수익률 상세
var dailyProfitRateDetails = await client.Account.GetDailyProfitRateDetailsAsync(
DateTime.Today.AddDays(-30), DateTime.Today);
Console.WriteLine($"일별 수익률 상세: {dailyProfitRateDetails.Data.Count}일 데이터");
// 🛒 주문 실행 (신용 거래 포함)
var buyOrderResult = await client.Order.PlaceOrderAsync(
KiwoomOrderType.Buy, // 매수
KiwoomOrderDomesticStockExchangeType.KRX, // 거래소
"005930", // 삼성전자
10, // 주문수량
KiwoomOrderTradeType.Normal, // 지정가
80000); // 주문가격
var sellOrderResult = await client.Order.PlaceOrderAsync(
KiwoomOrderType.Sell, // 매도
KiwoomOrderDomesticStockExchangeType.KRX, // 거래소
"005930", // 삼성전자
5, // 주문수량
KiwoomOrderTradeType.Market); // 시장가
// 🔧 주문 수정 및 취소
var modifyResult = await client.Order.ModifyOrderAsync(
KiwoomOrderDomesticStockExchangeType.KRX, // 거래소
"원주문번호", // 원주문번호
"005930", // 종목코드
8, // 수정수량
82000); // 수정가격
var cancelResult = await client.Order.CancelOrderAsync(
KiwoomOrderDomesticStockExchangeType.KRX, // 거래소
"원주문번호", // 원주문번호
"005930", // 종목코드
cancelQuantity: 3); // 취소수량
// 🥇 금현물 거래
var goldBuyOrderResult = await client.Order.GoldSpotPlaceOrderAsync(
KiwoomOrderType.Buy, // 매수
KiwoomGoldSpotStockCode.Gold_1kg, // 금 1kg
1, // 주문수량
KiwoomOrderGoldSpotTransactionType.Normal, // 보통
8500000); // 주문가격using KiwoomRestApi.Net.Clients;
var socketClient = await KiwoomSocketClient.CreateAsync(client.Token, isMock: true);
// 실시간 주식체결 수신
socketClient.OnRealtimeStockExecutionReceived += (message) =>
{
Console.WriteLine($"체결가: {message.ElementAt(0).Values.CurrentPrice}원");
};
// 실시간 주식체결 구독
await socketClient.WebSocket.SubscribeAsync([KiwoomWebSocketServiceName.StockExecution], ["005930", "000660"]);| 구분 | 제한사항 | 권장사항 |
|---|---|---|
| API 호출 | 초당 20회 | Rate limiting 구현 권장 |
| 실시간 구독 | 동시 40종목 | 필요한 종목만 구독 |
| WebSocket | 연결당 1개 | 연결 상태 모니터링 필요 |
| 토큰 유효기간 | 24시간 | 자동 갱신 로직 구현 |
// ✅ 좋은 예: CancellationToken 사용
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
var result = await client.StockInfo.GetStockInfoAsync("005930", DateTime.Today,
KiwoomStockInfoMarginLoanType.Loan, cts.Token);
// ✅ 좋은 예: 배치 처리
var stockCodes = new[] { "005930", "000660", "035420" };
var tasks = stockCodes.Select(code =>
client.StockInfo.GetStockInfoAsync(code, DateTime.Today, KiwoomStockInfoMarginLoanType.Loan));
var results = await Task.WhenAll(tasks);
// ❌ 나쁜 예: 동기 블로킹 호출
// var result = client.StockInfo.GetStockInfoAsync("005930", DateTime.Today, KiwoomStockInfoMarginLoanType.Loan).Result;- .NET Standard 2.0 (Unity, Xamarin 호환)
- .NET Standard 2.1
- .NET 6.0
- .NET 8.0
- .NET 9.0
- .NET 10.0 (Preview)
이 프로젝트는 MIT 라이선스 하에 배포됩니다.
이 라이브러리는 키움증권과 공식적인 관계가 없는 개인 프로젝트입니다.
실제 거래 시에는 충분한 테스트를 거쳐 사용하시기 바랍니다.
- | ka10079 | 주식틱차트조회요청 체결일 삭제
- | ka20004 | 업종틱차트조회요청 체결일 삭제
- | ka50010 | 금현물체결추이 API 추가 (
GetGoldTradeTrendsAsync) - | ka50012 | 금현물일별추이 API 추가 (
GetGoldDailyTrendsAsync) - | ka50087 | 금현물예상체결 API 추가 (
GetGoldExpectedTradesAsync) - | ka50100 | 금현물시세정보 API 추가 (
GetGoldInfoAsync) - | ka50101 | 금현물 호가 API 추가 (
GetGoldQuotesAsync) - | kt50000 | 금현물 매수주문 API 추가 (
GoldSpotPlaceOrderAsync) - | kt50001 | 금현물 매도주문 API 추가 (
GoldSpotPlaceOrderAsync) - | kt50002 | 금현물 정정주문 API 추가 (
GoldSpotModifyOrderAsync) - | kt50003 | 금현물 취소주문 API 추가 (
GoldSpotCancelOrderAsync) - | ka50079 | 금현물틱차트조회요청 API 추가 (
GetGoldSpotTickChartsAsync) - | ka50080 | 금현물분봉차트조회요청 API 추가 (
GetGoldSpotMinuteChartsAsync) - | ka50081 | 금현물일봉차트조회요청 API 추가 (
GetGoldSpotDailyChartsAsync) - | ka50082 | 금현물주봉차트조회요청 API 추가 (
GetGoldSpotWeeklyChartsAsync) - | ka50083 | 금현물월봉차트조회요청 API 추가 (
GetGoldSpotMonthlyChartsAsync) - | ka50091 | 금현물당일틱차트조회요청 API 추가 (
GetGoldSpotTodayTickChartsAsync) - | ka50092 | 금현물당일분봉차트조회요청 API 추가 (
GetGoldSpotTodayMinuteChartsAsync) - | ka52301 | 금현물투자자현황 API 추가 (
GetGoldSpotInvestorStatusAsync) - | 0I | 국제금환산가격 API 추가 (
OnRealtimeInternationalGoldPriceReceived) KiwoomChartGetTickChartItem수정KiwoomChartGetChartItem수정KiwoomChartGetYearlyCharts수정KiwoomChartGetYearChartItem추가KiwoomChartGetIndustryTickChartItem수정KiwoomChartGetIndustryMinuteCharts수정KiwoomChartGetIndustryMinuteChartItem추가KiwoomChartGetIndustryChartItem수정- API 문서화 개선
- .NET 10.0 타겟 프레임워크 추가(Preview)
GetCreditLoanAvailableStocksAsync요청필드명crd_stk_grae_tp에서crd_stk_grde_tp로 오류 수정KiwoomAccountGetDeposits.MinimumOrderable를decimal로 수정KiwoomAccountGetCreditDepositOrders.StockDepositRate를string로 수정KiwoomAccountGetMarginOrders.AccountMarginRate를string로 수정ExchangeType관련 필드를 모두~StockExchangeType로 수정StockExchangeType관련 필드를 모두~StockExchangeType로 수정IndustryCode필드를KiwoomChartIndustryCode로 수정ContYn필드를bool로 수정NxtEnable필드를bool로 수정Rank필드를decimal에서int로 수정Count관련 필드를 모두int,KiwoomInt로 수정ProfitLoss관련 필드를 모두KiwoomDecimal로 수정AfterMarketSinglePriceChange를KiwoomDecimal로 수정NetBuyVolume,NetBuyAmount필드를KiwoomDecimal로 수정AfterMarketSinglePriceChangeRate를KiwoomDecimal로 수정KiwoomStockInfoGetTradeItem.TradeVolume를KiwoomDecimal로 수정BuyBrokerVolume,SellBrokerVolume필드를KiwoomDecimal로 수정KiwoomMarketConditionGetStockInstitutionTransactionTrendItem.InstitutionPeriodAccumulation,InstitutionDailyNetVolume,ForeignPeriodAccumulation,ForeignDailyNetVolume를KiwoomDecimal로 수정TopBuyExitBroker필드를KiwoomString로 수정HoldingCount를HoldingQuantity로 수정AcquirableCount를AcquirableQuantity로 수정GetHourlyProgramTradeTrendsAsync,GetDailyProgramTradeTrendsAsync파라미터를KiwoomMarketConditionMarketType3로 수정KiwoomMarketConditionGetStockOriginTradeTrends를KiwoomMarketConditionGetStockInstitutionTransactionTrends로 수정
KiwoomString타입 추가KiwoomDecimal로 변환 작업Rank필드를string에서decimal로 수정KiwoomMarketConditionGetDailyInstitutionTradingStockItem에 누락된 필드 추가KiwoomTimeSpanConverter에서 파싱 실패하는 경우는null로 반환하도록 수정
- 합, 합계, 전체:
Total - 수량, 금액:
Quantity,Amount - 누적:
Accumulated - 율, 비율, 대비율:
Rate
- 상위, 하위:
Top,Bottom - 상한, 하한:
Upper,Lower - 상승, 보합, 하락:
Up,Flat,Down - 입금, 출금:
Deposit,Withdrawal - 입고, 출고:
Incoming,Outgoing
- 매수, 매도:
Buy,Sell - 순매수, 순매도:
NetBuy,NetSell - 거래, 매매:
Transaction - 체결, 미체결:
Trade,Unfilled - 위탁:
Consignment - 접수:
Submission
- 호가:
Quote - 잔량, 호가잔량:
RemainQuantity,OrderBook
- 시가, 고가, 저가, 종가:
Open,High,Low,Close
- 거래량, 거래수량, 매매수량:
Volume - 거래금액, 거래대금:
TransactionAmount - 거래량대비:
VolumeChange - 전일거래량:
PreviousDayVolume
- 금일, 전일:
Today,PreviousDay - D+1, D+2:
-D1,-D2 - 일별:
Daily
- 전일대비:
Change,PreviousDayChange(한 레코드 안에 대비 개념이 중복될 경우) - 급증, 급감:
Spike,Drop - 급등, 급락:
Surge,Plunge - 강도:
Momentum - 기호:
Sign
- 개인, 기관, 외국인:
Retail,Institution,Foreign - 거래원:
Broker
- 현금, 신용, 대출, 융자, 담보, 대주, 대용:
Cash,Credit,Loan,CreditLoan,Collateral,ShortSell,Substitute - 변제, 상환:
Repayment - 미납, 미상환:
Unpaid - 납부:
Payment
- 증거금, 미수금:
Margin,Unsettled - 예수금, 보증금:
Deposit
- 수수료, 세금:
Fee,Tax
- 주식, 투자, 원금:
Stock,Investment,Principal - 유가증권, 수익증권, 채권:
Securities,Fund,Bond - 업종:
Industry
- 차익:
Arbitrage - 정산:
Settlement - 보유:
Holding - 행사, 상장:
Exercise,List - 시가총액:
MarketCapitalization - 대차거래:
SecuritiesLending
- 소스코드 주석 추가
- | ka01690 | 일별잔고수익률 API 추가
KiwoomRealtimeQuoteRequests삭제KiwoomRealtimeQuoteRequestItem삭제KiwoomRealtimeQuoteRegistrations삭제KiwoomRealtimeQuoteRegistrationItem삭제KiwoomRealtimeQuoteValue삭제KiwoomRankingInfoGetForeignPeriodTransactionTopItem.NetBuyQuantity를KiwoomDecimal로 수정- 종속성 라이브러리 버전별 분기
- 소스코드 주석 추가
- | ka00198 | 실시간종목조회순위 API 추가
KiwoomStockInfoStockCondition.ExcludeManagedAndPreferredAndCaution추가KiwoomWebSocketStockExchangeType.Unified,NXT추가- | ka10061 | 종목별투자자기관별합계요청의
trde_tp값0으로 고정 - | kt10003 | 주식 취소주문의 API ID를
kt10002로 잘못 호출하고 있던 문제 수정 KiwoomAccountDelistingQueryType을bool로 수정 (isExcludeDelisted)KiwoomChartUseOption을bool로 수정 (isUpdateStockPrice)KiwoomRankingInfoInclusionOption을bool로 수정KiwoomStockInfonInclusionOption을bool로 수정KiwoomStockInfoUseOption을bool로 수정KiwoomElwTradeQuantityType을decimal로 수정 (minVolume)KiwoomRankingInfoTradeQuantityType을decimal로 수정 (minVolume)KiwoomRankingInfoTradePriceCondition을decimal로 수정 (minTransactionAmount)KiwoomStockInfoTradeQuantityType을decimal로 수정 (minVolume)KiwoomForeignInstitutionPeriodQueryType을int로 수정 (period)KiwoomAccountDepositQueryType.General을KiwoomAccountDepositQueryType.Normal로 수정KiwoomMarketConditionEstimatedUnitPriceType을KiwoomMarketConditionUnitPriceType로 수정KiwoomRankingInfoTradeQuantitySortType.TradingVolume을Volume로 수정KiwoomRankingInfoTradeQuantitySortType.TradingAmount을TransactionAmount로 수정KiwoomRankingInfoPreviousTradeQuantityQueryType.Top100ByYesterdayTradingAmount을Top100ByYesterdayTransactionAmount로 수정KiwoomWebSocketRealtimeOrderExecution.ExchangeType타입을KiwoomWebSocketStockExchangeType로 수정KiwoomWebSocketRealtimeStockExecution.ExchangeType타입을KiwoomWebSocketStockExchangeType로 수정KiwoomForeignInstitutionNetSellAmountType삭제 (2고정값)KiwoomSecuritiesLendingQueryType삭제
- 아이콘 업데이트 및 NuGet 패키지 메타데이터 개선
- 코드 문서화 개선
- 프로젝트 아이콘 변경
- README 문서 구조 개선
- NuGet 패키지 최초 릴리즈
- 패키지 메타데이터 및 설명 추가
- API 문서화 개선
- 빌드 설정 최적화
- FAQ 문서 추가
- 패키지 참조 오류 수정
⭐ 이 프로젝트가 도움이 되었다면 스타를 눌러주세요!