コード例 #1
0
def get_list_of_timer_functions_for_backup():
    data_arctic_backups = dataBlob(log_name='backup_arctic_to_csv')
    data_backup_files = dataBlob(log_name='backup_files')

    arctic_backup_object = backupArcticToCsv(data_arctic_backups)
    files_backup_object = backupFiles(data_backup_files)

    list_of_timer_names_and_functions = [('backup_arctic_to_csv',
                                          arctic_backup_object),
                                         ('backup_files', files_backup_object)]

    return list_of_timer_names_and_functions
コード例 #2
0
def get_list_of_timer_functions_for_capital_update():
    data_total_capital = dataBlob(log_name="update_total_capital")
    data_strategy_capital = dataBlob(log_name="strategy_allocation")

    total_capital_update_object = totalCapitalUpdate(data_total_capital)
    strategy_capital_update_object = updateStrategyCapital(
        data_strategy_capital)
    list_of_timer_names_and_functions = [
        ("update_total_capital", total_capital_update_object),
        ("strategy_allocation", strategy_capital_update_object),
    ]

    return list_of_timer_names_and_functions
コード例 #3
0
def get_list_of_timer_functions_for_cleaning():
    data_backtests = dataBlob(log_name='clean_backtest_states')
    data_echos = dataBlob(log_name='clean_echo_files')
    data_logs = dataBlob(log_name ='clean_log_files')

    backtest_clean_object = cleanTruncateBacktestStates(data_backtests)
    log_clean_object = cleanTruncateLogFiles(data_logs)
    echo_clean_object = cleanTruncateEchoFiles(data_echos)

    list_of_timer_names_and_functions = [
                        ('clean_backtest_states', backtest_clean_object),
        ('clean_echo_files', echo_clean_object),
        ('clean_log_files', log_clean_object)]

    return list_of_timer_names_and_functions
コード例 #4
0
    def __init__(self, data=arg_not_supplied):
        # Check data has the right elements to do this
        if data is arg_not_supplied:
            data = dataBlob()

        data.add_class_list("mongoControlProcessData")
        self.data = data
コード例 #5
0
def get_data_and_create_csv_directories():

    backup_dir = get_private_then_default_key_value('csv_backup_directory')

    class_paths = dict(csvFuturesContractPriceData="contract_prices",
                       csvFuturesAdjustedPricesData="adjusted_prices",
                       csvFuturesMultiplePricesData="multiple_prices",
                       csvFxPricesData="fx_prices")

    for class_name, path in class_paths.items():
        dir_name = "%s/%s/" % (backup_dir, path)
        class_paths[class_name] = dir_name
        if not os.path.exists(dir_name):
            os.mkdir(dir_name)

    data = dataBlob(csv_data_paths=class_paths, keep_original_prefix=True)

    data.add_class_list(
        "csvFuturesContractPriceData csvFuturesAdjustedPricesData csvFuturesMultiplePricesData csvFxPricesData"
    )
    data.add_class_list(
        "arcticFuturesContractPriceData arcticFuturesMultiplePricesData arcticFuturesAdjustedPricesData arcticFxPricesData"
    )

    return data
コード例 #6
0
    def __init__(self, data = arg_not_supplied):
        # Check data has the right elements to do this
        if data is arg_not_supplied:
            data = dataBlob()

        data.add_class_list("mongoRollStateData mongoContractPositionData mongoStrategyPositionData mongoOptimalPositionData")
        self.data = data
