주문 (order)¶
매수·매도·정정·취소 등 주문 기능을 담당하는 모듈입니다.
실계좌 주의
env="real" 환경에서는 실제 계좌에 주문이 접수됩니다.
반드시 env="demo" (모의투자)로 먼저 테스트하세요.
파라미터 타입 안내¶
모든 고정 선택지 파라미터는 의미 있는 문자열 키를 사용합니다. API 내부 코드(숫자)로의 변환은 라이브러리가 자동으로 처리합니다.
| 타입 | 값 | 의미 |
|---|---|---|
OrderTradeType |
"market" / "limit" / "conditional" / "best" / "priority" / "stop" / "mid" / "limit_ioc" / "market_ioc" / "best_ioc" / "limit_fok" / "market_fok" / "best_fok" / "mid_ioc" / "mid_fok" / "pre_market" / "after_hours" / "post_market" |
매매구분 |
OrderExchange |
"KRX" / "NXT" / "SOR" |
국내거래소구분 |
매매구분 상세¶
| 값 | 한글명 | 비고 |
|---|---|---|
"limit" |
보통(지정가) | 가격 지정 필수 |
"market" |
시장가 | price 생략 가능 |
"conditional" |
조건부지정가 | |
"best" |
최유리지정가 | |
"priority" |
최우선지정가 | |
"stop" |
스톱지정가 | condition_price 지정 필수 |
"mid" |
중간가 | |
"limit_ioc" |
보통(IOC) | |
"market_ioc" |
시장가(IOC) | |
"best_ioc" |
최유리(IOC) | |
"limit_fok" |
보통(FOK) | |
"market_fok" |
시장가(FOK) | |
"best_fok" |
최유리(FOK) | |
"mid_ioc" |
중간가(IOC) | |
"mid_fok" |
중간가(FOK) | |
"pre_market" |
장시작전시간외 | |
"after_hours" |
시간외단일가 | |
"post_market" |
장마감후시간외 |
API 레퍼런스¶
kiwoompy.order
¶
주문 모듈 — 주식·신용 매수/매도/정정/취소 주문 (kt10000~kt10009) 및 금현물 주문·조회 (kt50000~kt50075).
KiwoomOrder
¶
키움 REST API 주문 클라이언트.
주식·신용 매수/매도/정정/취소 주문 TR을 담당한다.
모든 메서드는 KiwoomApi를 통해 HTTP 요청을 전송하며,
응답을 dataclass로 파싱하여 반환한다.
주문은 실계좌에 직접 영향을 미치므로 env="real" 사용 시 주의한다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api
|
KiwoomApi
|
인증 토큰이 설정된 |
required |
Source code in src/kiwoompy/order.py
buy
¶
buy(stock_code: str, quantity: str, trade_type: OrderTradeType, exchange: OrderExchange = 'KRX', price: str = '', condition_price: str = '') -> OrderResponse
주식 매수주문을 제출한다 (kt10000).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stock_code
|
str
|
종목코드 (예: |
required |
quantity
|
str
|
주문수량 (단위: 주). |
required |
trade_type
|
OrderTradeType
|
매매구분.
|
required |
exchange
|
OrderExchange
|
국내거래소구분. |
'KRX'
|
price
|
str
|
주문단가 (단위: 원). 시장가 주문 시 공백. |
''
|
condition_price
|
str
|
조건단가. 스톱지정가( |
''
|
Returns:
| Type | Description |
|---|---|
OrderResponse
|
매수주문 응답 |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류 또는 주문 실패. |
Source code in src/kiwoompy/order.py
cancel
¶
cancel(original_order_no: str, stock_code: str, cancel_quantity: str, exchange: OrderExchange = 'KRX') -> CancelOrderResponse
주식 취소주문을 제출한다 (kt10003).
미체결 주문을 취소한다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original_order_no
|
str
|
원주문번호 (취소할 주문의 주문번호). |
required |
stock_code
|
str
|
종목코드. |
required |
cancel_quantity
|
str
|
취소수량 (단위: 주). |
required |
exchange
|
OrderExchange
|
국내거래소구분. 기본값 |
'KRX'
|
Returns:
| Type | Description |
|---|---|
CancelOrderResponse
|
취소주문 응답 |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류 또는 주문 실패. |
Source code in src/kiwoompy/order.py
credit_buy
¶
credit_buy(stock_code: str, quantity: str, trade_type: OrderTradeType, exchange: OrderExchange = 'KRX', price: str = '', condition_price: str = '') -> OrderResponse
신용 매수주문을 제출한다 (kt10006).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stock_code
|
str
|
종목코드. |
required |
quantity
|
str
|
주문수량 (단위: 주). |
required |
trade_type
|
OrderTradeType
|
매매구분. |
required |
exchange
|
OrderExchange
|
국내거래소구분. 기본값 |
'KRX'
|
price
|
str
|
주문단가 (단위: 원). 시장가 주문 시 공백. |
''
|
condition_price
|
str
|
조건단가. 기본값 공백. |
''
|
Returns:
| Type | Description |
|---|---|
OrderResponse
|
신용 매수주문 응답 |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류 또는 주문 실패. |
Source code in src/kiwoompy/order.py
credit_cancel
¶
credit_cancel(original_order_no: str, stock_code: str, cancel_quantity: str, exchange: OrderExchange = 'KRX') -> CancelOrderResponse
신용 취소주문을 제출한다 (kt10009).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original_order_no
|
str
|
원주문번호. |
required |
stock_code
|
str
|
종목코드. |
required |
cancel_quantity
|
str
|
취소수량 (단위: 주). |
required |
exchange
|
OrderExchange
|
국내거래소구분. 기본값 |
'KRX'
|
Returns:
| Type | Description |
|---|---|
CancelOrderResponse
|
신용 취소주문 응답 |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류 또는 주문 실패. |
Source code in src/kiwoompy/order.py
credit_modify
¶
credit_modify(original_order_no: str, stock_code: str, modify_quantity: str, modify_price: str, exchange: OrderExchange = 'KRX', modify_condition_price: str = '') -> ModifyOrderResponse
신용 정정주문을 제출한다 (kt10008).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original_order_no
|
str
|
원주문번호. |
required |
stock_code
|
str
|
종목코드. |
required |
modify_quantity
|
str
|
정정수량 (단위: 주). |
required |
modify_price
|
str
|
정정단가 (단위: 원). |
required |
exchange
|
OrderExchange
|
국내거래소구분. 기본값 |
'KRX'
|
modify_condition_price
|
str
|
정정조건단가. 기본값 공백. |
''
|
Returns:
| Type | Description |
|---|---|
ModifyOrderResponse
|
신용 정정주문 응답 |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류 또는 주문 실패. |
Source code in src/kiwoompy/order.py
credit_sell
¶
credit_sell(stock_code: str, quantity: str, trade_type: OrderTradeType, credit_deal_type: str, exchange: OrderExchange = 'KRX', price: str = '', credit_loan_date: str = '', condition_price: str = '') -> OrderResponse
신용 매도주문을 제출한다 (kt10007).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stock_code
|
str
|
종목코드. |
required |
quantity
|
str
|
주문수량 (단위: 주). |
required |
trade_type
|
OrderTradeType
|
매매구분. |
required |
credit_deal_type
|
str
|
신용거래구분. |
required |
exchange
|
OrderExchange
|
국내거래소구분. 기본값 |
'KRX'
|
price
|
str
|
주문단가 (단위: 원). 시장가 주문 시 공백. |
''
|
credit_loan_date
|
str
|
대출일 ( |
''
|
condition_price
|
str
|
조건단가. 기본값 공백. |
''
|
Returns:
| Type | Description |
|---|---|
OrderResponse
|
신용 매도주문 응답 |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류 또는 주문 실패. |
Source code in src/kiwoompy/order.py
gold_balance
¶
금현물 잔고를 확인한다 (kt50020).
Returns:
| Type | Description |
|---|---|
GoldBalance
|
class: |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류. |
Source code in src/kiwoompy/order.py
gold_buy
¶
gold_buy(stock_code: GoldStockCode, order_quantity: str, trade_type: GoldOrderTradeType, order_price: str = '') -> GoldOrderResponse
금현물 매수주문을 제출한다 (kt50000).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stock_code
|
GoldStockCode
|
금현물 종목코드.
|
required |
order_quantity
|
str
|
주문수량 (단위: g). |
required |
trade_type
|
GoldOrderTradeType
|
매매구분. |
required |
order_price
|
str
|
주문단가. 시장가 주문 시 생략 가능. |
''
|
Returns:
| Type | Description |
|---|---|
GoldOrderResponse
|
class: |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류 또는 주문 실패. |
Source code in src/kiwoompy/order.py
gold_cancel
¶
gold_cancel(stock_code: GoldStockCode, original_order_no: str, cancel_quantity: str) -> GoldCancelOrderResponse
금현물 취소주문을 제출한다 (kt50003).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stock_code
|
GoldStockCode
|
금현물 종목코드.
|
required |
original_order_no
|
str
|
원주문번호. |
required |
cancel_quantity
|
str
|
취소수량 (단위: g). |
required |
Returns:
| Type | Description |
|---|---|
GoldCancelOrderResponse
|
class: |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류 또는 주문 실패. |
Source code in src/kiwoompy/order.py
gold_deposit
¶
금현물 예수금을 조회한다 (kt50021).
Returns:
| Type | Description |
|---|---|
GoldDeposit
|
class: |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류. |
Source code in src/kiwoompy/order.py
gold_modify
¶
gold_modify(stock_code: GoldStockCode, original_order_no: str, modify_quantity: str, modify_price: str) -> GoldModifyOrderResponse
금현물 정정주문을 제출한다 (kt50002).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stock_code
|
GoldStockCode
|
금현물 종목코드.
|
required |
original_order_no
|
str
|
원주문번호. |
required |
modify_quantity
|
str
|
정정수량 (단위: g). |
required |
modify_price
|
str
|
정정단가. |
required |
Returns:
| Type | Description |
|---|---|
GoldModifyOrderResponse
|
class: |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류 또는 주문 실패. |
Source code in src/kiwoompy/order.py
gold_order_detail
¶
gold_order_detail(stock_bond_type: StockBondType, sell_type: SellType, exchange: str, query_type: OrderHistoryQueryType = 'asc', order_date: str = '', stock_code: str = '', from_order_no: str = '') -> GoldOrderDetail
금현물 주문체결을 조회한다 (kt50031).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stock_bond_type
|
StockBondType
|
주식채권구분. |
required |
sell_type
|
SellType
|
매도수구분. |
required |
exchange
|
str
|
국내거래소구분. |
required |
query_type
|
OrderHistoryQueryType
|
조회구분. |
'asc'
|
order_date
|
str
|
주문일자 ( |
''
|
stock_code
|
str
|
종목코드. 공백 시 전체 종목. |
''
|
from_order_no
|
str
|
시작주문번호. 공백 시 전체 주문. |
''
|
Returns:
| Type | Description |
|---|---|
GoldOrderDetail
|
class: |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류. |
Source code in src/kiwoompy/order.py
gold_order_status
¶
gold_order_status(order_date: str, market_deal_type: str, stock_bond_type: StockBondType, sell_type: SellType, query_type: GoldOrderQueryType = 'asc', stock_code: str = '', from_order_no: str = '', exchange: str = '%') -> GoldOrderStatus
금현물 주문체결전체를 조회한다 (kt50030).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_date
|
str
|
주문일자 ( |
required |
market_deal_type
|
str
|
시장구분. |
required |
stock_bond_type
|
StockBondType
|
주식채권구분. |
required |
sell_type
|
SellType
|
매도수구분. |
required |
query_type
|
GoldOrderQueryType
|
조회구분. |
'asc'
|
stock_code
|
str
|
종목코드. 공백 시 전체 종목. |
''
|
from_order_no
|
str
|
시작주문번호. 공백 시 전체 주문. |
''
|
exchange
|
str
|
국내거래소구분. |
'%'
|
Returns:
| Type | Description |
|---|---|
GoldOrderStatus
|
class: |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류. |
Source code in src/kiwoompy/order.py
gold_sell
¶
gold_sell(stock_code: GoldStockCode, order_quantity: str, trade_type: GoldOrderTradeType, order_price: str = '') -> GoldOrderResponse
금현물 매도주문을 제출한다 (kt50001).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stock_code
|
GoldStockCode
|
금현물 종목코드.
|
required |
order_quantity
|
str
|
주문수량 (단위: g). |
required |
trade_type
|
GoldOrderTradeType
|
매매구분. |
required |
order_price
|
str
|
주문단가. 시장가 주문 시 생략 가능. |
''
|
Returns:
| Type | Description |
|---|---|
GoldOrderResponse
|
class: |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류 또는 주문 실패. |
Source code in src/kiwoompy/order.py
gold_trade_history
¶
gold_trade_history(start_date: str = '', end_date: str = '', trade_type: GoldTransactionType = 'all', stock_code: str = '') -> GoldTradeHistory
금현물 거래내역을 조회한다 (kt50032).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_date
|
str
|
시작일자 ( |
''
|
end_date
|
str
|
종료일자 ( |
''
|
trade_type
|
GoldTransactionType
|
구분. |
'all'
|
stock_code
|
str
|
종목코드. 공백 시 전체 종목. |
''
|
Returns:
| Type | Description |
|---|---|
GoldTradeHistory
|
class: |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류. |
Source code in src/kiwoompy/order.py
gold_unfilled
¶
gold_unfilled(order_date: str, market_deal_type: str, stock_bond_type: StockBondType, sell_type: SellType, query_type: GoldOrderQueryType = 'asc', stock_code: str = '', from_order_no: str = '', exchange: str = '%') -> GoldUnfilled
금현물 미체결을 조회한다 (kt50075).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_date
|
str
|
주문일자 ( |
required |
market_deal_type
|
str
|
시장구분. |
required |
stock_bond_type
|
StockBondType
|
주식채권구분. |
required |
sell_type
|
SellType
|
매도수구분. |
required |
query_type
|
GoldOrderQueryType
|
조회구분. |
'asc'
|
stock_code
|
str
|
종목코드. 공백 시 전체 종목. |
''
|
from_order_no
|
str
|
시작주문번호. 공백 시 전체 주문. |
''
|
exchange
|
str
|
국내거래소구분. |
'%'
|
Returns:
| Type | Description |
|---|---|
GoldUnfilled
|
class: |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류. |
Source code in src/kiwoompy/order.py
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 | |
modify
¶
modify(original_order_no: str, stock_code: str, modify_quantity: str, modify_price: str, exchange: OrderExchange = 'KRX', modify_condition_price: str = '') -> ModifyOrderResponse
주식 정정주문을 제출한다 (kt10002).
미체결 주문의 수량 또는 가격을 정정한다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original_order_no
|
str
|
원주문번호 (정정할 주문의 주문번호). |
required |
stock_code
|
str
|
종목코드. |
required |
modify_quantity
|
str
|
정정수량 (단위: 주). |
required |
modify_price
|
str
|
정정단가 (단위: 원). |
required |
exchange
|
OrderExchange
|
국내거래소구분. 기본값 |
'KRX'
|
modify_condition_price
|
str
|
정정조건단가. 기본값 공백. |
''
|
Returns:
| Type | Description |
|---|---|
ModifyOrderResponse
|
정정주문 응답 |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류 또는 주문 실패. |
Source code in src/kiwoompy/order.py
sell
¶
sell(stock_code: str, quantity: str, trade_type: OrderTradeType, exchange: OrderExchange = 'KRX', price: str = '', condition_price: str = '') -> OrderResponse
주식 매도주문을 제출한다 (kt10001).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stock_code
|
str
|
종목코드 (예: |
required |
quantity
|
str
|
주문수량 (단위: 주). |
required |
trade_type
|
OrderTradeType
|
매매구분.
|
required |
exchange
|
OrderExchange
|
국내거래소구분. |
'KRX'
|
price
|
str
|
주문단가 (단위: 원). 시장가 주문 시 공백. |
''
|
condition_price
|
str
|
조건단가. 스톱지정가( |
''
|
Returns:
| Type | Description |
|---|---|
OrderResponse
|
매도주문 응답 |
Raises:
| Type | Description |
|---|---|
KiwoomAuthError
|
토큰 미발급 또는 인증 실패. |
KiwoomApiError
|
서버 오류 또는 주문 실패. |