def create_contract_orders_outright( data, instrument_code, priced_contract_id, forward_contract_id, position_in_priced): diag_prices = diagPrices(data) reference_price_priced_contract, reference_price_forward_contract = tuple( diag_prices.get_last_matched_prices_for_contract_list( instrument_code, [priced_contract_id, forward_contract_id] ) ) strategy = ROLL_PSEUDO_STRATEGY first_order = contractOrder( strategy, instrument_code, priced_contract_id, -position_in_priced, reference_price=reference_price_priced_contract, roll_order=True, inter_spread_order=True, ) second_order = contractOrder( strategy, instrument_code, forward_contract_id, position_in_priced, reference_price=reference_price_forward_contract, roll_order=True, inter_spread_order=True, ) return [first_order, second_order]
def create_contract_orders_spread( data, instrument_code, priced_contract_id, forward_contract_id, position_in_priced): diag_prices = diagPrices(data) reference_price_priced_contract, reference_price_forward_contract = tuple( diag_prices.get_last_matched_prices_for_contract_list( instrument_code, [priced_contract_id, forward_contract_id] ) ) strategy = ROLL_PSEUDO_STRATEGY contract_id_list = [priced_contract_id, forward_contract_id] trade_list = [-position_in_priced, position_in_priced] spread_reference_price = ( reference_price_priced_contract - reference_price_forward_contract ) spread_order = contractOrder( strategy, instrument_code, contract_id_list, trade_list, reference_price=spread_reference_price, roll_order=True, ) return [spread_order]
def contract_order_for_direct_instrument_child_date_and_trade( instrument_order, child_date_and_trade): """ Gets a child contract order from a parent instrument order where the instrument is 'direct' eg the instrument name is the same as the instrument traded (This will not be the case for inter market orders) :param instrument_order: original parent order :param child_date_and_trade: :return: contractOrder. Fields reference_price, algo_to_use, limit_price will be set later """ if child_date_and_trade is None: return None child_contract, child_trade = child_date_and_trade parent_id = instrument_order.order_id strategy = instrument_order.strategy_name instrument = instrument_order.instrument_code child_contract_order = contractOrder( strategy, instrument, child_contract, child_trade, parent=parent_id, ) return child_contract_order
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, ) contract_order = contractOrder( strategy_name, instrument_code, contract_id_list, trade_qty_list, algo_to_use=algo_to_use, reference_price=None, limit_price=limit_price, manual_trade=True, ) return contract_order
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...") algo_to_use = get_and_convert( "Algo to use (Full function eg sysexecution.algos.algo_market.algo_market)", type_expected=str, default_str="None: Algo will be allocated automatically", default_value="") 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) contract_order = contractOrder( strategy_name, instrument_code, contract_id_list, trade_qty_list, algo_to_use=algo_to_use, reference_price=None, limit_price=limit_price, manual_trade=True, ) return contract_order
def create_balance_contract_order_from_broker_order(broker_order): contract_order = contractOrder(broker_order.strategy_name, broker_order.instrument_code, broker_order.contract_id, broker_order.trade, fill=broker_order.fill, algo_to_use=broker_order.algo_used, filled_price=broker_order.filled_price, fill_datetime=broker_order.fill_datetime, manual_fill=True, manual_trade=True, active=False) return contract_order