Exemplo n.º 1
0
	def __init__(self, job, eventdriver):
		# unique job name
		self.job = job

		# import data map config, such as MAP_ITORANGE
		self.config = Configuration()
		self.config.import_internal_config(job)
		self.config.print_config()

		# refresh config
		# config_listener = threading.Thread(target=self.config.update_config)
		# config_listener.setDaemon(True)
		# config_listener.start()

		self._lcurl = Lcurl()
		self._logger = Nlog()

		# event driver
		self._eventdriver = eventdriver
		self._eventdriver.add_event_listener(job, self.process)

		try:
			pull_strategy = self.config.CONFIG['GLOBAL']['JOB'][job]['PULL_STRATEGY']
			print('[PULL STRATEGY] %s' % pull_strategy)
			if pull_strategy is not None:
				pull_method = eval('self.pull_from_' + pull_strategy)
				setattr(self, 'pull', pull_method)
		except Exception as e:
			raise InternalError('[pusher constructor ERROR]', e)
def main():

    strategy = get_strategy()
    args_namespace = strategy.create_argument_parser(False).parse_args()

    events_log_file = '{}/events.log'.format(args_namespace.output_directory)

    strategy_params = strategy.get_strategy_params(args_namespace)
    strategy_params['send_notifications'] = True
    strategy_params['webhook'] = os.environ.get('WEBHOOK_PINBAR_NOTIFIER')

    configuration = Configuration(data_handler_name=OandaDataHandler,
                                  execution_handler_name=OandaExecutionHandler)
    configuration.set_option(
        Configuration.OPTION_NUMBER_OF_BARS_PRELOAD_FROM_HISTORY, '0')

    configuration.set_option(Configuration.OPTION_ACCOUNT_ID,
                             os.environ.get('OANDA_API_ACCOUNT_ID'))
    configuration.set_option(Configuration.OPTION_ACCESS_TOKEN,
                             os.environ.get('OANDA_API_ACCESS_TOKEN'))
    configuration.set_option(Configuration.OPTION_TIMEFRAME,
                             args_namespace.time_frame)

    trading = Trading(args_namespace.output_directory,
                      list(args_namespace.symbols), 0, configuration,
                      DataHandlerFactory(), ExecutionHandlerFactory(),
                      Portfolio, strategy, FixedPositionSize(0.01),
                      TextLogger(events_log_file), [Trading.LOG_TYPE_EVENTS],
                      strategy_params, 'equity.csv', 'trades.csv')

    trading.run()
    trading.print_performance()
Exemplo n.º 3
0
def main():
    strategy = get_strategy()
    args_namespace = strategy.create_argument_parser().parse_args()
    strategy_params_special = strategy.get_strategy_params(args_namespace)

    heartbeat = 0

    events_log_file = '{}/events.log'.format(args_namespace.output_directory)

    strategy_params = dict(stop_loss_pips=args_namespace.stop_loss,
                           take_profit_pips=args_namespace.take_profit)
    strategy_params.update(strategy_params_special)

    configuration = Configuration(data_handler_name=OandaDataHandler,
                                  execution_handler_name=OandaExecutionHandler)

    configuration.set_option(Configuration.OPTION_ACCOUNT_ID,
                             os.environ.get('OANDA_API_ACCOUNT_ID'))
    configuration.set_option(Configuration.OPTION_ACCESS_TOKEN,
                             os.environ.get('OANDA_API_ACCESS_TOKEN'))
    configuration.set_option(Configuration.OPTION_TIMEFRAME,
                             TimeFrame.TIME_FRAME_S5)

    trading = Trading(args_namespace.output_directory, args_namespace.symbols,
                      heartbeat, configuration, DataHandlerFactory(),
                      ExecutionHandlerFactory(), Portfolio, get_strategy(),
                      FixedPositionSize(0.01), TextLogger(events_log_file),
                      [Trading.LOG_TYPE_EVENTS], strategy_params, 'equity.csv',
                      'trades.csv')

    trading.run()
    trading.print_performance()
