def set_routes(self, routes: List[Any]) -> None: self._reset() self.routes = [] for r in routes: # validate strategy strategy_name = r[3] if jh.is_unit_testing(): exists = jh.file_exists( f"{sys.path[0]}/jesse/strategies/{strategy_name}/__init__.py" ) else: exists = jh.file_exists( f'strategies/{strategy_name}/__init__.py') if not exists: raise exceptions.InvalidRoutes( f'A strategy with the name of "{r[3]}" could not be found.' ) # validate timeframe route_timeframe = r[2] all_timeframes = [ timeframe for timeframe in jh.class_iter(timeframes) ] if route_timeframe not in all_timeframes: raise exceptions.InvalidRoutes( f'Timeframe "{route_timeframe}" is invalid. Supported timeframes are {", ".join(all_timeframes)}' ) self.routes.append(Route(*r))
def set_routes(self, routes: List[Any]) -> None: self._reset() self.routes = [] for r in routes: # validate strategy strategy_name = r[3] if jh.is_unit_testing(): exists = jh.file_exists(sys.path[0] + '/jesse/strategies/{}/__init__.py'.format(strategy_name)) else: exists = jh.file_exists('strategies/{}/__init__.py'.format(strategy_name)) if not exists: raise exceptions.InvalidRoutes( 'A strategy with the name of "{}" could not be found.'.format(r[3])) # validate timeframe timeframe = r[2] if timeframe not in ['1m', '3m', '5m', '15m', '30m', '45m', '1h', '2h', '3h', '4h', '6h', '8h', '12h', '1D', '3D', '1W'']: raise exceptions.InvalidRoutes( 'Timeframe "{}" is invalid. Supported timeframes are 1m, 3m, 5m, 15m, 30m, 45m, 1h, 2h, 3h, 4h, 6h, 8h, 12h, 1D, 3D, 1W'.format( timeframe) ) self.routes.append(Route(*r))
def set_routes(self, routes): self.routes = [] for r in routes: # validate strategy import jesse.helpers as jh from jesse import exceptions strategy_name = r[3] if jh.is_unit_testing(): exists = jh.file_exists( 'jesse/strategies/{}/__init__.py'.format(strategy_name)) else: exists = jh.file_exists( 'strategies/{}/__init__.py'.format(strategy_name)) if not exists: raise exceptions.InvalidRoutes( 'A strategy with the name of "{}" could not be found.'. format(r[3])) # validate timeframe timeframe = r[2] if timeframe not in [ '1m', '3m', '5m', '15m', '30m', '1h', '2h', '3h', '4h', '6h', '8h', '1D' ]: raise exceptions.InvalidRoutes( 'Timeframe "{}" is invalid. Supported timeframes are 1m, 3m, 5m, 15m, 30m, 1h, 2h, 3h, 4h, 6h, 8h, 1D' .format(timeframe)) self.routes.append(Route(*r))
def set_routes(self, routes: List[Any]) -> None: self._reset() self.routes = [] for r in routes: # validate strategy that the strategy file exists (if sent as a string) if isinstance(r["strategy"], str): strategy_name = r["strategy"] if jh.is_unit_testing(): path = sys.path[0] # live plugin if path.endswith('jesse-live'): strategies_dir = f'{sys.path[0]}/tests/strategies' # main framework else: strategies_dir = f'{sys.path[0]}/jesse/strategies' exists = jh.file_exists( f"{strategies_dir}/{strategy_name}/__init__.py") else: exists = jh.file_exists( f'strategies/{strategy_name}/__init__.py') else: exists = True if not exists and isinstance(r["strategy"], str): raise exceptions.InvalidRoutes( f'A strategy with the name of "{r["strategy"]}" could not be found.' ) self.routes.append( Route(r["exchange"], r["symbol"], r["timeframe"], r["strategy"], None))
def set_routes(self, routes: List[Any]) -> None: self._reset() self.routes = [] for r in routes: # validate strategy strategy_name = r[3] if jh.is_unit_testing(): exists = jh.file_exists(sys.path[0] + '/jesse/strategies/{}/__init__.py'.format(strategy_name)) else: exists = jh.file_exists('strategies/{}/__init__.py'.format(strategy_name)) if not exists: raise exceptions.InvalidRoutes( 'A strategy with the name of "{}" could not be found.'.format(r[3])) # validate timeframe route_timeframe = r[2] all_timeframes = [timeframe for timeframe in jh.class_iter(timeframes)] if route_timeframe not in all_timeframes: raise exceptions.InvalidRoutes( 'Timeframe "{}" is invalid. Supported timeframes are {}'.format( route_timeframe, ', '.join(all_timeframes)) ) self.routes.append(Route(*r))
def __init__(self, iterations: int, population_size: int, solution_len: int, charset: str = '()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvw', fitness_goal: float = 1, options: Dict[str, Union[bool, Any]] = None) -> None: self.started_index = 0 self.start_time = jh.now_to_timestamp() self.population = [] self.iterations = iterations self.population_size = population_size self.solution_len = solution_len self.charset = charset self.fitness_goal = fitness_goal self.cpu_cores = 0 if options is None: self.options = {} else: self.options = options os.makedirs('./storage/temp/optimize', exist_ok=True) self.temp_path = f"./storage/temp/optimize/{self.options['strategy_name']}-{self.options['exchange']}-{self.options['symbol']}-{self.options['timeframe']}-{self.options['start_date']}-{self.options['finish_date']}.pickle" if fitness_goal > 1 or fitness_goal < 0: raise ValueError('fitness scores must be between 0 and 1') # if temp file exists, load data to resume previous session if jh.file_exists(self.temp_path): if click.confirm('Previous session detected. Do you want to resume?', default=True): self.load_progress()
def report_exception( description: str, traceback: str, mode: str, attach_logs: bool, session_id: str, email: str = None, has_live: bool = False ) -> JSONResponse: access_token = get_access_token() if attach_logs and session_id: path_exchange_log = None if mode == 'backtest': path_log = f'storage/logs/backtest-mode/{session_id}.txt' elif mode == 'live': path_log = f'storage/logs/live-mode/{session_id}.txt' path_exchange_log = 'storage/logs/exchange-streams.txt' else: raise ValueError('Invalid mode') # attach exchange_log if there's any files = {'log_file': open(path_log, 'rb')} if path_exchange_log and jh.file_exists(path_exchange_log): files['exchange_log'] = open(path_exchange_log, 'rb') else: files = None from jesse.version import __version__ as jesse_version info = { 'os': jh.get_os(), 'python_version': '{}.{}'.format(*jh.python_version()), 'is_docker': jh.is_docker(), 'jesse_version': jesse_version } if has_live: from jesse_live.version import __version__ as live_plugin_version info['live_plugin_version'] = live_plugin_version params = { 'description': description, 'traceback': traceback, 'email': email, 'info': json.dumps(info) } res = requests.post( 'https://jesse.trade/api/exception', data=params, files=files, headers={'Authorization': f'Bearer {access_token}'} ) success_message = 'Exception report submitted successfully' error_message = f"{res.status_code} error: {res.json()['message']}" return JSONResponse({ 'status': 'success' if res.status_code == 200 else 'error', 'message': success_message if res.status_code == 200 else error_message }, status_code=200)
def __init__( self, iterations, population_size, solution_len, charset='()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvw', fitness_goal=1, options=None): """ :param iterations: int :param population_size: int :param solution_len: int :param charset: str default= '()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvw' which is 40-119 (len=80) :param fitness_goal: """ # used for naming the files related to this session self.session_id = str(jh.now()) self.started_index = 0 self.start_time = jh.now() self.population = [] self.iterations = iterations self.population_size = population_size self.solution_len = solution_len self.charset = charset self.fitness_goal = fitness_goal if options is None: self.options = {} else: self.options = options os.makedirs('./storage/temp/optimize', exist_ok=True) self.temp_path = './storage/temp/optimize/{}-{}-{}-{}.pickle'.format( self.options['strategy_name'], self.options['exchange'], self.options['symbol'], self.options['timeframe']) if fitness_goal > 1 or fitness_goal < 0: raise ValueError('fitness scores must be between 0 and 1') # if temp file exists, load data to resume previous session if jh.file_exists(self.temp_path): if click.confirm( 'Previous session detected. Do you want to resume?', default=True): self.load_progress()
def test_file_exists(): assert jh.file_exists('tests/test_helpers.py') is True