def _apply_float_override(override_as_float: float, original_position_no_override: int, proposed_trade: Order) -> Order: """ Works if override value is float, or override_close (float value is 0.0) or override_none (float value is 1.0) :param original_position_no_override: :param proposed_trade: :return: """ if override_as_float == 1.0: return proposed_trade desired_new_position = original_position_no_override + proposed_trade.trade.as_single_trade_qty_or_error() override_new_position = int( np.floor( desired_new_position * override_as_float)) new_trade_value = override_new_position - original_position_no_override proposed_trade.replace_required_trade_size_only_use_for_unsubmitted_trades( tradeQuantity(new_trade_value)) return proposed_trade
def _apply_reduce_only(original_position_no_override: int, proposed_trade: Order) -> Order: proposed_trade_value = proposed_trade.trade.as_single_trade_qty_or_error() desired_new_position = original_position_no_override + proposed_trade_value if sign(desired_new_position) != sign(original_position_no_override): # Wants sign to change, we convert into a pure closing trade new_trade_value = -original_position_no_override elif abs(desired_new_position) > abs(original_position_no_override): # Increasing trade not allowed, zero trade new_trade_value = 0 else: # Reducing trade and sign not changing, we'll allow new_trade_value = proposed_trade_value proposed_trade.replace_required_trade_size_only_use_for_unsubmitted_trades( tradeQuantity(new_trade_value)) return proposed_trade
def what_trade_is_possible(position: int, position_limit: int, order: Order) -> Order: ## POSIITON LIMITS CAN ONLY BE APPLIED TO SINGLE LEG TRADES, EG INSTRUMENT ORDERS proposed_trade = order.as_single_trade_qty_or_error() possible_trade = what_trade_is_possible_single_leg_trade(position=position, position_limit=position_limit, proposed_trade=proposed_trade) possible_trade_as_trade_qty = tradeQuantity(possible_trade) order = order.replace_required_trade_size_only_use_for_unsubmitted_trades(possible_trade_as_trade_qty) return order
def _apply_no_trading(proposed_trade: Order): new_trade = proposed_trade.replace_required_trade_size_only_use_for_unsubmitted_trades( tradeQuantity(0)) return new_trade