コード例 #7
0
def update_fx_prices():
    """
    Update FX prices stored in Arctic (Mongo) with interactive brokers prices (usually going back about a year)

    :return: Nothing
    """

    with mongoDb() as mongo_db,\
        logger("Update-FX-prices", mongo_db=mongo_db) as log,\
        connectionIB(log=log.setup(component="IB-connection")) as ib_conn:

        data = dataBlob("ibFxPricesData arcticFxPricesData",
                        ib_conn=ib_conn,
                        mongo_db=mongo_db)

        list_of_codes_all = data.ib_fx_prices.get_list_of_fxcodes(
        )  # codes must be in .csv file /sysbrokers/IB/ibConfigSpotFx.csv
        log.msg("FX Codes: %s" % str(list_of_codes_all))

        for fx_code in list_of_codes_all:
            try:
                log.label(currency_code=fx_code)
                update_fx_prices_for_code(fx_code, data)
            except Exception as e:
                log.warn("Something went wrong with FX update %s" % e)

    return success
コード例 #8
0
def run_daily_price_updates():
    process_name = "run_daily_prices_updates"
    data = dataBlob(log_name=process_name)
    list_of_timer_names_and_functions = get_list_of_timer_functions_for_price_update()
    price_process = processToRun(
        process_name, data, list_of_timer_names_and_functions)
    price_process.main_loop()
コード例 #9
0
def update_historical_prices():
    """
    Do a daily update for futures contract prices, using IB historical data

    :return: Nothing
    """
    with mongoDb() as mongo_db,\
        logger("Update-Historical-prices", mongo_db=mongo_db) as log,\
        connectionIB(mongo_db = mongo_db, log=log.setup(component="IB-connection")) as ib_conn:

        data = dataBlob(
            "ibFuturesContractPriceData arcticFuturesContractPriceData \
         arcticFuturesMultiplePricesData mongoFuturesContractData",
            mongo_db=mongo_db,
            log=log,
            ib_conn=ib_conn)

        list_of_codes_all = data.arctic_futures_multiple_prices.get_list_of_instruments(
        )
        for instrument_code in list_of_codes_all:
            update_historical_prices_for_instrument(
                instrument_code,
                data,
                log=log.setup(instrument_code=instrument_code))

    return success
コード例 #10
0
def interactive_update_capital_manual():
    """
    Interactive session that allows you to manipulate capital manually

    :return: Nothing
    """
    with dataBlob(log_name="Interactive-Update-Capital-Manual") as data:

        data_capital = dataCapital(data)

        still_running = True
        while still_running:
            # display capital and get input
            user_option_int = print_capital_and_get_user_input(data_capital)
            if user_option_int==0:
                setup_initial_capital(data_capital)
            elif user_option_int==1:
                update_capital_from_ib(data_capital)
            elif user_option_int==2:
                adjust_capital_for_delta(data_capital)
            elif user_option_int==3:
                modify_any_value(data_capital)
            elif user_option_int==4:
                delete_capital_since_time(data_capital)
            elif user_option_int==919:
                delete_all_capital(data_capital)
            elif user_option_int==5:
                still_running=False
                break
            else:
                print("%d is not a valid option but was in list of possible options: check code" % str(user_option_int))

            ## Back to top of while loop

    return success
コード例 #11
0
def update_manual_check_fx_prices(fx_code):
    """
    Update FX prices stored in Arctic (Mongo) with interactive brokers prices (usually going back about a year)

    :return: Nothing
    """

    with mongoDb() as mongo_db,\
        logger("Update-FX-prices", mongo_db=mongo_db) as log,\
        connectionIB(log=log.setup(component="IB-connection")) as ib_conn:

        data = dataBlob("ibFxPricesData arcticFxPricesData",
                        ib_conn=ib_conn,
                        mongo_db=mongo_db)

        list_of_codes_all = data.ib_fx_prices.get_list_of_fxcodes(
        )  # codes must be in .csv file /sysbrokers/IB/ibConfigSpotFx.csv

        if fx_code not in list_of_codes_all:
            print("\n\n\ %s is not an FX code (valid codes: %s) \n\n" %
                  (fx_code, list_of_codes_all))
            raise Exception()

        log.label(currency_code=fx_code)
        update_manual_check_fx_prices_for_code(fx_code, data)

    return success
