Beispiel #1
0
 def _sendOutExceptionNotification(self, exception):
     stack_trace = traceback.format_exc()
     timestamp_str = str(datetime.now().date())
     subject = '[Warning] %s job exception (%s)!' % (self._instance_id,
                                                     timestamp_str)
     printError('Job execution failed, suspend job: ' + str(exception))
     printError('Stack Trace: \n' + stack_trace)
     self._sendmail(subject, exception, stack_trace)
     printInfo('Email notification sent out.')
Beispiel #2
0
    def run(self):
        self._executeJobs()
        try:
            while True:
                schedule.run_pending()

                if (self._max_job_invocation_count is not None) and \
                   (self._job_invocation_count >= self._max_job_invocation_count):
                    printInfo('Max job invocation count reached. Exiting...')
                    break

                time.sleep(1)

        except (KeyboardInterrupt, SystemExit):
            pass
Beispiel #3
0
  def updateOneMinuteHistory(cls, one_minute_average):
    printWarning('One minute average: ' + str(one_minute_average))
    cls.one_minute_history.append(one_minute_average)

    # check buy in signal
    number_of_periods = 10
    buy_threshold = 0.06
    if not cls.position:
      buy_threshold_check = 0
      if len(cls.one_minute_history) > number_of_periods:
        for index in range(len(cls.one_minute_history) - number_of_periods, len(cls.one_minute_history)):
          delta = ((cls.one_minute_history[index] / cls.one_minute_history[index - 1]) - 1.0) * 100
          if delta >= buy_threshold:
            buy_threshold_check += 1
          printInfo('delta: ' + str(index) + ' vs ' + str(index - 1) + ' => '  + str(delta) + '%' + ' buy_threashold_check: ' + str(buy_threshold_check))

      if (buy_threshold_check == number_of_periods): # all checks have met 
        # send buy in signal
        printError('BUY BUY BUY')
Beispiel #4
0
    def _executeJobs(self):
        if self._jobs_enabled:
            self._disableJobs()
            for job in self._job_list:
                try:

                    job.execute()

                except SuspendExecutionException as see:
                    self._sendOutJobSuspensionNotification(see)
                    printInfo('Shutting down scheduler...')
                    self._shutdown()

                except Exception as e:
                    self._sendOutExceptionNotification(e)
                    pass

                self._job_invocation_count += 1

            self._enableJobs()
Beispiel #5
0
    def _sendmail(self, subject, exception, stack_trace):
        recipient_email = Constants.ERROR_EMAIL_RECIPIENT
        email_body = '\nHi there,\n\n'
        email_body += 'We\'ve got a problem!\n\n'
        email_body += 'Instance ID: %s\n\nException: %s \n\n Stack Trace: %s \n\n'%(\
          self._instance_id, str(exception), stack_trace)
        email_body += 'Please... fix my problem at your earliest convenience :) Thank you!\n\n'
        email_body += 'Cheers!\nSliver match data scraper\n\n'

        printInfo('Sending out email...')
        printInfo('Recipient: %s' % (", ".join(recipient_email)))
        printInfo('Subject: %s' % (subject))
        printInfo('Body: \n%s' % (email_body))

        EmailClient.send(recipient_email=recipient_email,
                         subject=subject,
                         body=email_body)
Beispiel #6
0
import json
from common.constants import Constants
from common.utils import Logger, printInfo, printWarning, printError
from common.scheduler.scheduler import JobScheduler
from feed import Feed 
from brain import Brain


if __name__ == '__main__':
  # load config file
  with open(Constants.CONFIG_FILE) as config_file:
    config = json.load(config_file)
    printInfo('Loading config:')
    printInfo(config)

  # initialize logger
  Logger.init(Constants.LOG_FOLDER)

  # initialize trading brain
  Brain.init()
 
  # setup data feed pulling
  scheduler = JobScheduler(
    instance_id = "data_feed",
    job_execution_interval_in_seconds = Constants.FEED_EXECUTION_FREEQUENCY) 
  job_list = []
  job_list.append(Feed(config))
  scheduler.addJobs(job_list)
  printInfo('Setting up data feed pulling. Will execute every ' + str(Constants.FEED_EXECUTION_FREEQUENCY) + ' seconds..')
  scheduler.run()
Beispiel #7
0
 def init(cls):
   printInfo('TradingBrain initialized')