Exemplo n.º 4
0
def run_backtest_instance(args_namespace, events_log_file, heartbeat, sl, tp,
                          short_window, long_window, equity_filename,
                          trained_model_file):

    trades_filename = 'trades.csv'

    strategy_params = dict(stop_loss_pips=sl,
                           take_profit_pips=tp,
                           trained_model_file=trained_model_file,
                           sma_short_period=short_window,
                           sma_long_period=long_window)

    configuration = Configuration(
        data_handler_name=HistoricCSVDataHandler,
        execution_handler_name=SimulatedExecutionHandler)
    configuration.set_option(Configuration.OPTION_CSV_DIR,
                             args_namespace.data_directory)

    backtest = Backtest(args_namespace.output_directory,
                        args_namespace.symbols,
                        args_namespace.initial_capital_usd, heartbeat,
                        args_namespace.start_date, configuration,
                        DataHandlerFactory(), ExecutionHandlerFactory(),
                        Portfolio, EurUsdDailyForecastStrategy,
                        FixedPositionSize(0.5), TextLogger(events_log_file),
                        [Backtest.LOG_TYPE_EVENTS], strategy_params,
                        equity_filename, trades_filename)
    backtest.run()

    return backtest.stats
def main():

    strategy = get_strategy()
    args_namespace = strategy.create_argument_parser(False).parse_args()
    strategy_params_special = strategy.get_strategy_params(args_namespace)

    events_log_file = '{}/events.log'.format(args_namespace.output_directory)

    strategy_params = dict(stop_loss_pips=args_namespace.stop_loss,
                           take_profit_pips=args_namespace.take_profit)
    strategy_params.update(strategy_params_special)

    configuration = Configuration(data_handler_name=OandaDataHandler,
                                  execution_handler_name=OandaExecutionHandler)
    configuration.set_option(Configuration.OPTION_ACCOUNT_ID,
                             os.environ.get('OANDA_API_ACCOUNT_ID'))
    configuration.set_option(Configuration.OPTION_ACCESS_TOKEN,
                             os.environ.get('OANDA_API_ACCESS_TOKEN'))
    configuration.set_option(Configuration.OPTION_TIMEFRAME,
                             args_namespace.time_frame)
    configuration.set_option(
        Configuration.OPTION_NUMBER_OF_BARS_PRELOAD_FROM_HISTORY,
        max(strategy_params['sma_short_period'],
            strategy_params['sma_long_period']))

    trading = Trading(args_namespace.output_directory,
                      list(args_namespace.symbols), 0, configuration,
                      DataHandlerFactory(), ExecutionHandlerFactory(),
                      Portfolio, strategy, FixedPositionSize(0.01),
                      TextLogger(events_log_file), [Trading.LOG_TYPE_EVENTS],
                      strategy_params, 'equity.csv', 'trades.csv')

    trading.run()
    trading.print_performance()
Exemplo n.º 6
0
def main():

    # Load, prepare and validate configuration
    config = Configuration(args)

    # Initiate OpenStreetMap helper containing data
    data = OsmConnector(config)

    # Refresh argument option calls
    if args.refresh_routes:
        data.get_routes(refresh=True)
    elif args.refresh_stops:
        data.get_stops(refresh=True)
    elif args.refresh_osm:
        data.get_routes(refresh=True)
        data.get_stops(refresh=True)
    elif args.refresh_schedule_source:
        config.get_schedule_source(refresh=True)
    elif args.refresh_all:
        data.get_routes(refresh=True)
        data.get_stops(refresh=True)
        config.get_schedule_source(refresh=True)

    # Define (transitfeed) object for GTFS creation
    feed = transitfeed.Schedule()

    # Initiate creators for GTFS components through an object factory
    factory = CreatorFactory(config)
    agency_creator = factory.get_agency_creator()
    feed_info_creator = factory.get_feed_info_creator()
    routes_creator = factory.get_routes_creator()
    stops_creator = factory.get_stops_creator()
    schedule_creator = factory.get_schedule_creator()
    trips_creator = factory.get_trips_creator()

    # Add data to feed
    agency_creator.add_agency_to_feed(feed)
    feed_info_creator.add_feed_info_to_feed(feed)
    stops_creator.add_stops_to_feed(feed, data)
    routes_creator.add_routes_to_feed(feed, data)
    schedule_creator.add_schedule_to_data(data)
    trips_creator.add_trips_to_feed(feed, data)

    # Remove unused data from feed
    stops_creator.remove_unused_stops_from_feed(feed)
    routes_creator.remove_unused_routes_from_feed(feed)

    # Validate GTFS
    feed.Validate(transitfeed.ProblemReporter())

    # Write GTFS
    feed.WriteGoogleTransitFeed(config.output)

    sys.exit()
