def CustomCallAndListen(self, request, context):
     name = request.name
     arguments = convert_arguments_from_protobuf_to_python(
         request.arguments)
     function = getattr(self.control, name)
     code = request.listen_request.code
     class_name = request.listen_request.class_name
     if code and class_name:
         g = {}
         l = {}
         exec(code, g, l)  # pylint: disable=exec-used
         handler = eval(class_name, g, l)(self.control, request, context)  # pylint: disable=eval-used
         assert isinstance(handler, KiwoomOpenApiPlusEventHandler)
     else:
         handler = KiwoomOpenApiPlusAllEventHandler(self.control, context)
     with handler:
         result = function(*arguments)
         response = KiwoomOpenApiPlusService_pb2.CallAndListenResponse()
         if isinstance(result, str):
             response.call_response.return_value.string_value = result  # pylint: disable=no-member
         elif isinstance(result, int):
             response.call_response.return_value.long_value = result  # pylint: disable=no-member
         elif result is None:
             pass
         else:
             raise TypeError(
                 'Unexpected return value type from server side dynamicCall(): %s'
                 % type(result))
         yield response
         for listen_response in handler:
             response = KiwoomOpenApiPlusService_pb2.CallAndListenResponse()
             response.listen_response = listen_response
             yield response
 def fn():
     request = KiwoomOpenApiPlusService_pb2.BidirectionalListenRequest(
     )
     request.listen_request.slots.append(self._name)  # pylint: disable=no-member
     observer.on_next(request)
     observer_iterator = iter(observer)
     for i, response in enumerate(
             self._stub.BidirectionalListen(observer_iterator)):  # pylint: disable=unused-variable
         args = convert_arguments_from_protobuf_to_python(
             response.arguments)
         callback(*args)
         request = KiwoomOpenApiPlusService_pb2.BidirectionalListenRequest(
         )
         observer.on_next(request)
示例#3
0
 def RealCall(
     self,
     scrno,
     codes,
     fids,
     realtype=None,
     infer_fids=False,
     readable_names=False,
     fast_parse=False,
 ):
     request = KiwoomOpenApiPlusService_pb2.RealRequest()
     if scrno is None:
         scrnos = []
     elif isinstance(scrno, str):
         scrnos = [scrno]
     else:
         scrnos = scrno
     fids = [int(fid) for fid in fids]
     if realtype is None:
         realtype = "0"
     request.screen_no.extend(scrnos)  # pylint: disable=no-member
     request.code_list.extend(codes)  # pylint: disable=no-member
     request.fid_list.extend(fids)  # pylint: disable=no-member
     request.real_type = realtype
     request.flags.infer_fids = infer_fids  # pylint: disable=no-member
     request.flags.readable_names = readable_names  # pylint: disable=no-member
     request.flags.fast_parse = fast_parse  # pylint: disable=no-member
     return self._stub.RealCall(request)
 def TransactionCall(self,
                     rqname,
                     trcode,
                     scrnno,
                     inputs,
                     stop_condition=None):
     request = KiwoomOpenApiPlusService_pb2.TransactionRequest()
     request.request_name = rqname
     request.transaction_code = trcode
     request.screen_no = scrnno or ''
     for k, v in inputs.items():
         request.inputs[k] = v  # pylint: disable=no-member
     if stop_condition:
         request.stop_condition.name = stop_condition.get('name', '')  # pylint: disable=no-member
         request.stop_condition.value = str(stop_condition.get('value', ''))  # pylint: disable=no-member
         request.stop_condition.comparator = { # pylint: disable=no-member
             '<=': KiwoomOpenApiPlusService_pb2.TransactionStopConditionCompartor.LESS_THAN_OR_EQUAL_TO,
             '<': KiwoomOpenApiPlusService_pb2.TransactionStopConditionCompartor.LESS_THAN,
             '>=': KiwoomOpenApiPlusService_pb2.TransactionStopConditionCompartor.GREATER_THAN_OR_EQUAL_TO,
             '>': KiwoomOpenApiPlusService_pb2.TransactionStopConditionCompartor.GREATER_THAN,
             '==': KiwoomOpenApiPlusService_pb2.TransactionStopConditionCompartor.EQUAL_TO,
             '!=': KiwoomOpenApiPlusService_pb2.TransactionStopConditionCompartor.NOT_EQUAL_TO,
         }.get(stop_condition.get('comparator', '<='))
         request.stop_condition.include_equal = stop_condition.get(
             'include_equal', False)  # pylint: disable=no-member
     return self._stub.TransactionCall(request)
