예제 #1
0
def main():
    # Initialize Argument Parser
    parser = argparse.ArgumentParser()
    parser.add_argument("-u", "--update", help="Daily Update Data (Execute Before Market Starts)",
                        action="store_true")
    parser.add_argument("-fu", "--force_update",
                        help="Force Update All Data Up to Max. Allowed Years (USE WITH CAUTION)", action="store_true")
    parser.add_argument("-d", "--database", help="Store All CSV Data to Database", action="store_true")

    # Retrieve file names for all strategies as the argument option
    strategy_list = [Path(file_name).name[:-3] for file_name in glob.glob("./strategies/*.py") if
                     "__init__" not in file_name and "Strategies" not in file_name]
    parser.add_argument("-s", "--strategy", type=str, choices=strategy_list,
                        help="Execute HFT using Pre-defined Strategy")

    # Retrieve file names for all strategies as the argument option
    filter_list = [Path(file_name).name[:-3] for file_name in glob.glob("./filters/*.py") if
                   "__init__" not in file_name and "Filters" not in file_name]
    parser.add_argument("-f", "--filter", type=str, choices=filter_list, nargs="+",
                        help="Filter Stock List based on Pre-defined Filters")
    parser.add_argument("-en", "--email_name", type=str, help="Name of the applied stock filtering techniques")

    # Evaluate Arguments
    args = parser.parse_args()

    # Initialization Connection
    futu_trade = trading_engine.FutuTrade()
    email_handler = email_engine.Email()

    # Initialize Config Parser
    config = configparser.ConfigParser()
    config.read("config.ini")

    # Initialize Stock List
    stock_list = json.loads(config.get('TradePreference', 'StockList'))
    if not stock_list:
        stock_list = data_engine.DatabaseInterface(
            database_path=config.get('Database', 'Database_path')).get_stock_list()

    if args.filter:
        filtered_stock_list = init_stock_filter(args.filter)
        filtered_stock_dict = YahooFinanceInterface.get_stocks_email(filtered_stock_list)
        subscription_list = json.loads(config.get('Email', 'SubscriptionList'))
        for subscriber in subscription_list:
            filter_name = args.email_name if args.email_name else "Default Stock Filter"
            email_handler.write_daily_stock_filter_email(subscriber, filter_name, filtered_stock_dict)
    if args.update:
        # Daily Update Data
        daily_update_data(futu_trade=futu_trade, stock_list=stock_list, force_update=args.force_update)
    if args.database:
        # Update ALl Data to Database
        futu_trade.store_all_data_database()
    if args.strategy:
        # Initialize Strategies
        stock_list = filtered_stock_list if args.filter else stock_list
        stock_list.extend(data_engine.YahooFinanceInterface.get_top_30_hsi_constituents())
        init_day_trading(futu_trade, stock_list, args.strategy)
        futu_trade.display_quota()
예제 #2
0
파일: main.py 프로젝트: juvu/futu_algo
def main():
    # Initialize Argument Parser
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-u",
        "--update",
        help="Daily Update Data (Execute Before Market Starts)",
        action="store_true")
    parser.add_argument(
        "-fu",
        "--force_update",
        help=
        "Force Update All Data Up to Max. Allowed Years (USE WITH CAUTION)",
        action="store_true")
    parser.add_argument("-d",
                        "--database",
                        help="Store All CSV Data to Database",
                        action="store_true")

    # Retrieve file names for all strategies as the argument option
    strategy_list = [
        file_name.split("\\")[1][:-3]
        for file_name in glob.glob(f"./strategies/*.py")
        if "__init__" not in file_name and "Strategies" not in file_name
    ]
    parser.add_argument("-s",
                        "--strategy",
                        type=str,
                        choices=strategy_list,
                        help="Execute HFT using Pre-defined Strategy")

    # Retrieve file names for all strategies as the argument option
    filter_list = [
        file_name.split("\\")[1][:-3]
        for file_name in glob.glob(f"./filters/*.py")
        if "__init__" not in file_name and "Filters" not in file_name
    ]
    parser.add_argument("-f",
                        "--filter",
                        type=str,
                        choices=filter_list,
                        nargs="+",
                        help="Filter Stock List based on Pre-defined Filters")

    # Evaluate Arguments
    args = parser.parse_args()

    # Initialization Connection
    futu_trade = trading_engine.FutuTrade()

    if args.filter:
        filtered_stock_list = init_stock_filter(args.filter)
        print(filtered_stock_list)
    if args.update:
        # Daily Update Data
        daily_update_data(futu_trade=futu_trade,
                          force_update=args.force_update)
    if args.database:
        # Update ALl Data to Database
        futu_trade.store_all_data_database()
    if args.strategy:
        # Initialize Strategies
        # stock_list = filtered_stock_list if args.filter else data_engine.DatabaseInterface(
        #     database_path='./database/stock_data.sqlite').get_stock_list()
        stock_list = [
            'HK.00322', 'HK.01208', 'HK.01378', 'HK.01530', 'HK.01860',
            'HK.02600'
        ]
        stock_list.extend(
            data_engine.YahooFinanceInterface.get_top_30_hsi_constituents())
        init_day_trading(futu_trade, stock_list, args.strategy)
        futu_trade.display_quota()

    init_backtesting()