/*
 * Websocket Subscription Schemas
 *
 * Schema definitions Websocket API subscriptions for Thalex exchange.
 *
 * The version of the OpenAPI document: 1.0.0
 *
 * Generated by: https://openapi-generator.tech
 */

use crate::models;
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Sgsl {
    /// Individually identifies this bot instance. You can use it to cancel this specific one.
    #[serde(rename = "bot_id")]
    pub bot_id: String,
    #[serde(rename = "status")]
    pub status: Status,
    /// The reason why the bot stopped executing.
    #[serde(rename = "stop_reason", skip_serializing_if = "Option::is_none")]
    pub stop_reason: Option<StopReason>,
    /// equal to \"sgsl\"
    #[serde(rename = "strategy")]
    pub strategy: String,
    /// Name of the instrument.
    #[serde(rename = "instrument_name")]
    pub instrument_name: String,
    #[serde(rename = "signal")]
    pub signal: Signal,
    /// Price to compare `signal` price to, to determine necessary adjustments to the portfolio. See [the bot strategies section](#tag/bot_strategies) for more explanation.
    #[serde(rename = "entry_price")]
    pub entry_price: rust_decimal::Decimal,
    /// The target position to maintain in the subaccount if `signal` price is above `entry_price`. See [the bot strategies section](#tag/bot_strategies) for more explanation.
    #[serde(rename = "target_position")]
    pub target_position: rust_decimal::Decimal,
    /// Price to compare `signal` price to, to determine necessary adjustments to the portfolio. See [the bot strategies section](#tag/bot_strategies) for more explanation.
    #[serde(rename = "exit_price")]
    pub exit_price: rust_decimal::Decimal,
    /// The target position to maintain in the subaccount if `signal` price is below `exit_price`. See [the bot strategies section](#tag/bot_strategies) for more explanation.
    #[serde(rename = "exit_position")]
    pub exit_position: rust_decimal::Decimal,
    /// Maximum slippage per trade, expressed as % of the traded instruments mark price.
    #[serde(rename = "max_slippage", skip_serializing_if = "Option::is_none")]
    pub max_slippage: Option<rust_decimal::Decimal>,
    /// Timestamp when the bot stops executing, cancelling its orders and leaving all positions of the subaccount intact.
    #[serde(rename = "end_time")]
    pub end_time: rust_decimal::Decimal,
    /// Timestamp indicating when the bot was created.
    #[serde(rename = "start_time")]
    pub start_time: rust_decimal::Decimal,
    /// Timestamp indicating when the bot stopped working due to specified `stop_reason`.
    #[serde(rename = "stop_time", skip_serializing_if = "Option::is_none")]
    pub stop_time: Option<rust_decimal::Decimal>,
    /// A label that the bot will add to all orders for easy identification.
    #[serde(rename = "label", skip_serializing_if = "Option::is_none")]
    pub label: Option<String>,
    /// Realized P&L made by this bot since the start.
    #[serde(rename = "realized_pnl")]
    pub realized_pnl: rust_decimal::Decimal,
    /// Trade fees by this bot.
    #[serde(rename = "fee")]
    pub fee: rust_decimal::Decimal,
    /// Average entry price of the position (if any).
    #[serde(rename = "average_price", skip_serializing_if = "Option::is_none")]
    pub average_price: Option<rust_decimal::Decimal>,
    /// Position size (if any).
    #[serde(rename = "position_size", skip_serializing_if = "Option::is_none")]
    pub position_size: Option<rust_decimal::Decimal>,
    /// Mark price of the bot instrument at the moment the bot was stopped.
    #[serde(rename = "mark_price_at_stop", skip_serializing_if = "Option::is_none")]
    pub mark_price_at_stop: Option<rust_decimal::Decimal>,
}

impl Sgsl {
    pub fn new(
        bot_id: String,
        status: Status,
        strategy: String,
        instrument_name: String,
        signal: Signal,
        entry_price: rust_decimal::Decimal,
        target_position: rust_decimal::Decimal,
        exit_price: rust_decimal::Decimal,
        exit_position: rust_decimal::Decimal,
        end_time: rust_decimal::Decimal,
        start_time: rust_decimal::Decimal,
        realized_pnl: rust_decimal::Decimal,
        fee: rust_decimal::Decimal,
    ) -> Sgsl {
        Sgsl {
            bot_id,
            status,
            stop_reason: None,
            strategy,
            instrument_name,
            signal,
            entry_price,
            target_position,
            exit_price,
            exit_position,
            max_slippage: None,
            end_time,
            start_time,
            stop_time: None,
            label: None,
            realized_pnl,
            fee,
            average_price: None,
            position_size: None,
            mark_price_at_stop: None,
        }
    }
}
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Status {
    #[serde(rename = "active")]
    Active,
    #[serde(rename = "stopped")]
    Stopped,
}

impl Default for Status {
    fn default() -> Status {
        Self::Active
    }
}
/// The reason why the bot stopped executing.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum StopReason {
    #[serde(rename = "client_cancel")]
    ClientCancel,
    #[serde(rename = "client_bulk_cancel")]
    ClientBulkCancel,
    #[serde(rename = "end_time")]
    EndTime,
    #[serde(rename = "instrument_deactivated")]
    InstrumentDeactivated,
    #[serde(rename = "margin_breach")]
    MarginBreach,
    #[serde(rename = "admin_cancel")]
    AdminCancel,
    #[serde(rename = "conflict")]
    Conflict,
    #[serde(rename = "strategy")]
    Strategy,
    #[serde(rename = "self_trade_prevention")]
    SelfTradePrevention,
}

impl Default for StopReason {
    fn default() -> StopReason {
        Self::ClientCancel
    }
}
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Signal {
    #[serde(rename = "last")]
    Last,
    #[serde(rename = "index")]
    Index,
    #[serde(rename = "mark")]
    Mark,
}

impl Default for Signal {
    fn default() -> Signal {
        Self::Last
    }
}
