def create_contract_orders_outright( roll_spread_info: rollSpreadInformation, ) -> listOfOrders: strategy = ROLL_PSEUDO_STRATEGY first_order = contractOrder( strategy, roll_spread_info.instrument_code, roll_spread_info.priced_contract_id, -roll_spread_info.position_in_priced, reference_price=roll_spread_info.reference_price_priced_contract, roll_order=True, order_type=CONTRACT_ORDER_TYPE_FOR_ROLL_ORDERS, ) second_order = contractOrder( strategy, roll_spread_info.instrument_code, roll_spread_info.forward_contract_id, roll_spread_info.position_in_priced, reference_price=roll_spread_info.reference_price_forward_contract, roll_order=True, order_type=CONTRACT_ORDER_TYPE_FOR_ROLL_ORDERS, ) return listOfOrders([first_order, second_order])
def contract_order_for_direct_instrument_child_date_and_trade( instrument_order: instrumentOrder, child_date_and_trade: contractIdAndTrade ) -> contractOrder: """ 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 """ child_contract, child_trade = child_date_and_trade parent_id = instrument_order.order_id strategy = instrument_order.strategy_name instrument = instrument_order.instrument_code order_type = map_instrument_order_type_to_contract_order_type( instrument_order.order_type ) # parent, limit and reference information will be added later child_contract_order = contractOrder( strategy, instrument, child_contract, child_trade, order_type=order_type, 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, ) 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 create_balance_contract_order_from_broker_order(broker_order: brokerOrder): contract_order = contractOrder( broker_order.strategy_name, broker_order.instrument_code, broker_order.contract_date_key, 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, order_type=balance_order_type_for_contract_orders) return contract_order
def create_contract_orders_spread(roll_spread_info: rollSpreadInformation) -> listOfOrders: strategy = ROLL_PSEUDO_STRATEGY contract_id_list = [roll_spread_info.priced_contract_id, roll_spread_info.forward_contract_id] trade_list = [-roll_spread_info.position_in_priced, roll_spread_info.position_in_priced] spread_order = contractOrder( strategy, roll_spread_info.instrument_code, contract_id_list, trade_list, reference_price=roll_spread_info.reference_price_spread, roll_order=True, order_type = CONTRACT_ORDER_TYPE_FOR_ROLL_ORDERS ) return listOfOrders([spread_order])