コード例 #1
0
 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, KiwoomOpenApiEventHandler)
     else:
         handler = KiwoomOpenApiAllEventHandler(self.control, context)
     with handler:
         result = function(*arguments)
         response = KiwoomOpenApiService_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 = KiwoomOpenApiService_pb2.CallAndListenResponse()
             response.listen_response = listen_response
             yield response
コード例 #2
0
 def TransactionCall(self,
                     rqname,
                     trcode,
                     scrnno,
                     inputs,
                     stop_condition=None):
     request = KiwoomOpenApiService_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
             '<=': KiwoomOpenApiService_pb2.TransactionStopConditionCompartor.LESS_THAN_OR_EQUAL_TO,
             '<': KiwoomOpenApiService_pb2.TransactionStopConditionCompartor.LESS_THAN,
             '>=': KiwoomOpenApiService_pb2.TransactionStopConditionCompartor.GREATER_THAN_OR_EQUAL_TO,
             '>': KiwoomOpenApiService_pb2.TransactionStopConditionCompartor.GREATER_THAN,
             '==': KiwoomOpenApiService_pb2.TransactionStopConditionCompartor.EQUAL_TO,
             '!=': KiwoomOpenApiService_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)
コード例 #3
0
 def RealCall(self,
              scrnno,
              codes,
              fids,
              realtype=None,
              infer_fids=False,
              readable_names=False,
              fast_parse=False):
     request = KiwoomOpenApiService_pb2.RealRequest()
     if scrnno is None:
         scrnnos = []
     elif isinstance(scrnno, str):
         scrnnos = [scrnno]
     else:
         scrnnos = scrnno
     fids = [int(fid) for fid in fids]
     if realtype is None:
         realtype = '0'
     request.screen_no.extend(scrnnos)  # 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)
コード例 #4
0
 def register_code(self, code):
     request = KiwoomOpenApiService_pb2.BidirectionalRealRequest()
     code_list = [code]
     fid_list = RealType.get_fids_by_realtype('주식시세')
     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)
     logging.debug('Registering code %s for real events', code)
コード例 #5
0
    def __init__(self, stub):
        self._stub = stub
        self._slots = [
            'OnReceiveMsg',
            'OnReceiveTrData',
            'OnReceiveChejanData',
            'OnEventConnect',
        ]

        request = KiwoomOpenApiService_pb2.ListenRequest()
        request.slots.extend(self._slots)  # pylint: disable=no-member
        self._response_iterator = self._stub.Listen(request)
        self._subscription = rx.from_iterable(
            self._response_iterator).subscribe(self)
コード例 #6
0
 def ConditionCall(self,
                   scrnno,
                   condition_name,
                   condition_index,
                   search_type,
                   with_info=False,
                   is_future_option=False,
                   request_name=None):
     request = request = KiwoomOpenApiService_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)
コード例 #7
0
 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 = KiwoomOpenApiService_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
コード例 #8
0
    def OrderCall(self,
                  rqname,
                  scrnno,
                  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 = KiwoomOpenApiService_pb2.OrderRequest()
        request.request_name = rqname or ''
        request.screen_no = str(scrnno).zfill(4) if scrnno 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)
コード例 #9
0
 def LoginCall(self):
     request = KiwoomOpenApiService_pb2.LoginRequest()
     for response in self._stub.LoginCall(request):
         errcode = response.arguments[0].long_value
     return errcode
コード例 #10
0
 def SetLogLevel(self, level, logger=''):
     request = KiwoomOpenApiService_pb2.SetLogLevelRequest()
     request.level = level
     request.logger = logger
     return self._stub.SetLogLevel(request)
コード例 #11
0
 def LoadConditionCall(self):
     request = KiwoomOpenApiService_pb2.LoadConditionRequest()
     for response in self._stub.LoadConditionCall(request):
         ret = response.arguments[0].long_value
         msg = response.arguments[1].string_value
     return (ret, msg)
コード例 #12
0
 def _create_call_request(cls, name, args):
     request = KiwoomOpenApiService_pb2.CallRequest()
     request.name = name
     convert_arguments_from_python_to_protobuf(args, request.arguments)  # pylint: disable=no-member
     return request
コード例 #13
0
 def initialize(self):
     request = KiwoomOpenApiService_pb2.BidirectionalRealRequest()
     request.initialize_request.fid_list.extend(self._fid_list)  # pylint: disable=no-member
     self._request_observer.on_next(request)
コード例 #14
0
 def SetLogLevel(self, request, context):
     level = request.level
     logger = request.logger
     set_loglevel(level, logger)
     response = KiwoomOpenApiService_pb2.SetLogLevelResponse()
     return response