Beispiel #1
0
    def update(self, model: Document, **kwargs) -> Document:
        for key, value in kwargs.items():
            model[key] = value

        model.status = CONST.STATUS_CRAWLED
        model.updated_at = _current_timestamp
        return model.save()
Beispiel #2
0
 def __init__(self, *args, **kwargs):
     '''
     Save at the end of construction.
     '''
     # We want to intialize should_save_attrs because __init__ calls __setsttr__.
     self.should_save_attrs = False
     Document.__init__(self, *args, **kwargs)
     self.should_save_attrs = True
Beispiel #3
0
 def __init__(self, *args, **kwargs):
     '''
     Save at the end of construction.
     '''
     # We want to intialize should_save_attrs because __init__ calls __setsttr__.
     self.should_save_attrs = False
     Document.__init__(self, *args, **kwargs)
     self.should_save_attrs = True
Beispiel #4
0
 def __setattr__(self, name, value):
     '''
     Setting attributes often consistates a save.
     '''
     Document.__setattr__(self, name, value)
     # We do not want to save recursively so we use should_save_attrs.
     if name in self._fields and self.should_save_attrs:
         self.should_save_attrs = False
         self.save()
         self.should_save_attrs = True
Beispiel #5
0
 def __setattr__(self, name, value):
     '''
     Setting attributes often consistates a save.
     '''
     Document.__setattr__(self, name, value)
     # We do not want to save recursively so we use should_save_attrs.
     if name in self._fields and self.should_save_attrs:
         self.should_save_attrs = False
         self.save()
         self.should_save_attrs = True
Beispiel #6
0
 def __init__(self, *args, **kwargs):
     Document.__init__(*args, **kwargs)
     if 'mid' in kwargs:
         self.mid = kwargs['mid']
     if 'text' in kwargs:
         self.text = kwargs['text']
     if 'sender' in kwargs:
         self.sender = kwargs['sender']
     if 'seen' in kwargs:
         self.seen = kwargs['seen']
Beispiel #7
0
    def __init__(self, *args, **kwargs):
        Document.__init__(self, *args, **kwargs)

        if 'aid' in kwargs:
            self.aid = kwargs['aid']
        if 'class_id' in kwargs:
            self.class_id = kwargs['class_id']
        if 'due' in kwargs:
            self.due = kwargs['due']
        if 'description' in kwargs:
            self.description = kwargs['description']
    def __init__(self, *args, **kwargs):
        Document.__init__(self, *args, **kwargs)

        if 'tid' in kwargs:
            self.tid = kwargs['tid']
        if 'name' in kwargs:
            self.name = kwargs['name']
        if 'user_ids' in kwargs:
            self.user_ids = kwargs['user_ids']
        if 'message_ids' in kwargs:
            self.message_ids = kwargs['message_ids']
        if 'task_ids' in kwargs:
            self.task_ids = kwargs['task_ids']
        if 'meeting_ids' in kwargs:
            self.meeting_ids = kwargs['meeting_ids']
    def __init__(self, *args, **kwargs):
        Document.__init__(self, *args, **kwargs)

        if 'pid' in kwargs:
            self.pid = kwargs['pid']
        if 'name' in kwargs:
            self.name = kwargs['name']
        if 'descr' in kwargs:
            self.descr = kwargs['descr']
        if 'url' in kwargs:
            self.url = kwargs['url']
        if 'team_ids' in kwargs:
            self.team_ids = kwargs['team_ids']
        if 'deliverable_ids' in kwargs:
            self.deliverable_ids = kwargs['deliverable_ids']
Beispiel #10
0
    def __init__(self, *args, **kwargs):
        Document.__init__(self, *args, **kwargs)

        if 'cid' in kwargs:
            self.cid = kwargs['cid']
        if 'name' in kwargs:
            self.name = kwargs['name']
        if 'descr' in kwargs:
            self.descr = kwargs['descr']
        if 'proj_ids' in kwargs:
            self.proj_ids = kwargs['proj_ids']
        if 'assign_id' in kwargs:
            self.assign_id = kwargs['assign_id']
        if 'instruct_id' in kwargs:
            self.instruct_id = kwargs['instruct_id']
 def __init__(self, *args, **kwargs):
     Document.__init__(self, *args, **kwargs)
     if 'uid' in kwargs:
         self.uid = kwargs['uid']
     if 'first_name' in kwargs:
         self.first_name = kwargs['first_name']
     if 'last_name' in kwargs:
         self.last_name = kwargs['last_name']
     if 'username' in kwargs:
         self.username = kwargs['username']
     if 'type' in kwargs:
         self.type = kwargs['type']
     if 'message_ids' in kwargs:
         self.message_ids = kwargs['message_ids']
     if 'encrypt_pw' in kwargs:
         self.encrypt_pw = kwargs['encrypt_pw']
Beispiel #12
0
    def is_exist(document: Document,
                 exp_message: Text = None,
                 raise_error=True,
                 *args,
                 **kwargs):
        """
        check if document exist

        :param document: document type
        :param exp_message: exception message
        :param raise_error: boolean to raise exception
        :param kwargs: filter parameters
        :return: boolean
        """
        doc = document.objects(**kwargs)
        if doc.__len__():
            if raise_error:
                if Utility.check_empty_string(exp_message):
                    raise AppException("Exception message cannot be empty")
                raise AppException(exp_message)
            else:
                return True
        else:
            if not raise_error:
                return False
Beispiel #13
0
 def to_son(self, use_db_field=True, fields=None):
     data = Document.to_mongo(self,
                              use_db_field=use_db_field,
                              fields=fields)
     data["id"] = data["$oid"]
     del data["$oid"]
     return data
