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
closeTimein 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: CategoryThe 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_timenorend_timeare provided, returns data from the last 1 day - If only
start_timeis provided, returns range betweenstart_timeandstart_time + 1 day - If only
end_timeis provided, returns range betweenend_time - 1 dayandend_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>
impl<'a> ClosedOptionsPositionsRequest<'a>
Sourcepub fn new(
category: Category,
symbol: Option<&'a str>,
start_time: Option<u64>,
end_time: Option<u64>,
limit: Option<usize>,
cursor: Option<&'a str>,
) -> Self
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 beCategory::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)
Sourcepub fn default() -> ClosedOptionsPositionsRequest<'a>
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.
Sourcepub fn validate(&self) -> Result<(), String>
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 passesErr(String)with error message if validation fails
Sourcepub fn with_symbol(self, symbol: &'a str) -> Self
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
Sourcepub fn with_time_range(self, start_time: u64, end_time: u64) -> Self
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 millisecondsend_time- The end timestamp in milliseconds
Sourcepub fn with_limit(self, limit: usize) -> Self
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)
Sourcepub fn with_cursor(self, cursor: &'a str) -> Self
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>
impl<'a> Clone for ClosedOptionsPositionsRequest<'a>
Source§fn clone(&self) -> ClosedOptionsPositionsRequest<'a>
fn clone(&self) -> ClosedOptionsPositionsRequest<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more