示例#1
0
    def __init__(self):
        Tool.__init__(self)
        self.menu = ['Te&st', '&Roof']
        self.steps = 1
        self.input_types = ['object']
        self.help = ['Select a polygon to build a roof over it']
        self.icon = 'cad-roof'

        self.reset()
示例#2
0
    def __init__(self):
        Tool.__init__(self)
        self.menu = ['&Boolean', '&Union']
        self.icon = 'boolean-union'
        self.shortcut = 'Ctrl+U'
        self.steps = 2
        self.input_types = ['object', 'object']
        self.help = ['Pick the first object', 'Pick the second object']

        self.reset()
示例#3
0
    def __init__(self):
        Tool.__init__(self)
        self.menu = 'Te&sts', '&TestTool1'
        self.steps = 1
        self.input_types = ['point']
        self.icon = ''
        self.shortcut = ''
        self.help = ''

        self.reset()
示例#4
0
    def __init__(self):
        Tool.__init__(self)
        self.menu = ['E&xpand', '&Fill']
        self.steps = 1
        self.input_types = ['object']
        self.icon = 'edit-fill'
        self.shortcut = ''
        self.help = ['Pick a planar curve to fill it']

        self.reset()
示例#5
0
    def __init__(self):
        Tool.__init__(self)
        self.menu = ['&Boolean', 'Dif&ference']
        self.icon = 'boolean-difference'
        self.shortcut = 'Ctrl+F'
        self.steps = 2
        self.input_types = ['object', 'object']
        self.help = ['Pick the first object', 'Pick the second object']

        self.reset()
示例#6
0
 def _compute_node(self, key, node: Tool):
     for name in node.inputs:
         key = node.inputs[name].connected_node.key
         port = node.inputs[name].connected_port
         if (key is None) or (port is None):
             raise RuntimeError(
                 f"Incomplete input data for node with key {key}")
         self._compute_node(key, self.nodes[key])
         node.inputs[name].update_value(self.nodes[key].outputs[port].value)
     node.compute()
示例#7
0
    def __init__(self):
        Tool.__init__(self)
        self.menu = ['&Edit', '&Delete']
        self.icon = 'edit-delete'
        self.shortcut = 'Ctrl+D'
        self.steps = 1
        self.input_types = ['object']
        self.help = ['Click on an object to delete it']

        self.reset()
示例#8
0
    def __init__(self):
        Tool.__init__(self)
        self.menu = ['E&xpand', '&Rotate']
        self.steps = 2
        self.input_types = ['object', 'point']
        self.icon = 'cad-revolve'
        self.shortcut = ''
        self.help = ['Pick a curve or a surface',
                     'Select the axis to rotate about']

        self.reset()
示例#9
0
    def __init__(self):
        Tool.__init__(self)
        self.menu = ['E&xpand', 'E&xtrude']
        self.steps = 2
        self.input_types = ['object', 'point']
        self.icon = 'cad-extrude'
        self.shortcut = 'Ctrl+E'
        self.help = ['Pick an object to extrude. It will be extruded '
                     'othogonally to the active plane',
                     'Determine the height of extrusion']

        self.reset()
示例#10
0
    def __init__(self):
        Tool.__init__(self)
        self.menu = ['&Transform', '&Tanslate']
        self.steps = 3
        self.input_types = ['object', 'point', 'point']
        self.icon = 'transform-move'
        self.shortcut = 'Ctrl+T'
        self.help = [
            'Pick the object to Translate', 'Enter the start point',
            'Enter the target point'
        ]

        self.reset()
示例#11
0
    def __init__(self):
        Tool.__init__(self)
        self.menu = ['&Transform', '&Mirror']
        self.steps = 1
        self.input_types = ['object']
        self.icon = 'transform-mirror'
        self.shortcut = 'Ctrl+M'
        self.help = [
            'Pick the object to mirror. It will be mirrored about'
            ' the active plane.'
        ]

        self.reset()
