Skip to main content

trailing_stop_calculate

Function trailing_stop_calculate 

Source
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, trigger type, or trailing offset type is invalid.
  • the order lacks a required trigger, trailing offset, trailing offset type, or limit offset.
  • the calculated price cannot be represented as a [Price].