pub fn trailing_stop_calculate(
price_increment: Price,
trigger_px: Option<Price>,
activation_px: Option<Price>,
order: &OrderAny,
bid: Option<Price>,
ask: Option<Price>,
last: Option<Price>,
) -> Result<(Option<Price>, Option<Price>)>Expand description
Calculates the new trigger and limit prices for a trailing stop order.
trigger_px and activation_px are optional overrides for the prices already
carried inside order. If Some(_), they take priority over the values on the
order itself, otherwise the function falls back to the values stored on the order.
§Returns
A tuple with the newly-set trigger-price and limit-price (if any).
None in either position means the respective price did not improve.
§Errors
Returns an error if:
- the order type or trigger type is invalid.
- the order does not carry a valid
TriggerTypeorTrailingOffsetType.
§Panics
- If the
trailing_offset_typeisNoTrailingOffsetor thetrigger_typeisNoTrigger. - If the
trailing_offsetcannot be converted to a float. - If the
trigger_typeis not supported by this function. - If the
order_typeis not a trailing stop type.