Skip to main content

ClosedOptionsPositionsRequest

Struct ClosedOptionsPositionsRequest 

Source
pub struct ClosedOptionsPositionsRequest<'a> {
    pub category: Category,
    pub symbol: Option<Cow<'a, str>>,
    pub start_time: Option<u64>,
    pub end_time: Option<u64>,
    pub limit: Option<usize>,
    pub cursor: Option<Cow<'a, str>>,
}
Expand description

Parameters for requesting closed options positions.

Used to construct a request to the /v5/position/get-closed-positions endpoint to retrieve closed options positions. Bots use this to analyze historical options trading performance, track P&L, and audit trading activity.

§Bybit API Reference

According to the Bybit V5 API documentation:

  • Only supports querying closed options positions in the last 6 months.
  • Sorted by closeTime in descending order.
  • Fee and price are displayed with trailing zeroes up to 8 decimal places.

§Usage Example

// Query closed options positions for a specific symbol
let request = ClosedOptionsPositionsRequest::new(
    Category::Option,
    Some("BTC-12JUN25-104019-C-USDT"),
    None,
    None,
    Some(50),
    None,
);

// Query all closed options positions from the last day
let request = ClosedOptionsPositionsRequest::new(
    Category::Option,
    None,
    Some(1749730000000), // startTime in milliseconds
    None,
    None,
    None,
);

Fields§

§category: Category

The product category (must be option).

Specifies the instrument type. For this endpoint, must be Category::Option.

§symbol: Option<Cow<'a, str>>

The options symbol name (e.g., “BTC-12JUN25-104019-C-USDT”) (optional).

Filters closed positions by symbol. If unset, all closed options positions are returned. Bots should specify this for targeted analysis of specific options contracts.

§start_time: Option<u64>

The start timestamp in milliseconds (optional).

The beginning of the time range for querying closed positions. According to Bybit API:

  • If neither start_time nor end_time are provided, returns data from the last 1 day
  • If only start_time is provided, returns range between start_time and start_time + 1 day
  • If only end_time is provided, returns range between end_time - 1 day and end_time
  • If both are provided, the rule is end_time - start_time <= 7 days
§end_time: Option<u64>

The end timestamp in milliseconds (optional).

The end of the time range for querying closed positions.

§limit: Option<usize>

The maximum number of records to return (optional).

Limit for data size per page. Valid range: [1, 100]. Default: 50. Bots should use pagination with the cursor field for large result sets.

§cursor: Option<Cow<'a, str>>

The cursor for pagination (optional).

Use the nextPageCursor token from the response to retrieve the next page of results. Bots use this to efficiently paginate through large sets of closed positions.

Implementations§

Source§

impl<'a> ClosedOptionsPositionsRequest<'a>

Source

pub fn new( category: Category, symbol: Option<&'a str>, start_time: Option<u64>, end_time: Option<u64>, limit: Option<usize>, cursor: Option<&'a str>, ) -> Self

Constructs a new ClosedOptionsPositions request with specified parameters.

Allows full customization of the closed options positions query. Bots should use this to specify time ranges, symbols, and pagination parameters.

§Arguments
  • category - The product category (must be Category::Option)
  • symbol - The options symbol name (optional)
  • start_time - The start timestamp in milliseconds (optional)
  • end_time - The end timestamp in milliseconds (optional)
  • limit - The maximum number of records to return (optional, range: 1-100)
  • cursor - The cursor for pagination (optional)
Source

pub fn default() -> ClosedOptionsPositionsRequest<'a>

Creates a default ClosedOptionsPositions request.

Returns a request with category set to Option, no symbol filter, no time range (returns last 1 day by default), limit set to 50, and no cursor. Suitable for testing but should be customized for production analysis.

Source

pub fn validate(&self) -> Result<(), String>

Validates the request parameters according to Bybit API constraints.

Bots should call this method before sending the request to ensure compliance with API limits.

§Returns
  • Ok(()) if validation passes
  • Err(String) with error message if validation fails
Source

pub fn with_symbol(self, symbol: &'a str) -> Self

Sets the symbol filter for the request.

Convenience method for updating the symbol filter.

§Arguments
  • symbol - The options symbol name
Source

pub fn with_time_range(self, start_time: u64, end_time: u64) -> Self

Sets the time range for the request.

Convenience method for updating both start and end times.

§Arguments
  • start_time - The start timestamp in milliseconds
  • end_time - The end timestamp in milliseconds
Source

pub fn with_limit(self, limit: usize) -> Self

Sets the limit for the request.

Convenience method for updating the result limit.

§Arguments
  • limit - The maximum number of records to return (1-100)
Source

pub fn with_cursor(self, cursor: &'a str) -> Self

Sets the cursor for pagination.

Convenience method for updating the pagination cursor.

§Arguments
  • cursor - The cursor string from previous response

Trait Implementations§

Source§

impl<'a> Clone for ClosedOptionsPositionsRequest<'a>

Source§

fn clone(&self) -> ClosedOptionsPositionsRequest<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Default for ClosedOptionsPositionsRequest<'a>

Source§

fn default() -> ClosedOptionsPositionsRequest<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more