コード例 #1
0
ファイル: event_recorder.py プロジェクト: mcloong/quant-test
 def add_with_merge(self, event_name, event_param, who, bar_id, datetime):
     ret_id = self.find_event(event_name, 1)
     if (ret_id != -1 and bar_id - ret_id < 5):
         self.df.iloc[-1].param = event_name
         self.df.iloc[-1].id = bar_id
         self.df.iloc[-1].datetime = datetime
         return False
     logUtils.my_print(self.TAG, "add event:%s from=%s" % (event_name, who))
     self.df.loc[len(
         self.df)] = [event_name, event_param, who, bar_id, datetime]
     return True
コード例 #2
0
 def add(self, value, bar_id, datetime):
     df_len = len(self.df)
     if (df_len >= 1 and bar_id - self.df.loc[df_len - 1].id < 5):
         #考虑是否两条消息合并
         self.df.loc[df_len - 1].id = bar_id
         self.df.loc[df_len - 1].datetime = datetime
         self.df.loc[df_len - 1].value = value
         logUtils.my_print(self.TAG, "last record does't timeout,combine")
         return False
     logUtils.my_print(self.TAG, "add one %s value=%d" % (value))
     self.df.loc[df_len] = [value, bar_id, datetime]
     return True
コード例 #3
0
ファイル: avg_record.py プロジェクト: mcloong/quant-test
    def on_bar(self, klines):
        self.df.loc[len(self.df)] = [
            klines.iloc[-1].id, klines.iloc[-1].datetime, self.average
        ]
        if (klines.iloc[-1].low > self.average):
            self.count_of_over += 1
        if (klines.iloc[-1].high < self.average):
            self.count_of_under += 1

        if (self.count > 2 and klines.iloc[-2].high >= self.df.iloc[-2].avg
                and klines.iloc[-1].high < self.average):
            logUtils.my_print(
                self.TAG, "crossunder cross_count=%d" % (len(self.cross_list)))
            self.cross_list.append([klines.iloc[-1].id, self.average])
        if (self.count > 2 and klines.iloc[-2].low <= self.df.iloc[-2].avg
                and klines.iloc[-1].low > self.average):
            logUtils.my_print(
                self.TAG, "crossover cross_count=%d" % (len(self.cross_list)))
            self.cross_list.append([klines.iloc[-1].id, self.average])
        self.count += 1
コード例 #4
0
ファイル: kcommon.py プロジェクト: mcloong/quant-test
 def check(self):
     if (self.position == 0):
         if (self.entry_conds.count() == 0): #表示立即执行
             return MyString.Open
         ret = self.entry_conds.is_ok()
         if (ret == True):
             return MyString.Open
     else:
         ret = self.gain_exit_conds.is_ok()
         if (ret == True):
             my_print(self.name, "gain_exit_conds")
             return MyString.Close
         ret = self.loss_exit_conds.is_ok()
         if (ret == True):
             my_print(self.name, "loss_exit_conds")
             return MyString.LossClose
         ret = self.expired_exit_conds.is_ok()
         if (ret == True):
             my_print(self.name, "expired_exit_conds")
             return MyString.Close
     return MyString.Nothing
コード例 #5
0
ファイル: event_recorder.py プロジェクト: mcloong/quant-test
 def add_with_interval(self, event_name, event_param, who, bar_id, datetime,
                       interval):
     ret_id = self.find_event(event_name, 1)
     df_len = len(self.df)
     if (df_len >= 1 and ret_id != -1 and bar_id - ret_id < interval):
         #考虑是否两条消息合并
         self.df.loc[df_len - 1].id = bar_id
         self.df.loc[df_len - 1].datetime = datetime
         self.df.loc[df_len - 1].param = event_param
         logUtils.my_print(self.TAG, "last record does't timeout,combine")
         return False
     if isinstance(event_param, int):
         logUtils.my_print(
             self.TAG, "add event=%s event_param=%d from=%s " %
             (event_name, event_param, who))
     elif isinstance(event_param, str):
         logUtils.my_print(
             self.TAG, "add event=%s event_param=%s from=%s " %
             (event_name, event_param, who))
     self.df.loc[len(
         self.df)] = [event_name, event_param, who, bar_id, datetime]
     return True