Skip to content

Commit f8380f2

Browse files
authored
Merge pull request #53 from Soju06/fix/44-foreign-realtime-order-execution-event
해외주식 실시간 체결 이벤트 버그 수정
2 parents 9af14cc + acd06d2 commit f8380f2

File tree

5 files changed

+25
-16
lines changed

5 files changed

+25
-16
lines changed

pykis/api/account/order.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def __eq__(self, value: object | KisOrderNumber) -> bool:
525525
self.account_number == value.account_number # type: ignore
526526
and self.symbol == value.symbol # type: ignore
527527
and self.market == value.market # type: ignore
528-
and self.branch == value.branch # type: ignore
528+
and (self.foreign or self.branch == value.branch) # type: ignore
529529
and int(self.number) == int(value.number) # type: ignore
530530
)
531531
except AttributeError:

pykis/api/websocket/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
KisDomesticRealtimeOrderbook,
44
KisUSRealtimeOrderbook,
55
)
6-
from pykis.api.websocket.order_execution import KisDomesticRealtimeOrderExecution
6+
from pykis.api.websocket.order_execution import (
7+
KisDomesticRealtimeOrderExecution,
8+
KisForeignRealtimeOrderExecution,
9+
)
710
from pykis.api.websocket.price import KisDomesticRealtimePrice, KisForeignRealtimePrice
811
from pykis.responses.websocket import KisWebsocketResponse
912

@@ -15,4 +18,6 @@
1518
"HDFSASP0": KisUSRealtimeOrderbook,
1619
"H0STCNI0": KisDomesticRealtimeOrderExecution,
1720
"H0STCNI9": KisDomesticRealtimeOrderExecution,
21+
"H0GSCNI0": KisForeignRealtimeOrderExecution,
22+
"H0GSCNI9": KisForeignRealtimeOrderExecution,
1823
}

pykis/api/websocket/order_execution.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,9 @@ class KisForeignRealtimeOrderExecution(KisRealtimeExecutionBase):
392392
None, # 12 CNTG_YN 체결여부 1:주문,정정,취소,거부 2:체결
393393
None, # 13 ACPT_YN 접수여부 1:주문접수 2:확인 3:취소(FOK/IOC)
394394
None, # 14 BRNC_NO 지점번호
395-
KisDecimal["quantity"], # 15 ODER_QTY 주문수량
395+
KisDecimal[
396+
"quantity", Decimal(-1)
397+
], # 15 ODER_QTY 주문수량 ,주문통보인 경우 해당 위치 미출력 (주문통보의 주문수량은 CNTG_QTY 위치에 출력). 체결통보인 경우 해당 위치에 주문수량이 출력
396398
None, # 16 ACNT_NAME 계좌명
397399
None, # 17 CNTG_ISNM 체결종목명
398400
KisAny(FOREIGN_MARKET_CODE_MAP.__getitem__)[
@@ -469,6 +471,9 @@ def __post_init__(self):
469471
self.timezone = get_market_timezone(self.market)
470472
self.time = self.time_kst.astimezone(self.timezone)
471473

474+
if self.quantity < 0:
475+
self.quantity = self.executed_quantity
476+
472477
if self.receipt:
473478
self.quantity = self.executed_quantity
474479
self.executed_quantity = ORDER_QUANTITY(0)

pykis/event/filters/order.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def __filter__(
149149
return not (
150150
order.symbol == value.symbol
151151
and order.market == value.market
152-
and order.branch == value.branch
152+
and (order.foreign or order.branch == value.branch)
153153
and int(order.number) == int(value.number)
154154
and order.account_number == value.account_number
155155
)

pykis/responses/websocket.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Any, Iterable, Protocol, TypeVar, get_args, runtime_checkable
33

44
from pykis import logging
5-
from pykis.responses.dynamic import KisNoneValueError, KisType
5+
from pykis.responses.dynamic import KisNoneValueError, KisType, empty
66
from pykis.responses.types import KisAny
77

88
__all__ = [
@@ -111,9 +111,7 @@ def parse(
111111
field = field.default_type()
112112

113113
if field.field is None:
114-
logging.logger.warning(
115-
f"{response_type.__name__}[{i}] 필드의 이름이 지정되지 않았습니다."
116-
)
114+
logging.logger.warning(f"{response_type.__name__}[{i}] 필드의 이름이 지정되지 않았습니다.")
117115
continue
118116

119117
try:
@@ -124,16 +122,17 @@ def parse(
124122

125123
setattr(response, field.field, value)
126124
except KisNoneValueError:
127-
nullable = (
128-
NoneType in get_args(anno) if (anno := annotation.get(field.field)) else False
129-
)
125+
nullable = NoneType in get_args(anno) if (anno := annotation.get(field.field)) else False
130126

131-
if not nullable:
132-
raise ValueError(
133-
f"{response_type.__name__}.{field.field} 필드가 None일 수 없습니다."
134-
)
127+
default_value = None if field.default is empty else field.default
135128

136-
setattr(response, field.field, None)
129+
if callable(default_value):
130+
default_value = default_value()
131+
132+
if default_value is None and not nullable:
133+
raise ValueError(f"{response_type.__name__}.{field.field} 필드가 None일 수 없습니다.")
134+
135+
setattr(response, field.field, default_value)
137136

138137
except Exception as e:
139138
raise ValueError(

0 commit comments

Comments
 (0)