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
TriggerType
orTrailingOffsetType
.
§Panics
- If the
trailing_offset_type
isNoTrailingOffset
or thetrigger_type
isNoTrigger
. - If the
trailing_offset
cannot be converted to a float. - If the
trigger_type
is not supported by this function. - If the
order_type
is not a trailing stop type.