@@ -838,12 +838,14 @@ async def _run() -> dict:
838838
839839 if not target_stock :
840840 return {'success' : False , 'message' : '보유 중인 주식이 아닙니다.' }
841-
841+
842842 avg_price = float (target_stock ['pchs_avg_pric' ])
843843 current_price = float (target_stock ['now_pric2' ])
844- qty = int (float (target_stock ['ovrs_cblc_qty' ]))
845-
846- res = await process_kis_overseas_sell_orders_with_analysis (kis , symbol , current_price , avg_price , qty )
844+ # 매도 시 미체결 주문을 제외한 주문 가능 수량(ord_psbl_qty)을 사용
845+ qty = int (float (target_stock .get ('ord_psbl_qty' , target_stock .get ('ovrs_cblc_qty' , 0 ))))
846+ exchange_code = target_stock .get ('ovrs_excg_cd' , 'NASD' )
847+
848+ res = await process_kis_overseas_sell_orders_with_analysis (kis , symbol , current_price , avg_price , qty , exchange_code )
847849 return res
848850 except Exception as e :
849851 return {'success' : False , 'error' : str (e )}
@@ -1125,8 +1127,11 @@ async def _run() -> dict:
11251127 name = stock .get ('ovrs_item_name' )
11261128 avg_price = float (stock .get ('pchs_avg_pric' , 0 ))
11271129 current_price = float (stock .get ('now_pric2' , 0 ))
1128- qty = int (float (stock .get ('ovrs_cblc_qty' , 0 )))
1129-
1130+ # 매도 시 미체결 주문을 제외한 주문 가능 수량(ord_psbl_qty)을 사용
1131+ # ord_psbl_qty가 없으면 ovrs_cblc_qty를 fallback으로 사용
1132+ qty = int (float (stock .get ('ord_psbl_qty' , stock .get ('ovrs_cblc_qty' , 0 ))))
1133+ exchange_code = stock .get ('ovrs_excg_cd' , 'NASD' )
1134+
11301135 self .update_state (
11311136 state = 'PROGRESS' ,
11321137 meta = {
@@ -1137,9 +1142,9 @@ async def _run() -> dict:
11371142 'percentage' : int ((index / total_count ) * 100 )
11381143 }
11391144 )
1140-
1145+
11411146 try :
1142- res = await process_kis_overseas_sell_orders_with_analysis (kis , symbol , current_price , avg_price , qty )
1147+ res = await process_kis_overseas_sell_orders_with_analysis (kis , symbol , current_price , avg_price , qty , exchange_code )
11431148 results .append ({'name' : name , 'symbol' : symbol , 'success' : res ['success' ], 'message' : res ['message' ]})
11441149 # 매도 성공 시 텔레그램 알림
11451150 if res .get ('success' ) and res .get ('orders_placed' , 0 ) > 0 :
@@ -1276,7 +1281,8 @@ async def _run() -> dict:
12761281 name = stock .get ('ovrs_item_name' )
12771282 avg_price = float (stock .get ('pchs_avg_pric' , 0 ))
12781283 current_price = float (stock .get ('now_pric2' , 0 ))
1279- qty = int (float (stock .get ('ovrs_cblc_qty' , 0 )))
1284+ # 매도 시 미체결 주문을 제외한 주문 가능 수량(ord_psbl_qty)을 사용
1285+ qty = int (float (stock .get ('ord_psbl_qty' , stock .get ('ovrs_cblc_qty' , 0 ))))
12801286 exchange_code = stock .get ('ovrs_excg_cd' , 'NASD' )
12811287
12821288 stock_steps = []
@@ -1358,7 +1364,7 @@ async def _run() -> dict:
13581364 # 5. 매도
13591365 self .update_state (state = 'PROGRESS' , meta = {'status' : f'{ symbol } 매도 주문 중...' , 'current' : index , 'total' : total_count , 'percentage' : int ((index / total_count ) * 100 )})
13601366 try :
1361- res = await process_kis_overseas_sell_orders_with_analysis (kis , symbol , current_price , avg_price , qty )
1367+ res = await process_kis_overseas_sell_orders_with_analysis (kis , symbol , current_price , avg_price , qty , exchange_code )
13621368 stock_steps .append ({'step' : '매도' , 'result' : res })
13631369 # 매도 성공 시 텔레그램 알림
13641370 if res .get ('success' ) and res .get ('orders_placed' , 0 ) > 0 :
0 commit comments