Exemplo n.º 1
0
    def calculate(penter: Plato,
                  pexit: Plato,
                  denter: StockDataFrame,
                  dexit: StockDataFrame,
                  begin,
                  end,
                  force=None):
        ts = time()
        penter.calculateAll(denter.copy(deep=True))
        pexit.calculateAll(dexit.copy(deep=True))

        statistics = Statistics(begin, end).calculate(penter, pexit)

        del penter.adviseData
        del pexit.adviseData
        del denter
        del dexit

        skip_negative = FileConfig().get('CALC.SKIP_NEGATIVE', True, bool)
        if force == True:
            skip_negative = False

        if skip_negative:
            isPositive = False
            for period in statistics:
                if statistics[period]['total'] > 0:
                    isPositive = True
                    break
        else:
            isPositive = True

        return (penter, pexit, begin, end, statistics if isPositive else None,
                time() - ts)
Exemplo n.º 2
0
    def __init__(self):
        config = FileConfig()
        config.load_yaml()
        self.modules_path = config.settings["METASPLOIT"]["MODULE_PATH"]

        db_init = DBInit()
        db_init.create()
        self.msf_dao = MsfDAO(db_init.session)
        self.modules_path_list = []
Exemplo n.º 3
0
def run():
    cli = CLI()
    try:
        (options, args) = cli.parse()

        if options.simple_db_migrate_version:
            msg = 'simple-db-migrate v%s' % SIMPLE_DB_MIGRATE_VERSION
            cli.info_and_exit(msg)

        if options.show_colors:
            CLI.show_colors()

        # Create config
        config = FileConfig(options.config_file, options.environment)
        config.put('schema_version', options.schema_version)
        config.put('show_sql', options.show_sql)
        config.put('show_sql_only', options.show_sql_only)
        config.put('new_migration', options.new_migration)
        config.put('drop_db_first', options.drop_db_first)
        config.put('paused_mode', options.paused_mode)
        config.put('log_dir', options.log_dir)
        config.put('label_version', options.label_version)
        config.put('force_use_files_on_down', options.force_use_files_on_down)
        config.put('force_execute_old_migrations_versions',
                   options.force_execute_old_migrations_versions)

        # paused mode forces log_level to 2
        log_level = int(options.log_level)
        if options.paused_mode:
            log_level = 2

        config.put('log_level', log_level)

        # Ask the password for user if configured
        if config.get('db_password') == '<<ask_me>>':
            if options.password:
                passwd = options.password
            else:
                cli.msg(
                    '\nPlease inform password to connect to database "%s@%s:%s"'
                    % (config.get('db_user'), config.get('db_host'),
                       config.get('db_name')))
                passwd = getpass()
            config.remove('db_password')
            config.put('db_password', passwd)

        # If CLI was correctly parsed, execute db-migrate.
        Main(config).execute()
    except KeyboardInterrupt:
        cli.info_and_exit("\nExecution interrupted by user...")
    except Exception, e:
        cli.error_and_exit(str(e))
Exemplo n.º 4
0
    def __init__(self, section_name: str = 'DB'):
        self.db = None

        config = FileConfig()

        try:
            self.db = connect(host=config.get(f'{section_name}.host'),
                              user=config.get(f'{section_name}.user'),
                              passwd=config.get(f'{section_name}.pass'),
                              database=config.get(f'{section_name}.name'))
        except ProgrammingError as e:
            print(f'[DB] [ERROR] {e.msg}')
            raise e
Exemplo n.º 5
0
    def __init__(self):
        config = FileConfig()
        config.load_yaml()
        self.github_api = config.settings["GITHUB_TOKEN"]

        db_init = DBInit()
        db_init.create()
        self.msf_dao = MsfDAO(db_init.session)

        self.session = requests_html.HTMLSession()
        self.session.keep_alive = False
        self.headers = {
            'user-agent':
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.170 Safari/537.36',
        }
Exemplo n.º 6
0
    def __init__(self, fast: int, slow: int, signal: int, period: int):
        self.db = None

        config = FileConfig()

        try:
            self.db = connect(host=config.get('DB.host'),
                              user=config.get('DB.user'),
                              passwd=config.get('DB.pass'),
                              database=config.get('DB.name'))
        except ProgrammingError as e:
            print(f'[DB] [ERROR] {e.msg}')
            raise e

        self.fast = fast
        self.slow = slow
        self.signal = signal
        self.period = period

        self.__table = '_'.join(
            map(str, ['a', self.fast, self.signal, self.period]))
        self.__key = '_'.join(
            map(str, [self.fast, self.slow, self.signal, self.period]))
Exemplo n.º 7
0
parser = argparse.ArgumentParser(description='Start Flypi Server.')
parser.add_argument(
    '--config',
    '-c',
    default=None,
    help=
    'Configuration file to change parameters (default: server_port on 8080, MongoDB connection on localhost:27017)'
)

args = parser.parse_args()

config = Config()
try:
    if args.config is not None:
        config = FileConfig(args.config)
except:
    print "Failed parsing config file, please check that file is accessible and well formatted."
    exit()

app = Bottle()


@app.route('/image/<file_name>')
def img_live(file_name):
    return static_file(file_name, root=lora.ssdv_path)