コード例 #12
0
def run_stack_handler():
    process_name = "run_stack_handler"
    data = dataBlob(log_name=process_name)
    list_of_timer_names_and_functions = get_list_of_timer_functions_for_stack_handler()
    price_process = processToRun(
        process_name, data, list_of_timer_names_and_functions)
    price_process.main_loop()
コード例 #13
0
def get_valid_fx_code_from_user(data=arg_not_supplied):
    if data is arg_not_supplied:
        data = dataBlob()
    all_fx_codes = get_list_of_fxcodes(data)
    fx_code = print_menu_of_values_and_get_response(all_fx_codes)

    return fx_code
コード例 #14
0
def update_multiple_adjusted_prices_daily():
    """
    Do a daily update for multiple and adjusted prices

    :return: Nothing
    """

    with mongoDb() as mongo_db, \
            logger("Update-multiple-adjusted-prices(daily)", mongo_db=mongo_db) as log:

        data = dataBlob("arcticFuturesContractPriceData \
                        arcticFuturesMultiplePricesData \
                        arcticFuturesAdjustedPricesData",
                        mongo_db=mongo_db,
                        log=log)

        list_of_codes_all = data.arctic_futures_multiple_prices.get_list_of_instruments(
        )
        for instrument_code in ['CRUDE_W']:
            try:

                update_multiple_adjusted_prices_for_instrument(
                    instrument_code,
                    data,
                    log=log.setup(instrument_code=instrument_code))
            except Exception as e:
                log.warn("ERROR: Multiple price update went wrong: %s" %
                         str(e))

    return success
コード例 #15
0
ファイル: volumes.py プロジェクト: Zuj3brusu/pysystemtrade
    def __init__(self, data: dataBlob = arg_not_supplied):
        # Check data has the right elements to do this
        if data is arg_not_supplied:
            data = dataBlob()

        data.add_class_object(arcticFuturesContractPriceData)
        self.data = data
コード例 #16
0
    def __init__(self, data=arg_not_supplied):
        # Check data has the right elements to do this
        if data is arg_not_supplied:
            data = dataBlob()

        data.add_class_list("arcticFxPricesData")
        self.data = data
コード例 #17
0
    def __init__(self, data=arg_not_supplied):
        # Check data has the right elements to do this
        if data is arg_not_supplied:
            data = dataBlob()

        data.add_class_list(" mongoFuturesInstrumentData")
        self.data = data
コード例 #18
0
ファイル: logs.py プロジェクト: vincent997/pysystemtrade
    def __init__(self, data=arg_not_supplied):
        # Check data has the right elements to do this
        if data is arg_not_supplied:
            data = dataBlob()

        data.add_class_object(mongoLogData)
        self.data = data
コード例 #19
0
ファイル: orders.py プロジェクト: sparkles25/pysystemtrade
 def __init__(self, data = arg_not_supplied):
     # Check data has the right elements to do this
     if data is arg_not_supplied:
         data = dataBlob()
     data.add_class_list("mongoInstrumentOrderStackData mongoContractOrderStackData mongoBrokerOrderStackData")
     data.add_class_list("mongoContractHistoricOrdersData mongoStrategyHistoricOrdersData mongoBrokerHistoricOrdersData")
     self.data = data
コード例 #20
0
def update_sampled_contracts():
    """
    Update the active contracts, according to what is available in IB for a given instrument

    These are stored in mongoDB

    The active contracts list is used to see what contracts have historical data sampled for

    It does not tell you what the current priced, forward, or carry contract are - that is in multiple prices (DRY)

    However we base the list of theoretical active contracts on the current priced, forward, and carry contracts

    We will end up adding to this list when we roll; this will change the current priced, forward, and carry contract

    When we add a new contract (because one has become available), we get the exact expiry date from IB and save this with the
       contract data.

    We do not sample contracts on the list when they have passed their expiry date

    Contracts are never deleted from the database

    We don't check IB for contracts; since we can't reverse engineer a YYYYMM identifier from a YYYYMMDD

    :returns: None
    """
    with dataBlob(log_name="Update-Sampled_Contracts") as data:
        update_contracts_object = updateSampledContracts(data)
        update_contracts_object.update_sampled_contracts()
