def build_attribute_dict(diag_logs, lookback_days):
    attribute_dict = {}
    not_finished = True
    while not_finished:
        print("Attributes selected so far %s" % str(attribute_dict))
        list_of_attributes = diag_logs.get_list_of_unique_log_attribute_keys(
            attribute_dict=attribute_dict, lookback_days=lookback_days
        )
        print("Which attribute to filter by?")
        attribute_name = print_menu_of_values_and_get_response(list_of_attributes)
        list_of_attribute_values = (
            diag_logs.get_unique_list_of_values_for_log_attribute(
                attribute_name,
                attribute_dict=attribute_dict,
                lookback_days=lookback_days,
            )
        )
        print("Which value for %s ?" % attribute_name)
        attribute_value = print_menu_of_values_and_get_response(
            list_of_attribute_values
        )
        attribute_dict[attribute_name] = attribute_value
        ans = input("Have you finished? (RETURN: No, anything else YES)")
        if not ans == "":
            not_finished = False
            break

    return attribute_dict
Пример #2
0
def get_valid_fx_code_from_user(
    data: dataBlob = arg_not_supplied, allow_none=False, none_str="None"
) -> str:
    if data is arg_not_supplied:
        data = dataBlob()
    all_fx_codes = get_list_of_fxcodes(data)
    if allow_none:
        fx_code = print_menu_of_values_and_get_response(
            all_fx_codes, default_str=none_str
        )
    else:
        fx_code = print_menu_of_values_and_get_response(all_fx_codes)

    return fx_code
def get_rolling_master_function():
    MANUAL_INPUT = "Manually input instrument codes and manually decide when to roll"
    MENU_OPTIONS = [
        MANUAL_INPUT,
        "Cycle through instrument codes automatically, but manually decide when to roll",
        "Cycle through instrument codes automatically, auto decide when to roll, manually confirm rolls",
        "Cycle through instrument codes automatically, auto decide when to roll, automatically roll",
    ]

    function_list = [
        update_roll_status_manual_cycle,
        update_roll_status_auto_cycle_manual_decide,
        update_roll_status_auto_cycle_manual_confirm,
        update_roll_status_full_auto,
    ]

    print("How do you want to do your rolls today?")
    selection = print_menu_of_values_and_get_response(
        MENU_OPTIONS, default_str=MANUAL_INPUT
    )
    selection_idx = MENU_OPTIONS.index(selection)

    function_to_call = function_list[selection_idx]

    return function_to_call
def get_roll_state_required(roll_data: RollDataWithStateReporting) -> RollState:
    invalid_input = True
    while invalid_input:
        roll_data.display_roll_query_banner()
        roll_state_required_as_str = print_menu_of_values_and_get_response(
            roll_data.allowable_roll_states_as_list_of_str
        )

        if roll_state_required_as_str != roll_data.original_roll_status_as_string:
            # check if changing
            print("")
            check = input(
                "Changing roll state for %s from %s to %s, are you sure y/n to try again/<RETURN> to exit: "
                % (
                    roll_data.instrument_code,
                    roll_data.original_roll_status_as_string,
                    roll_state_required_as_str,
                )
            )
            print("")
            if check == "y":
                # happy
                return RollState[roll_state_required_as_str]

            elif check == "":
                print("Okay, we're done")
                return no_change_required

            else:
                print("OK. Choose again.")
                # back to top of loop
                continue
        else:
            print("No change")
            return no_change_required
def view_individual_order(data):
    list_of_order_types = [
        "Instrument / Strategy",
        "Instrument / Contract",
        "Broker level",
    ]
    print("Which order queue?")
    order_type = print_menu_of_values_and_get_response(list_of_order_types)
    order_id = get_and_convert(
        "Order number?", type_expected=int, default_value=None, default_str="CANCEL"
    )
    if order_id is None:
        return None

    data_orders = dataOrders(data)
    if order_type == list_of_order_types[0]:
        order = data_orders.get_historic_instrument_order_from_order_id(order_id)
    elif order_type == list_of_order_types[1]:
        order = data_orders.get_historic_contract_order_from_order_id(order_id)
    elif order_type == list_of_order_types[2]:
        order = data_orders.get_historic_broker_order_from_order_id(order_id)
    else:
        print("Don't know what to do")
        return None

    print(order.full_repr())

    return None
def actual_instrument_position(data):
    diag_positions = diagPositions(data)

    strategy_name_list = diag_positions.get_list_of_strategies_with_positions()
    strategy_name = print_menu_of_values_and_get_response(strategy_name_list)
    if strategy_name is user_exit:
        return None

    instrument_code_list = (
        diag_positions.get_list_of_instruments_for_strategy_with_position(
            strategy_name, ignore_zero_positions=False
        )
    )
    instrument_code = get_valid_code_from_list(instrument_code_list)
    if instrument_code is user_exit:
        return None
    instrument_strategy = instrumentStrategy(
        strategy_name=strategy_name, instrument_code=instrument_code
    )

    pos_series = diag_positions.get_position_df_for_instrument_strategy(
        instrument_strategy
    )
    print(pos_series)
    return None
