bybit/models/side.rs
1use crate::prelude::*;
2
3/// Represents the side of an order in trading, either buying or selling.
4///
5/// In financial markets, the "side" of an order indicates whether the trader is
6/// purchasing (Buy) or selling (Sell) an asset. For perpetual futures on Bybit,
7/// this determines whether the trader is opening a long position (Buy) or a short
8/// position (Sell). When writing trading bots, the side is critical for position
9/// management, as it affects margin requirements and exposure to price movements.
10/// For example, a Buy order in a rising market aims to profit from price increases,
11/// while a Sell order in a falling market aims to profit from price declines.
12/// Incorrectly setting the side can lead to unintended positions, so bots must
13/// validate this field against their strategy.
14#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
15pub enum Side {
16 /// Represents a buy order, initiating a long position or closing a short position.
17 #[default]
18 Buy,
19
20 /// Represents a sell order, initiating a short position or closing a long position.
21 Sell,
22}
23
24impl Side {
25 /// Converts the `Side` enum to its string representation.
26 ///
27 /// This method is used to serialize the `Side` enum into a string format
28 /// compatible with Bybit's API, which expects "Buy" or "Sell". Bots should use
29 /// this method when constructing API requests to ensure correct formatting.
30 pub fn as_str(&self) -> &str {
31 match self {
32 Side::Buy => "Buy",
33 Side::Sell => "Sell",
34 }
35 }
36}