Beispiel #14
0
 def is_exist(
     document: Document, query: Dict, exp_message: Text = None, raise_error=True,
 ):
     doc = document.objects(status=True, __raw__=query)
     if doc.__len__():
         if raise_error:
             if Utility.check_empty_string(exp_message):
                 raise AppException("Exception message cannot be empty")
             raise AppException(exp_message)
         else:
             return True
     else:
         if not raise_error:
             return False
Beispiel #15
0
    def retrieve_field_values(document: Document, field: str, *args, **kwargs):
        """
        Retrieve particular fields in document if exists, else returns None.
        This should only be used when the field is a required field in the document.

        :param document: document type
        :param field: field to retrieve from documents
        :param kwargs: filter parameters
        :return: list of values for a particular field if document exists else None
        """
        documents = document.objects(args, **kwargs)
        values = None
        if documents.__len__():
            values = [getattr(doc, field) for doc in documents]
        return values
Beispiel #16
0
 def is_exist(document: Document,
              exp_message: Text = None,
              raise_error=True,
              *args,
              **kwargs):
     doc = document.objects(**kwargs)
     if doc.__len__():
         if raise_error:
             if Utility.check_empty_string(exp_message):
                 raise AppException("Exception message cannot be empty")
             raise AppException(exp_message)
         else:
             return True
     else:
         if not raise_error:
             return False
Beispiel #17
0
    def ref_klass(self):
        """
          Reference the object
          return:
              the object of self's Reference
        """
        from mongoengine.document import Document, EmbeddedDocument

        if self.ref:
            _known_models = {}
            for klass in Document.__subclasses__():
                if hasattr(klass, "objects"):
                    _known_models[klass.__name__] = klass

                for sub in klass.__subclasses__():
                    if hasattr(sub, "objects"):
                        _known_models[sub.__name__] = sub

                    for _sub in sub.__subclasses__():
                        if hasattr(_sub, "objects"):
                            _known_models[_sub.__name__] = _sub

            return _known_models.get(self.ref, None)
Beispiel #18
0
    def __init__(self):
        super().__init__()
        self.setControl("KFOPENAPI.KFOpenAPICtrl.1")
        self.OnEventConnect.connect(self.on_event_connect)
        self.OnReceiveTrData.connect(self.on_receive_tr_data)
        self.OnReceiveRealData.connect(self.on_receive_real_data)
        self.OnReceiveMsg.connect(self.on_receive_msg)
        self.OnReceiveChejanData.connect(self.on_receive_chejan_data)
        self.future_item_list = []
        self.future_code_list = []
        self.tick_count = {}
        self.screen_number = 1000
        self.account_numbers = []
        self.current_position = {}
        self.stop_loss = {}
        self.basis_ma = 0
        self.code_symbol = ''
        self.basis_tick_unit = 0
        self.basis_time_unit = 0
        self.exit_time = ''
        self.start_time = ''
        self.profit_tick = 0
        self.loss_tick = 0
        self.tick_unit = {}
        self.quantity = 0

        self.is_starting_time = False
        self.is_just_position_close = False
        self.current_skip_candle = 0
        self.skip_candle = 0

        self.maximum_profit = 0
        self.maximum_loss = 0
        self.current_profit_loss = 0 # 실현손익이 +인 상황에서는 0보다 큰 +, -인 상황에서는 0보다 작은 -

        self.switching_strategy = 0

        self.stop_loss_candle_count = 0

        self.current_entry_price = {}

        self.current_tick_close = 0
        self.current_tick_high = 0
        self.current_tick_low = 0
        self.current_tick_open = 0

        self.current_minute_close = 0
        self.current_minute_high = 0
        self.current_minute_low = 0
        self.current_minute_open = 0

        self.target_minute_index = -1
        self.target_minutes = [1, 3, 5, 15, 30]
        self.minute_1_range = [str(minute).zfill(2) for minute in range(0, 60)]
        self.minute_3_range = [str(minute).zfill(2) for minute in range(0, 60, 3)]
        self.minute_5_range = [str(minute).zfill(2) for minute in range(0, 60, 5)]
        self.minute_15_range = [str(minute).zfill(2) for minute in range(0, 60, 15)]
        self.minute_30_range = [str(minute).zfill(2) for minute in range(0, 60, 30)]
        self.current_minute = None

        self.target_hour_index = -1
        self.target_hours = [60, 120, 180, 240, 360, 720]
        self.hour_1_range = [str(minute).zfill(2) for minute in range(0, 24)]
        self.hour_2_range = [str(minute).zfill(2) for minute in range(0, 24, 2)]
        self.hour_3_range = [str(minute).zfill(2) for minute in range(0, 24, 3)]
        self.hour_4_range = [str(minute).zfill(2) for minute in range(0, 24, 4)]
        self.hour_6_range = [str(minute).zfill(2) for minute in range(0, 24, 6)]
        self.hour_12_range = [str(minute).zfill(2) for minute in range(0, 24, 12)]
        self.current_hour = None

        self.login()
        mongoengine.connect(host='mongodb://localhost:27017/kiwoom?connect=false')
        db = Document._get_db()
        db.drop_collection('tick')
        db.drop_collection('minute')
Beispiel #19
0
 def save(self, *args, **kwargs):
     self.modified = datetime.utcnow()
     return Document.save(self, *args, **kwargs)
 def to_son(self,use_db_field=True, fields=None):
     data = Document.to_mongo(self, use_db_field=use_db_field, fields=fields)
     data["id"] = data["$oid"]
     del data["$oid"]
     return data