/*
* OANDA v20 API
*
* The full OANDA v20 API Specification. This specification defines how to interact with v20 Accounts, Trades, Orders, Pricing and more.
*
* The version of the OpenAPI document: 0.2.1
* Contact: jmicoud02@gmail.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
/// TrailingStopLossOrder : A TrailingStopLossOrder is an order that is linked to an open Trade and created with a price distance. The price distance is used to calculate a trailing stop value for the order that is in the losing direction from the market price at the time of the order's creation. The trailing stop value will follow the market price as it moves in the winning direction, and the order will filled (closing the Trade) by the first price that is equal to or worse than the trailing stop value. A TrailingStopLossOrder cannot be used to open a new Position.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct TrailingStopLossOrder {
/// The Order's identifier, unique within the Order's Account.
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i32>,
/// A date and time value using either RFC3339 or UNIX time representation. The RFC 3339 representation is a string conforming to https://tools.ietf.org/rfc/rfc3339.txt. The Unix representation is a string representing the number of seconds since the Unix Epoch (January 1st, 1970 at UTC). The value is a fractional number, where the fractional part represents a fraction of a second (up to nine decimal places).
#[serde(rename = "createTime", skip_serializing_if = "Option::is_none")]
pub create_time: Option<String>,
#[serde(rename = "state", skip_serializing_if = "Option::is_none")]
pub state: Option<models::OrderState>,
#[serde(rename = "clientExtensions", skip_serializing_if = "Option::is_none")]
pub client_extensions: Option<Box<models::ClientExtensions>>,
/// The type of the Order.
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
pub r#type: Option<Type>,
/// The ID of the Trade to close when the price threshold is breached.
#[serde(rename = "tradeID", skip_serializing_if = "Option::is_none")]
pub trade_id: Option<i32>,
/// The client ID of the Trade to be closed when the price threshold is breached.
#[serde(rename = "clientTradeID", skip_serializing_if = "Option::is_none")]
pub client_trade_id: Option<String>,
#[serde(rename = "timeInForce", skip_serializing_if = "Option::is_none")]
pub time_in_force: Option<models::TradeOrderTimeInForce>,
/// A date and time value using either RFC3339 or UNIX time representation. The RFC 3339 representation is a string conforming to https://tools.ietf.org/rfc/rfc3339.txt. The Unix representation is a string representing the number of seconds since the Unix Epoch (January 1st, 1970 at UTC). The value is a fractional number, where the fractional part represents a fraction of a second (up to nine decimal places).
#[serde(rename = "gtdTime", skip_serializing_if = "Option::is_none")]
pub gtd_time: Option<String>,
#[serde(rename = "triggerCondition", skip_serializing_if = "Option::is_none")]
pub trigger_condition: Option<models::TradeOrderTriggerCondition>,
/// ID of the Transaction that filled this Order (only provided when the Order's state is FILLED)
#[serde(rename = "fillingTransactionID", skip_serializing_if = "Option::is_none")]
pub filling_transaction_id: Option<i32>,
/// A date and time value using either RFC3339 or UNIX time representation. The RFC 3339 representation is a string conforming to https://tools.ietf.org/rfc/rfc3339.txt. The Unix representation is a string representing the number of seconds since the Unix Epoch (January 1st, 1970 at UTC). The value is a fractional number, where the fractional part represents a fraction of a second (up to nine decimal places).
#[serde(rename = "filledTime", skip_serializing_if = "Option::is_none")]
pub filled_time: Option<String>,
/// Trade ID of Trade opened when the Order was filled (only provided when the Order's state is FILLED and a Trade was opened as a result of the fill)
#[serde(rename = "tradeOpenedID", skip_serializing_if = "Option::is_none")]
pub trade_opened_id: Option<i32>,
/// Trade ID of Trade reduced when the Order was filled (only provided when the Order's state is FILLED and a Trade was reduced as a result of the fill)
#[serde(rename = "tradeReducedID", skip_serializing_if = "Option::is_none")]
pub trade_reduced_id: Option<i32>,
/// Trade IDs of Trades closed when the Order was filled (only provided when the Order's state is FILLED and one or more Trades were closed as a result of the fill)
#[serde(rename = "tradeClosedIDs", skip_serializing_if = "Option::is_none")]
pub trade_closed_ids: Option<Vec<i32>>,
/// ID of the Transaction that cancelled the Order (only provided when the Order's state is CANCELLED)
#[serde(rename = "cancellingTransactionID", skip_serializing_if = "Option::is_none")]
pub cancelling_transaction_id: Option<i32>,
/// A date and time value using either RFC3339 or UNIX time representation. The RFC 3339 representation is a string conforming to https://tools.ietf.org/rfc/rfc3339.txt. The Unix representation is a string representing the number of seconds since the Unix Epoch (January 1st, 1970 at UTC). The value is a fractional number, where the fractional part represents a fraction of a second (up to nine decimal places).
#[serde(rename = "cancelledTime", skip_serializing_if = "Option::is_none")]
pub cancelled_time: Option<String>,
/// The ID of the Order that was replaced by this Order (only provided if this Order was created as part of a cancel/replace).
#[serde(rename = "replacesOrderID", skip_serializing_if = "Option::is_none")]
pub replaces_order_id: Option<i32>,
/// The ID of the Order that replaced this Order (only provided if this Order was cancelled as part of a cancel/replace).
#[serde(rename = "replacedByOrderID", skip_serializing_if = "Option::is_none")]
pub replaced_by_order_id: Option<i32>,
/// The price distance (in price units) specified for the TrailingStopLoss Order.
#[serde(rename = "distance", skip_serializing_if = "Option::is_none")]
pub distance: Option<f64>,
/// The trigger price for the Trailing Stop Loss Order. The trailing stop value will trail (follow) the market price by the TSL order's configured \"distance\" as the market price moves in the winning direction. If the market price moves to a level that is equal to or worse than the trailing stop value, the order will be filled and the Trade will be closed.
#[serde(rename = "trailingStopValue", skip_serializing_if = "Option::is_none")]
pub trailing_stop_value: Option<f64>,
}
impl TrailingStopLossOrder {
/// A TrailingStopLossOrder is an order that is linked to an open Trade and created with a price distance. The price distance is used to calculate a trailing stop value for the order that is in the losing direction from the market price at the time of the order's creation. The trailing stop value will follow the market price as it moves in the winning direction, and the order will filled (closing the Trade) by the first price that is equal to or worse than the trailing stop value. A TrailingStopLossOrder cannot be used to open a new Position.
pub fn new() -> TrailingStopLossOrder {
TrailingStopLossOrder {
id: None,
create_time: None,
state: None,
client_extensions: None,
r#type: None,
trade_id: None,
client_trade_id: None,
time_in_force: None,
gtd_time: None,
trigger_condition: None,
filling_transaction_id: None,
filled_time: None,
trade_opened_id: None,
trade_reduced_id: None,
trade_closed_ids: None,
cancelling_transaction_id: None,
cancelled_time: None,
replaces_order_id: None,
replaced_by_order_id: None,
distance: None,
trailing_stop_value: None,
}
}
}
/// The type of the Order.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Type {
#[serde(rename = "TAKE_PROFIT")]
TakeProfit,
#[serde(rename = "STOP_LOSS")]
StopLoss,
#[serde(rename = "TRAILING_STOP_LOSS")]
TrailingStopLoss,
}
impl Default for Type {
fn default() -> Type {
Self::TakeProfit
}
}