コード例 #21
0
def run_backups():
    process_name = "run_backups"
    data = dataBlob(log_name=process_name)
    list_of_timer_names_and_functions = get_list_of_timer_functions_for_backup()
    backup_process = processToRun(
        process_name, data, list_of_timer_names_and_functions)
    backup_process.main_loop()
コード例 #22
0
ファイル: trades.py プロジェクト: vincent997/pysystemtrade
def trades_info(
    data=arg_not_supplied,
    calendar_days_back=1,
    end_date=arg_not_supplied,
    start_date=arg_not_supplied,
):
    """
    Report on system status

    :param: data blob
    :return: list of formatted output items
    """
    if data is arg_not_supplied:
        data = dataBlob()

    if end_date is arg_not_supplied:
        end_date = datetime.datetime.now()

    if start_date is arg_not_supplied:
        start_date = end_date - datetime.timedelta(days=calendar_days_back)

    results_object = get_trades_report_data(data,
                                            start_date=start_date,
                                            end_date=end_date)
    formatted_output = format_trades_data(results_object)

    return formatted_output
コード例 #23
0
def run_cleaners():
    process_name = "run_cleaners"
    data = dataBlob(log_name=process_name)
    list_of_timer_names_and_functions = get_list_of_timer_functions_for_cleaning()
    cleaning_process = processToRun(
        process_name, data, list_of_timer_names_and_functions
    )
    cleaning_process.main_loop()
コード例 #24
0
    def __init__(self, data=arg_not_supplied):
        # Check data has the right elements to do this
        if data is arg_not_supplied:
            data = dataBlob()

        data.add_class_list("mongoOptimalPositionData")
        self.data = data
        self.log = data.log
コード例 #25
0
    def __init__(self, data=arg_not_supplied):
        # Check data has the right elements to do this
        if data is arg_not_supplied:
            data = dataBlob()

        data.add_class_list("arcticFuturesContractPriceData arcticFuturesMultiplePricesData \
         mongoFuturesContractData arcticFuturesAdjustedPricesData")
        self.data = data
コード例 #26
0
def run_capital_update():
    process_name = "run_capital_update"
    data = dataBlob(log_name=process_name)
    list_of_timer_names_and_functions = get_list_of_timer_functions_for_capital_update()
    capital_process = processToRun(
        process_name, data, list_of_timer_names_and_functions
    )
    capital_process.main_loop()
コード例 #27
0
    def __init__(self, data=arg_not_supplied):
        # Check data has the right elements to do this
        if data is arg_not_supplied:
            data = dataBlob()

        data.add_class_list(
            "ibFxPricesData ibFuturesContractPriceData ibFuturesContractData\
        ibContractPositionData ibOrdersData ibMiscData")
        self.data = data
コード例 #28
0
def run_strategy_order_generator():
    with dataBlob(log_name="run_strategy_order_generator") as data:

        # FIX ME CODE TO RUN MULTIPLE TIMES
        # FOR NOW JUST RUN ONCE A DAY
        order_handler = orderHandlerAcrossStrategies(data)
        order_handler.check_for_orders_across_strategies()

    return None
コード例 #29
0
def run_strategy_order_generator():
    data = dataBlob(log_name=process_name)
    list_of_timer_names_and_functions = get_list_of_timer_functions_for_strategies(
        process_name, data)
    order_process = processToRun(process_name,
                                 data,
                                 list_of_timer_names_and_functions,
                                 use_strategy_config=True)
    order_process.main_loop()
コード例 #30
0
def update_historical_prices():
    """
    Do a daily update for futures contract prices, using IB historical data

    :return: Nothing
    """
    with dataBlob(log_name="Update-Historical-Prices") as data:
        update_historical_price_object = updateHistoricalPrices(data)
        update_historical_price_object.update_historical_prices()
    return success