Exemplo n.º 7
0
Arquivo: pusher.py Projeto: Dkner/mr2p
    def __init__(self, job):
        # unique job name
        self.job = job

        # import data map config, such as MAP_ITORANGE
        global_config = Configuration()
        self.config = copy.deepcopy(global_config)
        self.config.import_internal_config(job)
        self.config.print_config()

        self._lcurl = Lcurl()
        self._loop = None
Exemplo n.º 8
0
def run():
    log.info("=== Singularity ===")
    args = init_args_parser()
    log.info(f'Current environment: {args.env}')
    config = Configuration(args.env)
    log.info("=== Spark project is running... ===")
    log.info("== Configurations ==")

    log.info(f'app_name: {config.app_name}')
    log.info(f'input_mongodb_uri: {config.input_mongodb_uri}')
    log.info(f'output_mongodb_uri: {config.output_mongodb_uri}')
    log.info(f'jars_dir: {config.jars_dir}')
Exemplo n.º 9
0
	def __init__(self, name, job_list):
		self.config = Configuration()
		# refresh config
		config_listener = threading.Thread(target=self.config.update_config)
		config_listener.setDaemon(True)
		config_listener.start()

		# job_name => job(subclass of pusher), flag(start or pause), process
		self._register = {}
		for job in job_list:
			self._register[job.job] = {
				'class': job,
				'process': None
			}
Exemplo n.º 10
0
def main():

    # Load, prepare and validate configuration
    config = Configuration(args)

    # Initiate OpenStreetMap helper containing data
    data = OsmConnector(config.config)

    # Refresh argument option calls
    if args.refresh_routes:
        data.get_routes(refresh=True)
        sys.exit(0)
    elif args.refresh_stops:
        data.get_stops(refresh=True)
        sys.exit(0)
    elif args.refresh_all:
        data.get_routes(refresh=True)
        data.get_stops(refresh=True)
        sys.exit(0)

    # Define (transitfeed) schedule object for GTFS creation
    schedule = transitfeed.Schedule()

    # Initiate creators for GTFS components through an object factory
    factory = CreatorFactory(config.config)
    agency_creator = factory.get_agency_creator()
    feed_info_creator = factory.get_feed_info_creator()
    routes_creator = factory.get_routes_creator()
    stops_creator = factory.get_stops_creator()
    trips_creator = factory.get_trips_creator()

    # Add data to schedule object
    agency_creator.add_agency_to_schedule(schedule)
    feed_info_creator.add_feed_info_to_schedule(schedule)
    routes_creator.add_routes_to_schedule(schedule, data)
    stops_creator.add_stops_to_schedule(schedule, data)
    trips_creator.add_trips_to_schedule(schedule, data)

    # Validate GTFS
    schedule.Validate(transitfeed.ProblemReporter())

    # Write GTFS
    schedule.WriteGoogleTransitFeed(config.output)

    # Add feed_info.txt to GTFS
    add_feed_info(schedule, config.output)

    sys.exit()
Exemplo n.º 11
0
def main() -> None:
    # create the argument parser
    ap = argparse.ArgumentParser(prog="CryptoHFT.py")
    ap.add_argument("-w", "--warranty",
                    help="shows the details about the warranty.",
                    action="store_true")
    ap.add_argument("-c", "--conditions",
                    help="shows the details about the redistribution.",
                    action="store_true")
    ap.add_argument("-i", "--init",
                    help="create a new configuration.",
                    action="store_true")

    # retrieve the arguments
    args = ap.parse_args()

    # check if the -w flag or the -c flag has been written
    shownWarrantyOrConditions = False
    if args.conditions:
        printConditions()
        shownWarrantyOrConditions = True

    if args.warranty:
        printWarranty()
        shownWarrantyOrConditions = True

    if shownWarrantyOrConditions:
        sys.exit(0)

    # shows the license
    printLicense()

    # check if it's necessary to create a new configuration file
    if args.init:
        Configuration.createConfiguration(CONFIG_FILE_PATH)

    # load the configuration
    userConfig = Configuration(CONFIG_FILE_PATH)

    # create the bot object
    bot = Bot(userConfig)

    # setup the bot
    bot.setup()

    # enter the trade loop
    bot.tradeLoop()
Exemplo n.º 12
0
def main(env):
    # event driver loop
    eventdriver = EventDriver(maxtask=20)
    eventdriver.start(True)

    # import global config
    config = Configuration()
    config.import_global_config(env)

    task_config = config.CONFIG['GLOBAL']['JOB']
    for i in task_config:
        # add task when key 'DO_MR2P' equals 1
        if 0 == int(task_config[i].get(
                "DO_MR2P", 0)) or not "MR2P_PROCESSOR" in task_config[i]:
            continue
        new_task = eval(task_config[i]['MR2P_PROCESSOR'] + "(i, eventdriver)")
        new_task.run()