示例#5
0
 def LoginCall(self, credential=None):
     # pylint: disable=no-member
     request = KiwoomOpenApiPlusService_pb2.LoginRequest()
     if credential is not None:
         request.credential.user_id = credential.get(
             "user_id"
         )  # pylint: disable=no-member
         request.credential.user_password = credential.get(
             "user_password"
         )  # pylint: disable=no-member
         request.credential.cert_password = credential.get(
             "cert_password"
         )  # pylint: disable=no-member
         request.credential.is_simulation = credential.get(
             "is_simulation"
         )  # pylint: disable=no-member
         account_passwords = credential.get(
             "account_passwords"
         )  # pylint: disable=no-member
         for account_no, account_password in account_passwords.items():
             request.credential.account_passwords[
                 account_no
             ] = account_password  # pylint: disable=no-member
     for response in self._stub.LoginCall(request):
         errcode = response.arguments[0].long_value
     return errcode
示例#6
0
 def TransactionCall(self, rqname, trcode, scrno, inputs, stop_condition=None):
     # pylint: disable=no-member
     request = KiwoomOpenApiPlusService_pb2.TransactionRequest()
     request.request_name = rqname
     request.transaction_code = trcode
     request.screen_no = scrno or ""
     for k, v in inputs.items():
         request.inputs[k] = v  # pylint: disable=no-member
     if stop_condition:
         request.stop_condition.name = stop_condition.get(
             "name", ""
         )  # pylint: disable=no-member
         request.stop_condition.value = str(
             stop_condition.get("value", "")
         )  # pylint: disable=no-member
         request.stop_condition.comparator = {  # pylint: disable=no-member
             "<=": KiwoomOpenApiPlusService_pb2.TransactionStopConditionCompartor.LESS_THAN_OR_EQUAL_TO,
             "<": KiwoomOpenApiPlusService_pb2.TransactionStopConditionCompartor.LESS_THAN,
             ">=": KiwoomOpenApiPlusService_pb2.TransactionStopConditionCompartor.GREATER_THAN_OR_EQUAL_TO,
             ">": KiwoomOpenApiPlusService_pb2.TransactionStopConditionCompartor.GREATER_THAN,
             "==": KiwoomOpenApiPlusService_pb2.TransactionStopConditionCompartor.EQUAL_TO,
             "!=": KiwoomOpenApiPlusService_pb2.TransactionStopConditionCompartor.NOT_EQUAL_TO,
         }.get(stop_condition.get("comparator", "<="))
         request.stop_condition.include_equal = stop_condition.get(
             "include_equal", False
         )  # pylint: disable=no-member
     return self._stub.TransactionCall(request)
 def register_code(self, code):
     request = KiwoomOpenApiPlusService_pb2.BidirectionalRealRequest()
     code_list = [code]
     fid_list = KiwoomOpenApiPlusRealType.get_fids_by_realtype_name("주식시세")
     request.register_request.code_list.extend(code_list)  # pylint: disable=no-member
     request.register_request.fid_list.extend(fid_list)  # pylint: disable=no-member
     self._request_observer.on_next(request)
     self.logger.debug("Registering code %s for real events", code)
    def __init__(self, stub):
        self._stub = stub

        request = KiwoomOpenApiPlusService_pb2.ListenRequest()
        self._response_iterator = self._stub.OrderListen(request)
        self._response_subject = Subject()
        self._response_scheduler_max_workers = 8
        self._response_scheduler = ThreadPoolScheduler(self._response_scheduler_max_workers)
        self._buffered_response_iterator = QueueBasedBufferedIterator(self._response_iterator)
        self._response_observable = rx.from_iterable(self._buffered_response_iterator, self._response_scheduler)
        self._response_subscription = self._response_observable.subscribe(self._response_subject)

        self._observable = Subject()
        self._subscription = self._response_subject.pipe(
            self.filter_chejan_response(),
            self.convert_to_dict(),
        ).subscribe(self._observable)
