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
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) print(order) return None
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
def interactively_choose_timestamp(self, strategy_name): list_of_timestamps = sorted( self.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 interactively_choose_stage(self): list_of_stages = self.get_list_of_stages() print("Which stage to acccess:\n") stage_name = print_menu_of_values_and_get_response(list_of_stages, default_str="EXIT") if stage_name=="EXIT": return user_exit return stage_name
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 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) return None
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_valid_strategy_name_from_user( data=arg_not_supplied, allow_all=False, all_code="ALL", source="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
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_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
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) instrument_code = get_valid_code_from_list(instrument_code_list) if instrument_code is user_exit: return None pos_series = diag_positions.get_position_df_for_strategy_and_instrument(strategy_name, instrument_code) print(pos_series) return None
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()
def interactively_choose_method(self, stage_name): list_of_methods = self.get_list_of_methods_for_stage(stage_name) print("Which method:\n") method_name = print_menu_of_values_and_get_response(list_of_methods) return method_name