def enter_manual_contract_order(data, instrument_order):
    strategy_name = instrument_order.strategy_name
    instrument_code = instrument_order.instrument_code
    qty = instrument_order.trade

    leg_count = get_and_convert("How many legs?", type_expected=int, default_value=1)
    contract_id_list = []
    for leg_idx in range(leg_count):
        print("Choose contract for leg %d" % leg_idx)
        _, contract_date = get_valid_instrument_code_and_contractid_from_user(
            data, instrument_code=instrument_code
        )
        contract_id_list.append(contract_date)

    trade_qty_list = []
    for trade_idx in range(leg_count):
        trade_qty = get_and_convert(
            "Enter quantity for leg %d" % trade_idx,
            type_expected=int,
            allow_default=False,
        )
        trade_qty_list.append(trade_qty)

    if sum(trade_qty_list) != sum(qty):
        print(
            "Sum of instrument quantity %s is different from sum of contract quantity %s"
            % (str(qty), str(trade_qty_list))
        )
        print("It's unlikely you meant to do this...")

    NO_ALGO = "None: allow system to allocate"
    algo_to_use = print_menu_of_values_and_get_response(
        list_of_algos, default_str=NO_ALGO
    )
    if algo_to_use == NO_ALGO:
        algo_to_use = ""

    limit_price = get_and_convert(
        "Limit price? (will override instrument order limit price, will be ignored by some algo types",
        type_expected=float,
        default_str="None",
        default_value=None,
    )

    order_type = map_instrument_order_type_to_contract_order_type(
        instrument_order.order_type
    )
    contract_order = contractOrder(
        strategy_name,
        instrument_code,
        contract_id_list,
        trade_qty_list,
        algo_to_use=algo_to_use,
        order_type=order_type,
        reference_price=None,
        limit_price=limit_price,
        manual_trade=True,
    )

    return contract_order
    def get_roll_state_required(self) -> str:
        invalid_input = True
        while invalid_input:
            self.display_roll_query_banner()
            roll_state_required_as_str = print_menu_of_values_and_get_response(
                self.allowable_roll_states_as_list_of_str)

            if roll_state_required_as_str != self.original_roll_status_as_string:
                # check if changing
                print("")
                check = input(
                    "Changing roll state for %s from %s to %s, are you sure y/n to try again/<RETURN> to exit: "
                    %
                    (self.instrument_code, self.original_roll_status_as_string,
                     roll_state_required_as_str))
                print("")
                if check == "y":
                    # happy
                    self.set_new_roll_state(roll_state_required_as_str)
                    return roll_state_required_as_str

                elif check == "":
                    print("Okay, we're done")
                    return no_state_available

                else:
                    print("OK. Choose again.")
                    # back to top of loop
                    continue
            else:
                print("No change")
                return no_state_available
Пример #9
0
def get_valid_fx_code_from_user(data: dataBlob = arg_not_supplied) -> str:
    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
def capital_strategy(data):
    data_capital = dataCapital(data)
    strat_list = data_capital.get_list_of_strategies_with_capital()
    strategy_name = print_menu_of_values_and_get_response(
        strat_list, default_str=strat_list[0]
    )
    capital_series = data_capital.get_capital_pd_series_for_strategy(strategy_name)
    print(capital_series.tail(30))
    return None
Пример #11
0
def interactively_choose_timestamp(strategy_name: str,
                                   data: dataBlob = arg_not_supplied):
    data_backtest = dataBacktest(data)
    list_of_timestamps = sorted(
        data_backtest.get_list_of_timestamps_for_strategy(strategy_name))
    # most recent last
    print("Choose the backtest to load:\n")
    timestamp = print_menu_of_values_and_get_response(
        list_of_timestamps, default_str=list_of_timestamps[-1])
    return timestamp
def get_state_to_use_for_held_position() -> RollState:

    print(
        "Choose state to automatically assume if we have a position in priced contract AND roll state is currently NO ROLL"
    )

    select_state_for_position_held = print_menu_of_values_and_get_response(
        STATE_OPTIONS_AS_STR, default_str=STATE_OPTIONS_AS_STR[0])

    state_when_position_held = STATE_OPTIONS[STATE_OPTIONS_AS_STR.index(
        select_state_for_position_held)]

    return state_when_position_held
Пример #13
0
def get_valid_strategy_name_from_user(data: dataBlob = arg_not_supplied,
                                      allow_all: bool = False,
                                      all_code: str = "ALL",
                                      source: str = "config"):
    all_strategies = get_list_of_strategies(data=data, source=source)
    if allow_all:
        default_strategy = all_code
    else:
        default_strategy = all_strategies[0]

    strategy_name = print_menu_of_values_and_get_response(
        all_strategies, default_str=default_strategy)

    return strategy_name
Пример #14
0
def update_system_backtests():
    ## function if called from script
    with dataBlob(log_name="Update-System_Backtest") as data:
        list_of_strategies = get_list_of_strategies_for_process(data, process_name)
        ALL = "ALL"
        print("Which strategy?")
        strategy_name = print_menu_of_values_and_get_response(list_of_strategies, default_str=ALL)

        if not strategy_name == ALL:
            list_of_strategies = [strategy_name]


        for strategy_name in list_of_strategies:
            system_backtest_runner = strategyRunner(data, strategy_name, process_name, backtest_function)
            system_backtest_runner.run_strategy_method()
Пример #15
0
def update_strategy_orders():
    ## function if called from script
    with dataBlob(log_name="Update-Strategy-Orders") as data:

        list_of_strategies = get_list_of_strategies_for_process(
            data, process_name)
        ALL = "ALL"
        print("Which strategy?")
        strategy_name = print_menu_of_values_and_get_response(
            list_of_strategies, default_str=ALL)

        if not strategy_name == ALL:
            list_of_strategies = [strategy_name]

        for strategy_name in list_of_strategies:
            strategy_order_generator = strategyRunner(
                data, strategy_name, process_name,
                name_of_main_generator_method)
            strategy_order_generator.run_strategy_method()