示例#9
0
    def OrderCall(
        self,
        rqname,
        scrno,
        account,
        order_type,
        code,
        quantity,
        price,
        quote_type,
        original_order_no=None,
    ):
        """
        [거래구분]
          모의투자에서는 지정가 주문과 시장가 주문만 가능합니다.

          00 : 지정가
          03 : 시장가
          05 : 조건부지정가
          06 : 최유리지정가
          07 : 최우선지정가
          10 : 지정가IOC
          13 : 시장가IOC
          16 : 최유리IOC
          20 : 지정가FOK
          23 : 시장가FOK
          26 : 최유리FOK
          61 : 장전시간외종가
          62 : 시간외단일가매매
          81 : 장후시간외종가

        [주문유형]
          1:신규매수, 2:신규매도 3:매수취소, 4:매도취소, 5:매수정정, 6:매도정정
        """
        request = KiwoomOpenApiPlusService_pb2.OrderRequest()
        request.request_name = rqname or ""
        request.screen_no = str(scrno).zfill(4) if scrno else ""
        request.account_no = str(account) if account else ""
        request.order_type = int(order_type) if order_type else 0
        request.code = code or ""
        request.quantity = int(quantity) if quantity else 0
        request.price = int(price) if price else 0
        request.quote_type = quote_type or ""
        request.original_order_no = original_order_no or ""
        return self._stub.OrderCall(request)
 def Call(self, request, context):
     name = request.name
     arguments = convert_arguments_from_protobuf_to_python(
         request.arguments)
     function = getattr(self.control, name)
     result = function(*arguments)
     response = KiwoomOpenApiPlusService_pb2.CallResponse()
     if isinstance(result, str):
         response.return_value.string_value = result  # pylint: disable=no-member
     elif isinstance(result, int):
         response.return_value.long_value = result  # pylint: disable=no-member
     elif result is None:
         pass
     else:
         raise TypeError(
             "Unexpected return value type from server side dynamicCall(): %s"
             % type(result))
     return response
 def ConditionCall(self,
                   scrnno,
                   condition_name,
                   condition_index,
                   search_type,
                   with_info=False,
                   is_future_option=False,
                   request_name=None):
     request = request = KiwoomOpenApiPlusService_pb2.ConditionRequest()
     request.screen_no = scrnno or ''
     request.condition_name = condition_name
     request.condition_index = condition_index
     request.search_type = search_type
     request.flags.with_info = with_info  # pylint: disable=no-member
     request.flags.is_future_option = is_future_option  # pylint: disable=no-member
     if request_name is not None:
         request.request_name = request_name
     return self._stub.ConditionCall(request)
 def SetLogLevel(self, request, context):
     level = request.level
     logger = request.logger
     logging.getLogger(logger).setLevel(level)
     response = KiwoomOpenApiPlusService_pb2.SetLogLevelResponse()
     return response
 def LoginCall(self):
     request = KiwoomOpenApiPlusService_pb2.LoginRequest()
     for response in self._stub.LoginCall(request):
         errcode = response.arguments[0].long_value
     return errcode
示例#14
0
 def SetLogLevel(self, level, logger=""):
     request = KiwoomOpenApiPlusService_pb2.SetLogLevelRequest()
     request.level = level
     request.logger = logger
     return self._stub.SetLogLevel(request)
示例#15
0
 def LoadConditionCall(self):
     request = KiwoomOpenApiPlusService_pb2.LoadConditionRequest()
     for response in self._stub.LoadConditionCall(request):
         ret = response.arguments[0].long_value
         msg = response.arguments[1].string_value
     return (ret, msg)
 def _stop_observer(cls, observer):
     request = KiwoomOpenApiPlusService_pb2.BidirectionalListenRequest()
     observer.on_next(request)
     observer.on_completed()
示例#17
0
 def _create_call_request(cls, name, args):
     request = KiwoomOpenApiPlusService_pb2.CallRequest()
     request.name = name
     convert_arguments_from_python_to_protobuf(args, request.arguments)  # pylint: disable=no-member
     return request
 def initialize(self):
     request = KiwoomOpenApiPlusService_pb2.BidirectionalRealRequest()
     request.initialize_request.fid_list.extend(self._fid_list)  # pylint: disable=no-member
     self._request_observer.on_next(request)