示例#12
0
    def __init__(self):
        Tool.__init__(self)
        self.menu = ['&Transform', '&Rotate']
        self.steps = 4
        self.input_types = ['object', 'point', 'point', 'point']
        self.icon = 'transform-rotate'
        self.shortcut = 'Ctrl+R'
        self.help = [
            'Pick the object to rotate', 'Enter the axis of rotation',
            'Enter a point to determine the start of the rotation',
            'Enter a point to determine the target of the rotation'
        ]

        self.prev_dat = {}

        self.reset()
示例#13
0
def display_help_tools():
    tools = Tool.find_tools()

    for tool in tools:
        try:
            alias, msgs = Tool.tool_help(tool)

            if alias:
                Terminal.inst().message(
                    "  --tool=%s, --%s %s" %
                    (tool, alias, msgs[0] if len(msgs) > 0 else ""))
            else:
                Terminal.inst().message(
                    "  --tool=%s %s" %
                    (tool, msgs[0] if len(msgs) > 0 else ""))

            for msg in msgs[1:]:
                Terminal.inst().message("    " + msg)
        except:
            pass
示例#14
0
文件: fund.py 项目: hzy0110/PythonAI
 def cal_fund_parameter_2_max_trade(self):
     fund_code = 400001
     max_trade_timestamp = int(Dao().get_fund_history_max_trade_timestamp_by_fund_code(fund_code)['max_trade_timestamp'][0])
     fund_create_timestamp = int(Dao().fund_info(fund_code)['fund_create_timestamp'][0])
     date_list = ['30d', '90d', '180d', '1y', '2y', '3y', '4y', '5y']
     print('max_trade_timestamp', max_trade_timestamp)
     trade_day_timestamp_list = Tool().get_trade_day_list(max_trade_timestamp)
     print(trade_day_timestamp_list)
     max_trade_timestamp_fund_history_pd = Dao().get_fund_history_by_fund_code_trade_timestamp(
         fund_code, max_trade_timestamp)
     max_trade_timestamp_fund_history_pd.drop('created_time', inplace=True, axis=1)
     for timestamp, date in zip(trade_day_timestamp_list, date_list):
         print('timestamp', timestamp)
         if timestamp < fund_create_timestamp:
             timestamp = fund_create_timestamp
         self.save_fund_mean(max_trade_timestamp_fund_history_pd, fund_code, date, timestamp, max_trade_timestamp)
         self.save_fund_dividend(max_trade_timestamp_fund_history_pd, fund_code, date, timestamp, max_trade_timestamp)
         self.save_fund_report(max_trade_timestamp_fund_history_pd, fund_code, date, timestamp, max_trade_timestamp)
         self.save_fund_subtraction(max_trade_timestamp_fund_history_pd, fund_code, date, timestamp, max_trade_timestamp)