Exemplo n.º 13
0
def init():
    init_dependencies()
    log.info("=== Singularity ===")
    args = init_args_parser()
    log.info(f'Current environment: {args.env}')
    config = Configuration(args.env)
    log.info("=== Spark project is running... ===")
    log.info("== Configurations ==")

    log.info(f'app_name: {config.app_name}')
    log.info(f'input_mongodb_uri: {config.input_mongodb_uri}')
    log.info(f'output_mongodb_uri: {config.output_mongodb_uri}')
    log.info(f'jars_dir: {config.jars_dir}')
    log.info(f'master: {config.master}')

    sp = SparkManager(config)
    sp.run()
Exemplo n.º 14
0
    def __init__(self, labels, input_folder, mode):
        super().__init__()

        # init UI state
        self.title = 'PyQt5 - Annotation tool for assigning image classes'
        self.left = 200
        self.top = 100
        self.width = 1100
        self.height = 770
        # img panal size should be square-like to prevent some problems with different aspect ratios
        self.img_panel_width = 650
        self.img_panel_height = 650

        # state variables
        self.configuration = Configuration(
            input_folder,
            labels,
            mode,
        )

        self.counter = 0
        self.assigned_labels = {}

        # initialize list to save all label buttons
        self.label_buttons = []

        # Initialize Labels
        self.image_box = QLabel(self)
        self.img_name_label = QLabel(self)
        self.progress_bar = QLabel(self)
        self.curr_image_headline = QLabel('Current image', self)
        self.csv_note = QLabel(
            '(csv will be also generated automatically after closing the app)',
            self)
        self.csv_generated_message = QLabel(self)
        self.show_next_checkbox = QCheckBox(
            "Automatically show next image when labeled", self)
        self.generate_xlsx_checkbox = QCheckBox("Also generate .xlsx file",
                                                self)

        # create label folders
        if mode == 'copy' or mode == 'move':
            self.create_label_folders(labels, self.configuration.input_folder)

        # init UI
        self.init_ui()
Exemplo n.º 15
0
def run(p_port=None, verbose=False, config_path=None):
    global config
    config = Configuration(config_path=config_path)
    path = config.get_log_file_path()
    # choose the log file path
    if path:
        log.add_handler(path)
    config.set_verbose(verbose)
    # recheck if its locked because the last check is maybe a false lock
    pid = os.getpid()
    file_lock_path = "/tmp/SeaGoat.lock"
    if is_lock(file_lock_path):
        sys.exit(-1)

    file_lock = open(file_lock_path, "w")
    file_lock.write("%s" % pid)
    file_lock.close()

    if not p_port:
        port = config.get_tcp_output_config()
    else:
        port = p_port

    # Create and register the service
    server = jsonrpc_server.JsonrpcServer(port)
    try:
        server.register()
    except BaseException as e:
        log.printerror_stacktrace(logger, e)
        server.close()
        sys.exit(1)

    # Start the server
    logger.info('Serving on port %s - pid %s', port, pid)
    logger.info('Waiting command')
    try:
        server.run()
    except (KeyboardInterrupt, SystemExit):
        logger.info("Close SeaGoat. See you later!")
    except BaseException:
        raise
    finally:
        server.close()
        # force closing the file
        os.remove(file_lock_path)
Exemplo n.º 16
0
def main(env):
    # import global config
    config = Configuration()
    config.import_global_config(env)

    task_config = config.CONFIG['GLOBAL']['JOB']
    task_list = []
    for job_name in task_config:
        # add task when key 'DO_MR2P' equals 1
        if 0 == int(task_config[job_name].get(
                "DO_MR2P",
                0)) or not "MR2P_PROCESSOR" in task_config[job_name]:
            continue
        new_task = eval(task_config[job_name]['MR2P_PROCESSOR'] + "(job_name)")
        task_list.append(new_task)

    o = scheduler("mr2p", task_list)
    o.run()
