17 using Newtonsoft.Json;
30 [JsonProperty(PropertyName =
"trailingAmount")]
36 [JsonProperty(PropertyName =
"trailingAsPercentage")]
65 public TrailingStopOrder(
Symbol symbol, decimal quantity, decimal stopPrice, decimal trailingAmount,
bool trailingAsPercentage,
67 : base(symbol, quantity, stopPrice, time, tag, properties)
87 : this(symbol, quantity, 0, trailingAmount, trailingAsPercentage, time, tag, properties)
106 base.ApplyUpdateOrderRequest(request);
155 public static bool TryUpdateStopPrice(decimal currentMarketPrice, decimal currentStopPrice, decimal trailingAmount,
156 bool trailingAsPercentage,
OrderDirection direction, out decimal updatedStopPrice)
158 updatedStopPrice = 0m;
160 ? currentMarketPrice - currentStopPrice
161 : currentStopPrice - currentMarketPrice;
162 var stopReference = trailingAsPercentage ? currentMarketPrice * trailingAmount : trailingAmount;
164 if (distanceToMarketPrice <= stopReference)
169 updatedStopPrice =
CalculateStopPrice(currentMarketPrice, trailingAmount, trailingAsPercentage, direction);
181 public static decimal
CalculateStopPrice(decimal currentMarketPrice, decimal trailingAmount,
bool trailingAsPercentage,
184 if (trailingAsPercentage)
187 ? currentMarketPrice * (1 + trailingAmount)
188 : currentMarketPrice * (1 - trailingAmount);
192 ? currentMarketPrice + trailingAmount
193 : currentMarketPrice - trailingAmount;