예제 #1
0
 def _logging_entry(self):
     log_frame = "Entry: {{trade_id: {}, currency_pair: {}, action: {}," \
                 " amount: {}, entry_price: {}, entry_datetime: {}}}"
     log_msg = log_frame.format(self.id_, self.currency_pair, self.action,
                                self.amount, self.entry_price,
                                self.entry_datetime)
     trade_logger.info(log_msg,
                       extra={'strategyid': self._strategy_descriptor()})
예제 #2
0
    def stop(self):
        if self._status.is_stopped():
            trade_logger.info('process already stopped',
                              extra={'strategyid': self._descriptor()})
            return

        self._status.to_stopped()
        self._wake_up_and_next_loop()
예제 #3
0
    def restart(self):
        if self._status.is_running():
            trade_logger.info('process already running',
                              extra={'strategyid': self._descriptor()})
            return

        self._status.to_running()
        trade_logger.info('process restarted',
                          extra={'strategyid': self._descriptor()})
        self._wake_up_and_next_loop()
예제 #4
0
    def _main_loop(self, sec_wait):
        try:
            while self._status.is_alive():
                self._status.wait_until_continuable()

                if self._need_stop():
                    self.stop()
                    break

                trade_logger.info('process running',
                                  extra={'strategyid': self._descriptor()})

                self._trading_routine()
                self._sleep(sec_wait)
        except Exception as e:
            trade_logger.exception(e, extra={'strategyid': self._descriptor()})
            trade_logger.error('exception occurred, process will stop',
                               extra={'strategyid': self._descriptor()})
            self.stop()
        finally:
            trade_logger.info('process stopped',
                              extra={'strategyid': self._descriptor()})
예제 #5
0
 def _logging_exit(self):
     log_frame = "Exit: {{trade_id: {}, currency_pair: {}, exit_price: {}, exit_datetime: {}}}"
     log_msg = log_frame.format(self.id_, self.currency_pair,
                                self.exit_price, self.exit_datetime)
     trade_logger.info(log_msg,
                       extra={'strategyid': self._strategy_descriptor()})
예제 #6
0
 def start(self, *, sec_wait=1):
     self.started = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
     self._status.to_running()
     trade_logger.info('process started',
                       extra={'strategyid': self._descriptor()})
     self._main_loop(sec_wait=sec_wait)
예제 #7
0
 def _need_stop(self):
     if self.stop_rule is None:
         return False
     trade_logger.info('check stop',
                       extra={'strategyid': self._descriptor()})
     return self.stop_rule.need_stop(self._trade)
예제 #8
0
 def _check_exit(self):
     trade_logger.info('check exit',
                       extra={'strategyid': self._descriptor()})
     if self.exit_rule.can_exit(self._trade):
         self._exit()
예제 #9
0
 def _check_entry(self):
     trade_logger.info('check entry',
                       extra={'strategyid': self._descriptor()})
     if self.entry_rule.can_entry():
         self._entry()