/*
 * 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 Trade {
    #[serde(rename = "trade_type", skip_serializing_if = "Option::is_none")]
    pub trade_type: Option<models::TradeTypeEnum>,
    #[serde(rename = "trade_id", skip_serializing_if = "Option::is_none")]
    pub trade_id: Option<String>,
    #[serde(rename = "order_id", skip_serializing_if = "Option::is_none")]
    pub order_id: Option<String>,
    #[serde(rename = "instrument_name", skip_serializing_if = "Option::is_none")]
    pub instrument_name: Option<String>,
    #[serde(rename = "direction", skip_serializing_if = "Option::is_none")]
    pub direction: Option<models::DirectionEnum>,
    /// Trade price.
    #[serde(rename = "price", skip_serializing_if = "Option::is_none")]
    pub price: Option<rust_decimal::Decimal>,
    /// Traded amount.
    #[serde(rename = "amount", skip_serializing_if = "Option::is_none")]
    pub amount: Option<rust_decimal::Decimal>,
    /// User label.
    #[serde(rename = "label", skip_serializing_if = "Option::is_none")]
    pub label: Option<String>,
    /// Time of trade (Unix timestamp).
    #[serde(rename = "time", skip_serializing_if = "Option::is_none")]
    pub time: Option<rust_decimal::Decimal>,
    /// Position in this instrument right after the trade.
    #[serde(rename = "position_after", skip_serializing_if = "Option::is_none")]
    pub position_after: Option<rust_decimal::Decimal>,
    /// Session realised P&L for this instrument right after the trade.
    #[serde(
        rename = "session_realised_after",
        skip_serializing_if = "Option::is_none"
    )]
    pub session_realised_after: Option<rust_decimal::Decimal>,
    /// If trade closed a position, the positional P&L that was realised.
    #[serde(rename = "position_pnl", skip_serializing_if = "Option::is_none")]
    pub position_pnl: Option<rust_decimal::Decimal>,
    /// If trade closed a position in a perpetual, the funding P&L that was realised.
    #[serde(
        rename = "perpetual_funding_pnl",
        skip_serializing_if = "Option::is_none"
    )]
    pub perpetual_funding_pnl: Option<rust_decimal::Decimal>,
    /// The fee paid for this trade.  The fee for a trade is calculated as `fee_basis * fee_rate * amount`, and is then subject to clamping to minimum and maximum fee. Depending on the instrument, `fee_basis` can be different (e.g. it can be equal to the underlying index, trade price or combo mark price). Please refer to trading information pages for more details.
    #[serde(rename = "fee", skip_serializing_if = "Option::is_none")]
    pub fee: Option<rust_decimal::Decimal>,
    /// The relevant index at time of trade.
    #[serde(rename = "index", skip_serializing_if = "Option::is_none")]
    pub index: Option<rust_decimal::Decimal>,
    /// The fee rate applied to calculate the fee.
    #[serde(rename = "fee_rate", skip_serializing_if = "Option::is_none")]
    pub fee_rate: Option<rust_decimal::Decimal>,
    /// The fee basis on which the fee is calculated.
    #[serde(rename = "fee_basis", skip_serializing_if = "Option::is_none")]
    pub fee_basis: Option<rust_decimal::Decimal>,
    /// The perpetual funding mark as applied to the trade (see `Ticker`).
    #[serde(rename = "funding_mark", skip_serializing_if = "Option::is_none")]
    pub funding_mark: Option<rust_decimal::Decimal>,
    /// Fee paid in case of liquidation.
    #[serde(rename = "liquidation_fee", skip_serializing_if = "Option::is_none")]
    pub liquidation_fee: Option<rust_decimal::Decimal>,
    /// Client order reference as set in related order.
    #[serde(rename = "client_order_id", skip_serializing_if = "Option::is_none")]
    pub client_order_id: Option<rust_decimal::Decimal>,
    #[serde(rename = "maker_taker", skip_serializing_if = "Option::is_none")]
    pub maker_taker: Option<models::MakerTakerEnum>,
    /// If the trade was made by a bot, the ID of that bot. Otherwise omitted.
    #[serde(rename = "bot_id", skip_serializing_if = "Option::is_none")]
    pub bot_id: Option<String>,
    /// Index of a leg on which the trade happened for combination orders. Zero for single-leg orders.  For combination orders the direction of the trade is defined by the direction of the order and the sign of the leg quantity.
    #[serde(rename = "leg_index", skip_serializing_if = "Option::is_none")]
    pub leg_index: Option<rust_decimal::Decimal>,
}

impl Trade {
    pub fn new() -> Trade {
        Trade {
            trade_type: None,
            trade_id: None,
            order_id: None,
            instrument_name: None,
            direction: None,
            price: None,
            amount: None,
            label: None,
            time: None,
            position_after: None,
            session_realised_after: None,
            position_pnl: None,
            perpetual_funding_pnl: None,
            fee: None,
            index: None,
            fee_rate: None,
            fee_basis: None,
            funding_mark: None,
            liquidation_fee: None,
            client_order_id: None,
            maker_taker: None,
            bot_id: None,
            leg_index: None,
        }
    }
}