Exemplo n.º 17
0
def main():

    # Load, prepare and validate configuration
    config = Configuration()

    # Initiate gateways for communication through an object factory
    factory = GatewayFactory(config)
    sms_gateway = factory.get_sms_gateway()
    you_gateway = factory.get_you_gateway()

    # Check if the flag to only run one direction is set.
    # If nothing is set, both will run (default behaviour).
    if args.you2sms:
        _you2sms(sms_gateway, you_gateway)
    elif args.sms2you:
        _sms2you(sms_gateway, you_gateway)
    else:
        _sms2you(sms_gateway, you_gateway)
        _you2sms(sms_gateway, you_gateway)

    sys.exit()
Exemplo n.º 18
0
def main():

    strategy = get_strategy()
    args_namespace = strategy.create_argument_parser(True).parse_args()
    strategy_params_special = strategy.get_strategy_params(args_namespace)

    events_log_file = '{}/events.log'.format(args_namespace.output_directory)

    strategy_params = dict(stop_loss_pips=args_namespace.stop_loss,
                           take_profit_pips=args_namespace.take_profit)
    strategy_params.update(strategy_params_special)

    configuration = Configuration(
        data_handler_name=HistoricCSVDataHandler,
        execution_handler_name=SimulatedExecutionHandler)
    configuration.set_option(Configuration.OPTION_CSV_DIR,
                             args_namespace.data_directory)

    backtest = Backtest(
        args_namespace.output_directory,
        args_namespace.symbols,
        args_namespace.initial_capital_usd,
        0,
        args_namespace.start_date,
        configuration,
        DataHandlerFactory(),
        ExecutionHandlerFactory(),
        Portfolio,
        strategy,
        FixedPositionSize(0.5),
        TextLogger(events_log_file),
        [Backtest.LOG_TYPE_EVENTS],
        strategy_params,
        'equity.csv',
        'trades.csv',
    )

    backtest.run()
    backtest.print_performance()
Exemplo n.º 19
0
def main(env):
    config = Configuration()
    config.import_global_config(env)
    task_config = config.CONFIG['GLOBAL']['JOB']
    task_list = []
    if not isinstance(task_config, dict):
        return
    else:
        for i in task_config:
            # add task when key 'DO_MR2P' equals 1
            if not "DO_MR2P" in task_config or not "MR2P_PROCESSOR" in task_config[
                    i]:
                continue
            elif '0' == task_config[i]['DO_MR2P']:
                continue
            new_task = eval(task_config[i]['MR2P_PROCESSOR'] + "(i)")
            processor_num = int(task_config[i].get('PROCESSOR_NUM', 1))
            for i in range(processor_num):
                task_list.append(new_task)

    o = scheduler("mr2p", task_list)
    o.run()
def main():

    strategy = get_strategy()
    args_namespace = strategy.create_argument_parser(True).parse_args()

    events_log_file = '{}/events.log'.format(args_namespace.output_directory)

    strategy_params = strategy.get_strategy_params(args_namespace)
    strategy_params['send_notifications'] = False
    strategy_params['webhook'] = ''

    configuration = Configuration(
        data_handler_name=HistoricCSVDataHandler,
        execution_handler_name=SimulatedExecutionHandler)

    configuration.set_option(Configuration.OPTION_CSV_DIR,
                             args_namespace.data_directory)

    simulation = Backtest(
        args_namespace.output_directory,
        args_namespace.symbols,
        args_namespace.initial_capital_usd,
        0,
        args_namespace.start_date,
        configuration,
        DataHandlerFactory(),
        ExecutionHandlerFactory(),
        Portfolio,
        strategy,
        FixedPositionSize(0.5),
        TextLogger(events_log_file),
        [Backtest.LOG_TYPE_EVENTS],
        strategy_params,
        'equity.csv',
        'trades.csv',
    )

    simulation.run()
    simulation.print_performance()
Exemplo n.º 21
0
Arquivo: nlog.py Projeto: Dkner/mr2p
	def __init__(self):
		config = Configuration().CONFIG['GLOBAL']
		self._ip = config['NLOG']['ip']
		self._port = int(config['NLOG']['port'])
Exemplo n.º 22
0
import sys
sys.path.append("..")
import getopt
from core.configuration import Configuration
from plugins.company2b import Company2b

if __name__ == '__main__':
    optlist, args = getopt.getopt(sys.argv[1:], 'e:', ['env='])
    env = ''
    for k, v in optlist:
        if k == '-e' or k == '--env':
            env = v
    if env != '':
        config = Configuration()
        config.import_global_config(env)
        script = Company2b('CNLINFO')
        script.run()
    else:
        print('[ERROR] lack env config')