@app.route('/images/last')
def img_live():
    last_filename = ""
Exemplo n.º 8
0
from config import FileConfig
from json import dumps
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, Float, Text, String, create_engine
from sqlalchemy.orm import sessionmaker, scoped_session

config = FileConfig()

Base = declarative_base()

class Backtest(Base):

    __tablename__ = 'main_backtest'
    __table_args__ = {'extend_existing': True}

    id = Column(Integer, primary_key=True)

    active = Column(Integer)

    buy_fast = Column(Integer)
    buy_slow = Column(Integer)
    buy_signal = Column(Integer)
    buy_period = Column(Integer)

    sell_fast = Column(Integer)
    sell_slow = Column(Integer)
    sell_signal = Column(Integer)
    sell_period = Column(Integer)

    ts_start = Column(Integer)
    ts_end = Column(Integer)
Exemplo n.º 9
0
 def __init__(self):
     config = FileConfig()
     config.load_yaml()
     self.modules_path = config.settings["METASPLOIT"]["MODULE_PATH"]
Exemplo n.º 10
0
def run(options):
    try:
        if options.get('simple_db_migrate_version'):
            msg = 'simple-db-migrate v%s' % SIMPLE_DB_MIGRATE_VERSION
            CLI.info_and_exit(msg)

        if options.get('show_colors'):
            CLI.show_colors()

        # Create config
        if options.get('config_file') or os.path.exists('simple-db-migrate.conf'):
            config = FileConfig(options.get('config_file') or 'simple-db-migrate.conf', options.get('environment'))
        else:
            config = Config()

        config.update('schema_version', options.get('schema_version'))
        config.update('show_sql', options.get('show_sql'))
        config.update('show_sql_only', options.get('show_sql_only'))
        config.update('new_migration', options.get('new_migration'))
        config.update('drop_db_first', options.get('drop_db_first'))
        config.update('paused_mode', options.get('paused_mode'))
        config.update('log_dir', options.get('log_dir'))
        config.update('label_version', options.get('label_version'))
        config.update('force_use_files_on_down', options.get('force_use_files_on_down'))
        config.update('force_execute_old_migrations_versions', options.get('force_execute_old_migrations_versions'))
        config.update('utc_timestamp', options.get('utc_timestamp'))
        config.update('database_user', options.get('database_user'))
        config.update('database_password', options.get('database_password'))
        config.update('database_host', options.get('database_host'))
        config.update('database_port', options.get('database_port'))
        config.update('database_name', options.get('database_name'))

        if config.get('database_port', None):
            config.update('database_port', int(config.get('database_port')))

        if options.get('database_migrations_dir'):
            config.update("database_migrations_dir", Config._parse_migrations_dir(options.get('database_migrations_dir')))

        config.update('database_engine', options.get('database_engine'))
        if not config.get('database_engine', None):
            config.update('database_engine', "mysql")

        config.update('database_version_table', options.get('database_version_table'))
        if not config.get('database_version_table', None):
            config.update('database_version_table', "__db_version__")

        # paused mode forces log_level to 2
        log_level = int(options.get('log_level'))
        if options.get('paused_mode'):
            log_level = 2

        config.update('log_level', log_level)

        # Ask the password for user if configured
        if config.get('database_password') == '<<ask_me>>':
            if options.get('password'):
                passwd = options.get('password')
            else:
                CLI.msg('\nPlease inform password to connect to database "%s@%s:%s"' % (config.get('database_user'), config.get('database_host'), config.get('database_name')))
                passwd = getpass()
            config.update('database_password', passwd)

        if options.get('info_database'):
            if options.get('info_database').lower() == 'last_label':
                CLI.info_and_exit(Main(config).last_label() or "NONE")
            elif options.get('info_database').lower() == 'labels':
                labels = Main(config).labels()
                CLI.info_and_exit(labels and "\n".join(labels) or "NONE")
            else:
                CLI.error_and_exit("The '%s' is a wrong parameter for info" % options.get('info_database').lower())

        # If CLI was correctly parsed, execute db-migrate.
        Main(config).execute()
    except KeyboardInterrupt:
        CLI.info_and_exit("\nExecution interrupted by user...")
    except Exception, e:
        CLI.error_and_exit(str(e))
Exemplo n.º 11
0
 def __init__(self):
     config = FileConfig()
     config.load_yaml()
     self.shodan_key_string = config.settings["SHODAN_API_KEY"]
     self.shodan_api = shodan.Shodan(self.shodan_key_string)
Exemplo n.º 12
0
def get_calculating():
    return list(map(int, files_list(join(basedir, 'btrun'))))


def touch(fname, times=None):
    fhandle = open(fname, 'a')
    try:
        utime(fname, times)
    finally:
        fhandle.close()


if __name__ == '__main__':
    calculating = get_calculating()
    max_running = FileConfig().get('APP.POOL_PROCESSES', 4, int)

    bt = None

    if len(calculating) < max_running:
        bt = Backtest.findOneToProcess(calculating)
    else:
        print('Server is busy now')
        exit(0)

    if bt is None:
        print('No backtest found')
        exit(0)

    fname = join(basedir, 'btrun', str(bt.id))