def update_roll_state(instrument_code: str):
    """
    Update the roll state for a particular instrument
    This includes the option, where possible, to switch the adjusted price series on to a new contract

    :param instrument_code: str
    :return: None
    """
    """
    mongo_db = mongoDb()
    log=logger("Update-Sampled_Contracts", mongo_db=mongo_db)
    """
    with mongoDb() as mongo_db,\
        logger("Update-Roll-Adjusted-Prices", mongo_db=mongo_db, instrument_code=instrument_code) as log:

        data = dataBlob("mongoRollStateData", mongo_db=mongo_db, log=log)

        ## First get the roll info
        # This will also update to console
        report_results = run_report_with_data_blob(
            roll_report_config, data, instrument_code=instrument_code)
        if report_results is failure:
            print("Can't run roll report, so can't change status")
            return failure

        current_roll_status, roll_state_required = get_required_roll_state(
            data, instrument_code)
        if roll_state_required is no_state_available:
            return failure

        data.mongo_roll_state.set_roll_state(instrument_code,
                                             roll_state_required)

        if roll_state_required is roll_adj_state:
            ## Going to roll adjusted prices
            roll_result = _roll_adjusted_and_multiple_prices(
                data, instrument_code)
            if roll_result is success:
                ## Return the state back to default (no roll) state
                data.log.msg(
                    "Successful roll! Returning roll state of %s to %s" %
                    (instrument_code, default_state))
                data.mongo_roll_state.set_roll_state(instrument_code,
                                                     default_state)
            else:
                data.log.msg(
                    "Something has gone wrong with rolling adjusted of %s! Returning roll state to previous state of %s"
                    % (instrument_code, current_roll_status))
                data.mongo_roll_state.set_roll_state(instrument_code,
                                                     current_roll_status)

        return success
def interactive_update_roll_status():
    """
    Update the roll state for a particular instrument
    This includes the option, where possible, to switch the adjusted price series on to a new contract

    :param instrument_code: str
    :return: None
    """

    with dataBlob(log_name="Interactive_Update-Roll-Status") as data:
        instrument_code = get_valid_instrument_code_from_user(data=data)
        # First get the roll info
        # This will also update to console
        config = roll_report_config.new_config_with_modified_output("console")
        config.modify_kwargs(instrument_code=instrument_code)
        report_results = run_report_with_data_blob(config, data)
        if report_results is failure:
            print("Can't run roll report, so can't change status")
            return failure

        current_roll_status, roll_state_required = get_required_roll_state(
            data, instrument_code)
        if roll_state_required is no_state_available:
            return failure

        update_positions = updatePositions(data)
        update_positions.set_roll_state(instrument_code, roll_state_required)

        if roll_state_required is roll_adj_state:
            # Going to roll adjusted prices
            roll_result = _roll_adjusted_and_multiple_prices(
                data, instrument_code)
            if roll_result is success:
                # Return the state back to default (no roll) state
                data.log.msg(
                    "Successful roll! Returning roll state of %s to %s" %
                    (instrument_code, default_state))
                update_positions.set_roll_state(instrument_code, default_state)
            else:
                data.log.msg(
                    "Something has gone wrong with rolling adjusted of %s! Returning roll state to previous state of %s"
                    % (instrument_code, current_roll_status))
                update_positions.set_roll_state(instrument_code,
                                                current_roll_status)

        return success
def run_roll_report(data: dataBlob, instrument_code: str):
    config = roll_report_config.new_config_with_modified_output("console")
    config.modify_kwargs(instrument_code=instrument_code)
    report_results = run_report_with_data_blob(config, data)
    if report_results is failure:
        raise Exception("Can't run roll report, so can't change status")