Skip to main content

PositionManager

Struct PositionManager 

Source
pub struct PositionManager {
    pub client: Client,
    pub recv_window: u16,
}

Fields§

§client: Client§recv_window: u16

Implementations§

Source§

impl PositionManager

Source

pub async fn get_info<'b>( &self, req: PositionRequest<'_>, ) -> Result<InfoResponse, BybitError>

Asynchronously retrieves information about a position based on the provided request.

§Arguments
  • req - The position request containing the category, symbol, base coin, settle coin, and limit.
§Returns

A Result containing a vector of PositionInfo if the operation is successful, or an error if it fails.

§Example
use crate::model::{PositionRequest, Category};
use crate::errors::Result;
use crate::api::PositionInfo;
use my_module::PositionManager;

#[tokio::main]
async fn main() -> Result<()> {
    let position_manager = PositionManager::new();
    let request = PositionRequest::new(Category::Linear, Some("symbol"), Some("base_coin"), Some("settle_coin"), Some(10));
    let position_info = position_manager.get_info(request).await?;
    Ok(())
}
Source

pub async fn set_leverage<'b>( &self, req: LeverageRequest<'_>, ) -> Result<LeverageResponse, BybitError>

§Arguments
  • req - The leverage request containing category, symbol, and leverage.
§Returns

A result containing the leverage response.

Source

pub async fn set_margin_mode<'b>( &self, req: ChangeMarginRequest<'_>, ) -> Result<ChangeMarginResponse, BybitError>

Set the margin mode.

§Arguments
  • req - The ChangeMarginRequest containing the necessary information.
§Returns
  • Result - The result of setting the margin mode.
Source

pub async fn set_position_mode<'b>( &self, req: MarginModeRequest<'_>, ) -> Result<MarginModeResponse, BybitError>

Set the position mode.

§Arguments
  • req - The MarginModeRequest containing the necessary information.
§Returns
  • Result - The result of setting the position mode.
Source

pub async fn set_risk_limit<'b>( &self, req: SetRiskLimit<'_>, ) -> Result<SetRiskLimitResponse, BybitError>

Set the risk limit.

§Arguments
  • req - The SetRiskLimitRequest containing the necessary information.
§Returns
  • Result - The result of setting the risk limit.
Source

pub async fn set_trading_stop<'b>( &self, req: TradingStopRequest<'_>, ) -> Result<TradingStopResponse, BybitError>

Set the trading stop.

§Arguments
  • req - The TradingStopRequest containing the necessary information.
§Returns
  • Result - The result of setting the trading stop.
Source

pub async fn set_add_margin<'b>( &self, req: AddMarginRequest<'_>, ) -> Result<AddMarginResponse, BybitError>

Set the auto-add margin mode for a given position.

§Arguments
  • req - The AddMarginRequest containing the necessary information.
§Returns

A result containing the AddMarginResponse.

Source

pub async fn add_or_reduce_margin<'b>( &self, req: AddReduceMarginRequest<'_>, ) -> Result<AddReduceMarginResponse, BybitError>

Set the auto add margin.

§Arguments
  • req - The AddReduceMarginRequest containing the necessary information.
§Returns
  • Result - The result of setting the auto add margin.
Source

pub async fn get_closed_pnl<'b>( &self, req: ClosedPnlRequest<'_>, ) -> Result<ClosedPnlResponse, BybitError>

Source

pub async fn get_closed_options_positions<'b>( &self, req: ClosedOptionsPositionsRequest<'_>, ) -> Result<ClosedOptionsPositionsResult, BybitError>

Get closed options positions.

§Arguments
  • req - The ClosedOptionsPositionsRequest containing the necessary information.
§Returns

A result containing the closed options positions response.

Source

pub async fn confirm_pending_mmr<'b>( &self, req: ConfirmPendingMmrRequest<'_>, ) -> Result<ConfirmPendingMmrResponse, BybitError>

Confirm new risk limit (MMR - Maintenance Margin Rate).

§Arguments
  • req - The ConfirmPendingMmrRequest containing the necessary information.
§Returns

A result containing the confirm pending MMR response.

§Bybit API Reference

This endpoint is only applicable when the user is marked as only reducing positions (see the isReduceOnly field in the Get Position Info interface). After the user actively adjusts the risk level, this interface is called to try to calculate the adjusted risk level. If the call passes (retCode=0), the system will remove the position reduceOnly mark.

Source

pub async fn move_position<'b>( &self, req: MovePositionRequest<'_>, ) -> Result<MovePositionResponse, BybitError>

Moves positions from one user to another.

§Arguments
  • req - The request containing the fromUid, toUid, and list of positions to move.
§Returns

A result containing the response.

Source

pub async fn move_position_history<'b>( &self, req: MoveHistoryRequest<'_>, ) -> Result<MoveHistoryResponse, BybitError>

Retrieves the history of position movements.

§Arguments
  • req - The request containing the parameters for the history of position movements.
§Returns

A result containing the response.

Trait Implementations§

Source§

impl Bybit for PositionManager

Source§

fn new(api_key: Option<String>, secret_key: Option<String>) -> PositionManager

Creates a new instance of the module with default configuration. Read more
Source§

fn new_with_config( config: &Config, api_key: Option<String>, secret_key: Option<String>, ) -> PositionManager

Creates a new instance of the module with custom configuration. Read more
Source§

impl Clone for PositionManager

Source§

fn clone(&self) -> PositionManager

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

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