示例#15
0
def application(argv):
    fix_thread_set_name()

    # init terminal displayer
    Terminal()

    options = {
        'working-path': os.getcwd(),
        'identity': 'real',
        'config-path': './user/config',
        'log-path': './user/log',
        'reports-path': './user/reports',
        'markets-path': './user/markets',
        'log-name': 'siis.log',
    }

    # create initial siis data structure if necessary
    install(options)

    siis_log = SiisLog(options, Terminal().inst().style())
    siis_logger = logging.getLogger('siis')
    traceback_logger = logging.getLogger('siis.traceback')

    # parse process command line
    if len(argv) > 1:
        options['livemode'] = True

        # utc or local datetime ?
        for arg in argv:
            if arg.startswith('--'):
                if arg == '--paper-mode':
                    # livemode but in paper-mode
                    options['paper-mode'] = True

                elif arg == '--fetch':
                    # use the fetcher
                    options['tool'] = "fetcher"
                elif arg == '--binarize':
                    # use the binarizer
                    options['tool'] = "binarize"
                elif arg == '--optimizer':
                    # use the optimizer
                    options['tool'] = "optimizer"
                elif arg == '--sync':
                    # use the syncer
                    options['tool'] = "syncer"
                elif arg == '--rebuild':
                    # use the rebuilder
                    options['tool'] = "rebuilder"
                elif arg == '--export':
                    # use the exporter
                    options['tool'] = "exporter"
                elif arg == '--import':
                    # use the importer
                    options['tool'] = "importer"
                elif arg == '--clean':
                    # use the cleaner
                    options['tool'] = "cleaner"
                elif arg.startswith("--tool="):
                    # use a named tool
                    options['tool'] = arg.split('=')[1]

                elif arg == '--no-conf':
                    options['no-conf'] = True
                elif arg == '--zip':
                    options['zip'] = True

                elif arg == '--install-market':
                    options['install-market'] = True
                elif arg == '--initial-fetch':
                    # do the initial OHLC fetch for watchers
                    options['initial-fetch'] = True

                elif arg == '--backtest':
                    # backtest mean always paper-mode
                    options['paper-mode'] = True
                    options['backtesting'] = True
                elif arg.startswith('--timestep='):
                    # backesting timestep, default is 60 second
                    options['timestep'] = float(arg.split('=')[1])
                elif arg.startswith('--time-factor='):
                    # backtesting time-factor
                    options['time-factor'] = float(arg.split('=')[1])

                elif arg.startswith('--filename='):
                    # used with import or export
                    options['filename'] = arg.split('=')[1]

                elif arg.startswith('--from='):
                    # if backtest from date and tools
                    options['from'] = parse_datetime(arg.split('=')[1])
                    if not options['from']:
                        Terminal.inst().error("Invalid 'from' datetime format")
                        sys.exit(-1)
                elif arg.startswith('--to='):
                    # if backtest to date and tools
                    options['to'] = parse_datetime(arg.split('=')[1])
                    if not options['to']:
                        Terminal.inst().error("Invalid 'to' datetime format")
                        sys.exit(-1)
                elif arg.startswith('--last='):
                    # fetch the last n data history
                    options['last'] = int(arg.split('=')[1])
                    if options['last'] <= 0:
                        Terminal.inst().error(
                            "Invalid 'last' value. Must be at least 1")
                        sys.exit(-1)

                elif arg.startswith('--market='):
                    # fetch, binarize, optimize the data history for this market
                    options['market'] = arg.split('=')[1]
                elif arg.startswith('--spec='):
                    # fetcher data history option
                    options['option'] = arg.split('=')[1]
                elif arg.startswith('--broker='):
                    # broker name for fetcher, watcher, optimize, binarize
                    options['broker'] = arg.split('=')[1]
                elif arg.startswith('--timeframe='):
                    # fetch, binarize, optimize base timeframe
                    options['timeframe'] = arg.split('=')[1]
                elif arg.startswith('--cascaded='):
                    # fetch cascaded ohlc generation
                    options['cascaded'] = arg.split('=')[1]
                elif arg.startswith('--target='):
                    # target ohlc generation
                    options['target'] = arg.split('=')[1]

                elif arg == '--watcher-only':
                    # feed only with live data (not compatible with --read-only)
                    options['watcher-only'] = True
                elif arg == '--read-only':
                    # does not write to the database (not compatible with --watcher-only)
                    options['read-only'] = True

                elif arg.startswith('--profile='):
                    # appliances profile name
                    options['profile'] = arg.split('=')[1]

                elif arg == '--version':
                    Terminal.inst().info('%s %s' % (APP_SHORT_NAME, '.'.join(
                        [str(x) for x in APP_VERSION])))
                    sys.exit(0)

                elif arg == '--help' or '-h':
                    display_cli_help()
                    sys.exit(0)
            else:
                options['identity'] = argv[1]

        # watcher-only read-only mutual exclusion
        if options.get('watcher-only') and options.get('read-only'):
            Terminal.inst().error(
                "Options --watcher-only and --read-only are mutually exclusive !"
            )
            sys.exit(-1)

        # backtesting
        if options.get('backtesting', False):
            if options.get('from') is None or options.get('to') is None:
                del options['backtesting']
                Terminal.inst().error(
                    "Backtesting need from= and to= date time")
                sys.exit(-1)

    #
    # binarizer mode
    #

    if options.get('tool') == "binarizer":
        if options.get('market') and options.get('from') and options.get(
                'to') and options.get('broker'):
            from tools.binarizer import do_binarizer
            do_binarizer(options)
        else:
            display_cli_help()

        sys.exit(0)

    #
    # fetcher mode
    #

    if options.get('tool') == "fetcher":
        if options.get('market') and options.get('broker'):
            from tools.fetcher import do_fetcher
            do_fetcher(options)
        else:
            display_cli_help()

        sys.exit(0)

    #
    # optimizer mode
    #

    if options.get('tool') == "optimizer":
        if options.get('market') and options.get('from') and options.get(
                'broker'):
            from tools.optimizer import do_optimizer
            do_optimizer(options)
        else:
            display_cli_help()

        sys.exit(0)

    #
    # rebuilder mode
    #

    if options.get('tool') == "rebuilder":
        if options.get('market') and options.get('from') and options.get(
                'broker') and options.get('timeframe'):
            from tools.rebuilder import do_rebuilder
            do_rebuilder(options)
        else:
            display_cli_help()

        sys.exit(0)

    #
    # exporter mode
    #

    if options.get('tool') == "exporter":
        if options.get('market') and options.get('from') and options.get(
                'broker') and options.get('filename'):
            from tools.exporter import do_exporter
            do_exporter(options)
        else:
            display_cli_help()

        sys.exit(0)

    #
    # importer mode
    #

    if options.get('tool') == "importer":
        if options.get('filename'):
            from tools.importer import do_importer
            do_importer(options)
        else:
            display_cli_help()

        sys.exit(0)

    #
    # tool mode
    #

    if options.get('tool'):
        ToolClazz = Tool.load_tool(options.get('tool'))
        if ToolClazz:
            if ToolClazz.need_identity():
                if options['identity'].startswith('-'):
                    Terminal.inst().error(
                        "First option must be the identity name")
                    Terminal.inst().flush()

                    sys.exit(-1)

            tool = ToolClazz(options)

            if not tool.check_options(options):
                display_cli_help()
                sys.exit(-1)

            if ToolClazz.need_identity():
                Terminal.inst().info(
                    "Starting SIIS %s using %s identity..." %
                    (options.get('tool'), options['identity']))
            else:
                Terminal.inst().info("Starting SIIS %s..." %
                                     options.get('tool'))

            Terminal.inst().flush()

            tool.execute(options)

            Terminal.inst().info(
                "%s done!" %
                (ToolClazz.alias() or options.get('tool')).capitalize())
            Terminal.inst().flush()

            Terminal.terminate()

            sys.exit(0)
        else:
            sys.exit(-1)

    if options['identity'].startswith('-'):
        Terminal.inst().error("First option must be the identity name")

    #
    # normal mode
    #

    Terminal.inst().info("Starting SIIS using %s identity..." %
                         options['identity'])
    Terminal.inst().action("- type ':q<Enter> or :quit<Enter>' to terminate")
    Terminal.inst().action(
        "- type ':h<Enter> or :help<Enter>' to display help")
    Terminal.inst().flush()

    if options.get('backtesting'):
        Terminal.inst().notice("Process a backtesting.")

    if options.get('paper-mode'):
        Terminal.inst().notice("- Using paper-mode trader.")
    else:
        Terminal.inst().notice("- Using live-mode trader.")

    signal.signal(signal.SIGINT, signal_handler)

    #
    # application
    #

    watchdog_service = WatchdogService(options)
    watchdog_service.start(options)

    # application services
    view_service = None
    notifier_service = None
    watcher_service = None
    trader_service = None
    strategy_service = None

    # monitoring service
    Terminal.inst().info("Starting monitor service...")
    monitor_service = MonitorService(options)

    # notifier service
    try:
        notifier_service = NotifierService(options)
        notifier_service.start(options)
    except Exception as e:
        Terminal.inst().error(str(e))
        terminate(watchdog_service, watcher_service, trader_service,
                  strategy_service, monitor_service, view_service,
                  notifier_service)
        sys.exit(-1)

    # view service
    try:
        view_service = ViewService(options)
        watchdog_service.add_service(view_service)
    except Exception as e:
        Terminal.inst().error(str(e))
        terminate(watchdog_service, watcher_service, trader_service,
                  strategy_service, monitor_service, view_service,
                  notifier_service)
        sys.exit(-1)

    # database manager
    try:
        Database.create(options)
        Database.inst().setup(options)
    except Exception as e:
        Terminal.inst().error(str(e))
        terminate(watchdog_service, watcher_service, trader_service,
                  strategy_service, monitor_service, view_service,
                  notifier_service)
        sys.exit(-1)

    # watcher service
    Terminal.inst().info("Starting watcher's service...")
    try:
        watcher_service = WatcherService(options)
        watcher_service.start(options)
        watchdog_service.add_service(watcher_service)
    except Exception as e:
        Terminal.inst().error(str(e))
        terminate(watchdog_service, watcher_service, trader_service,
                  strategy_service, monitor_service, view_service,
                  notifier_service)
        sys.exit(-1)

    # trader service
    Terminal.inst().info("Starting trader's service...")
    try:
        trader_service = TraderService(watcher_service, monitor_service,
                                       options)
        trader_service.start(options)
        watchdog_service.add_service(trader_service)
    except Exception as e:
        Terminal.inst().error(str(e))
        terminate(watchdog_service, watcher_service, trader_service,
                  strategy_service, monitor_service, view_service,
                  notifier_service)
        sys.exit(-1)

    # want to display desktop notification and update views
    watcher_service.add_listener(view_service)

    # want to display desktop notification and update views
    trader_service.add_listener(view_service)

    # trader service listen to watcher service and update views
    watcher_service.add_listener(trader_service)

    # strategy service
    Terminal.inst().info("Starting strategy's service...")
    try:
        strategy_service = StrategyService(watcher_service, trader_service,
                                           monitor_service, options)
        strategy_service.start(options)
        watchdog_service.add_service(strategy_service)
    except Exception as e:
        Terminal.inst().error(str(e))
        terminate(watchdog_service, watcher_service, trader_service,
                  strategy_service, monitor_service, view_service,
                  notifier_service)
        sys.exit(-1)

    # wan't to be notifier of system errors
    watchdog_service.add_listener(notifier_service)

    # strategy service listen to watcher service
    watcher_service.add_listener(strategy_service)

    # strategy service listen to trader service
    trader_service.add_listener(strategy_service)

    # want to display desktop notification, update view and notify on discord
    strategy_service.add_listener(notifier_service)
    strategy_service.add_listener(view_service)

    # want signal and important notifications
    notifier_service.set_strategy_service(strategy_service)
    notifier_service.set_trader_service(trader_service)

    # register terminal commands
    commands_handler = CommandsHandler()
    commands_handler.init(options)

    # cli commands registration
    register_general_commands(commands_handler)
    register_trading_commands(commands_handler, trader_service,
                              strategy_service, monitor_service,
                              notifier_service)
    register_region_commands(commands_handler, strategy_service)

    # setup and start the monitor service
    monitor_service.setup(watcher_service, trader_service, strategy_service)
    try:
        monitor_service.start()
        watchdog_service.add_service(monitor_service)
    except Exception as e:
        Terminal.inst().error(str(e))
        terminate(watchdog_service, watcher_service, trader_service,
                  strategy_service, monitor_service, view_service,
                  notifier_service)
        sys.exit(-1)

    Terminal.inst().message("Running main loop...")

    Terminal.inst().upgrade()
    Terminal.inst().message("Steady...", view='notice')

    if view_service:
        # setup the default views
        try:
            setup_default_views(view_service, watcher_service, trader_service,
                                strategy_service)
        except Exception as e:
            Terminal.inst().error(str(e))
            terminate(watchdog_service, watcher_service, trader_service,
                      strategy_service, monitor_service, view_service,
                      notifier_service)
            sys.exit(-1)

    display_welcome()

    LOOP_SLEEP = 0.016  # in second
    MAX_CMD_ALIVE = 15  # in second

    running = True

    value = None
    value_changed = False
    command_timeout = 0
    prev_timestamp = 0

    try:
        while running:
            # keyboard input commands
            try:
                c = Terminal.inst().read()
                key = Terminal.inst().key()

                if c:
                    # split the commande line
                    args = [
                        arg
                        for arg in (value[1:].split(' ')
                                    if value and value.startswith(':') else [])
                        if arg
                    ]
                    if value and value[-1] == ' ':
                        args.append('')

                    # update the current type command
                    commands_handler.process_char(c, args)

                if key:
                    if key == 'KEY_ESCAPE':
                        # cancel command
                        value = None
                        value_changed = True
                        command_timeout = 0

                    # split the commande line
                    args = [
                        arg
                        for arg in (value[1:].split(' ')
                                    if value and value.startswith(':') else [])
                        if arg
                    ]
                    if value and value[-1] == ' ':
                        args.append('')

                    # process on the arguments
                    args = commands_handler.process_key(
                        key, args,
                        Terminal.inst().mode == Terminal.MODE_COMMAND)

                    if args:
                        # regen the updated commande ligne
                        value = ":" + ' '.join(args)
                        value_changed = True
                        command_timeout = 0

                    view_service.on_key_pressed(key)

                    if key == 'KEY_ESCAPE':
                        # was in command me, now in default mode
                        Terminal.inst().set_mode(Terminal.MODE_DEFAULT)

                # @todo move the rest to command_handler
                if c:
                    if value and value[0] == ':':
                        if c == '\b':
                            # backspace, erase last command char
                            value = value[:-1] if value else None
                            value_changed = True
                            command_timeout = time.time()

                        elif c != '\n':
                            # append to the advanced command value
                            value += c
                            value_changed = True
                            command_timeout = time.time()

                        elif c == '\n':
                            result = commands_handler.process_cli(value)
                            command_timeout = 0

                            if not result:
                                # maybe an application level command
                                if value == ':q' or value == ':quit':
                                    running = False

                                elif value.startswith(':x '):
                                    # manually exit position at market
                                    # @todo move as command
                                    target = value[3:]

                                    if target == "all" or target == "ALL":
                                        Terminal.inst().action(
                                            "Send close to market command for any positions",
                                            view='status')
                                        trader_service.command(
                                            Trader.COMMAND_CLOSE_ALL_MARKET,
                                            {})
                                    else:
                                        Terminal.inst().action(
                                            "Send close to market command for position %s"
                                            % (target, ),
                                            view='status')
                                        trader_service.command(
                                            Trader.COMMAND_CLOSE_MARKET,
                                            {'key': target})

                            # clear command value
                            value_changed = True
                            value = None

                            # use default mode
                            Terminal.inst().set_mode(Terminal.MODE_DEFAULT)

                    elif c != '\n':
                        # initial command value
                        value = "" + c
                        value_changed = True
                        command_timeout = time.time()

                        if value and value[0] == ':':
                            # use command mode
                            Terminal.inst().set_mode(Terminal.MODE_COMMAND)

                    if value and value[0] != ':':
                        # direct key

                        # use default mode
                        Terminal.inst().set_mode(Terminal.MODE_DEFAULT)

                        try:
                            result = commands_handler.process_accelerator(key)

                            # @todo convert to Command object accelerator
                            if not result:
                                result = True

                                # display views @todo must be managed by view_service
                                if value == 'C':
                                    Terminal.inst().clear_content()
                                elif value == 'D':
                                    Terminal.inst().switch_view('debug')
                                elif value == 'I':
                                    Terminal.inst().switch_view('content')
                                elif value == 'F':
                                    Terminal.inst().switch_view('strategy')
                                elif value == 'S':
                                    Terminal.inst().switch_view('stats')
                                elif value == 'P':
                                    Terminal.inst().switch_view('perf')
                                elif value == 'X':
                                    Terminal.inst().switch_view('position')
                                elif value == 'O':
                                    Terminal.inst().switch_view('order')
                                elif value == 'T':
                                    Terminal.inst().switch_view('ticker')
                                elif value == 'A':
                                    Terminal.inst().switch_view('account')
                                elif value == 'M':
                                    Terminal.inst().switch_view('market')
                                elif value == 'Q':
                                    Terminal.inst().switch_view('asset')
                                elif value == 'N':
                                    Terminal.inst().switch_view('signal')

                                elif value == '?':
                                    # ping services and workers
                                    watchdog_service.ping(1.0)

                                elif value == ' ':
                                    # a simple mark on the terminal
                                    Terminal.inst().notice(
                                        "Trading time %s" %
                                        (datetime.fromtimestamp(
                                            strategy_service.timestamp).
                                         strftime('%Y-%m-%d %H:%M:%S')),
                                        view='status')

                                elif value == 'a':
                                    if notifier_service:
                                        notifier_service.command(
                                            Notifier.COMMAND_TOGGLE, {
                                                'notifier': "desktop",
                                                'value': "audible"
                                            })
                                elif value == 'n':
                                    if notifier_service:
                                        notifier_service.command(
                                            Notifier.COMMAND_TOGGLE, {
                                                'notifier': "desktop",
                                                'value': "popup"
                                            })
                                elif value == '%':
                                    if view_service:
                                        view_service.toggle_percent()
                                elif value == ',':
                                    if view_service:
                                        view_service.toggle_group()
                                elif value == '!':
                                    if view_service:
                                        view_service.toggle_datetime_format()
                                else:
                                    result = False

                            if result:
                                value = None
                                value_changed = True
                                command_timeout = 0

                        except Exception as e:
                            siis_logger.error(repr(e))
                            traceback_logger.error(traceback.format_exc())

            except IOError:
                pass
            except Exception as e:
                siis_logger.error(repr(e))
                traceback_logger.error(traceback.format_exc())

            # display advanced command only
            if value_changed:
                if value and value.startswith(':'):
                    Terminal.inst().message("Command: %s" % value[1:],
                                            view='command')
                else:
                    Terminal.inst().message("", view='command')

            # clear input if no char hit during the last MAX_CMD_ALIVE
            if value and not value.startswith(':'):
                if (command_timeout > 0) and (time.time() - command_timeout >=
                                              MAX_CMD_ALIVE):
                    value = None
                    value_changed = True
                    Terminal.inst().info("Current typing canceled",
                                         view='status')

            try:
                # display strategy tarding time (update max once per second)
                if strategy_service.timestamp - prev_timestamp >= 1.0:
                    mode = "live"
                    if trader_service.backtesting:
                        mode = "backtesting"
                    elif trader_service.paper_mode:
                        mode = "paper-mode"

                    Terminal.inst().message(
                        "%s - %s" %
                        (mode,
                         datetime.fromtimestamp(strategy_service.timestamp).
                         strftime('%Y-%m-%d %H:%M:%S')),
                        view='notice')
                    prev_timestamp = strategy_service.timestamp

                # synchronous operations here
                watcher_service.sync()
                trader_service.sync()
                strategy_service.sync()

                if monitor_service:
                    monitor_service.sync()

                if view_service:
                    view_service.sync()

                if notifier_service:
                    notifier_service.sync()

                Terminal.inst().update()

            except BaseException as e:
                siis_logger.error(repr(e))
                traceback_logger.error(traceback.format_exc())

            # don't waste CPU time on main thread
            time.sleep(LOOP_SLEEP)

    finally:
        Terminal.inst().restore_term()

    Terminal.inst().info("Terminate...")
    Terminal.inst().flush()

    commands_handler.terminate(options) if commands_handler else None
    commands_handler = None

    # service terminate
    monitor_service.terminate() if monitor_service else None
    strategy_service.terminate() if strategy_service else None
    trader_service.terminate() if trader_service else None
    watcher_service.terminate() if watcher_service else None
    view_service.terminate() if view_service else None
    notifier_service.terminate() if notifier_service else None

    Terminal.inst().info("Saving database...")
    Terminal.inst().flush()

    Database.terminate()

    watchdog_service.terminate() if watchdog_service else None

    Terminal.inst().info("Bye!")
    Terminal.inst().flush()

    Terminal.terminate()
示例#16
0
import pandas as pd
import arrow
from tools.tool import Tool
#

# a = arrow.now()
# print(a)
# b = arrow.get('2010-01-15')
# print(b)
#
#
# d = arrow.get('2005-10-29')
# c = b - d
# print(c, type(c), c.days)
#
#
# def getTimedelta(dayStr):
#     if dayStr == '无日期':
#         return 0
#     now = arrow.now()
#     target_day = arrow.get(dayStr)
#     diff = now - target_day
#     return diff.days
# print(arrow.now().date())
a = Tool().getTradeDayList('')
print(a)