1use std::{
17 fmt::Display,
18 ops::{Deref, DerefMut},
19};
20
21use indexmap::IndexMap;
22use nautilus_core::{UUID4, UnixNanos, correctness::FAILED};
23use rust_decimal::Decimal;
24use serde::{Deserialize, Serialize};
25use ustr::Ustr;
26
27use super::{Order, OrderAny, OrderCore, OrderError};
28use crate::{
29 enums::{
30 ContingencyType, LiquiditySide, OrderSide, OrderStatus, OrderType, PositionSide,
31 TimeInForce, TrailingOffsetType, TriggerType,
32 },
33 events::{OrderEventAny, OrderInitialized, OrderUpdated},
34 identifiers::{
35 AccountId, ClientOrderId, ExecAlgorithmId, InstrumentId, OrderListId, PositionId,
36 StrategyId, Symbol, TradeId, TraderId, Venue, VenueOrderId,
37 },
38 orders::{check_display_qty, check_time_in_force},
39 types::{Currency, Money, Price, Quantity, quantity::check_positive_quantity},
40};
41
42#[derive(Clone, Debug, Serialize, Deserialize)]
43#[cfg_attr(
44 feature = "python",
45 pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.model")
46)]
47pub struct TrailingStopLimitOrder {
48 core: OrderCore,
49 pub activation_price: Option<Price>,
50 pub price: Price,
51 pub trigger_price: Price,
52 pub trigger_type: TriggerType,
53 pub limit_offset: Decimal,
54 pub trailing_offset: Decimal,
55 pub trailing_offset_type: TrailingOffsetType,
56 pub expire_time: Option<UnixNanos>,
57 pub is_post_only: bool,
58 pub display_qty: Option<Quantity>,
59 pub trigger_instrument_id: Option<InstrumentId>,
60 pub is_activated: bool,
61 pub is_triggered: bool,
62 pub ts_triggered: Option<UnixNanos>,
63}
64
65impl TrailingStopLimitOrder {
66 #[allow(clippy::too_many_arguments)]
75 pub fn new_checked(
76 trader_id: TraderId,
77 strategy_id: StrategyId,
78 instrument_id: InstrumentId,
79 client_order_id: ClientOrderId,
80 order_side: OrderSide,
81 quantity: Quantity,
82 price: Price,
83 trigger_price: Price,
84 trigger_type: TriggerType,
85 limit_offset: Decimal,
86 trailing_offset: Decimal,
87 trailing_offset_type: TrailingOffsetType,
88 time_in_force: TimeInForce,
89 expire_time: Option<UnixNanos>,
90 post_only: bool,
91 reduce_only: bool,
92 quote_quantity: bool,
93 display_qty: Option<Quantity>,
94 emulation_trigger: Option<TriggerType>,
95 trigger_instrument_id: Option<InstrumentId>,
96 contingency_type: Option<ContingencyType>,
97 order_list_id: Option<OrderListId>,
98 linked_order_ids: Option<Vec<ClientOrderId>>,
99 parent_order_id: Option<ClientOrderId>,
100 exec_algorithm_id: Option<ExecAlgorithmId>,
101 exec_algorithm_params: Option<IndexMap<Ustr, Ustr>>,
102 exec_spawn_id: Option<ClientOrderId>,
103 tags: Option<Vec<Ustr>>,
104 init_id: UUID4,
105 ts_init: UnixNanos,
106 ) -> anyhow::Result<Self> {
107 check_positive_quantity(quantity, stringify!(quantity))?;
108 check_display_qty(display_qty, quantity)?;
109 check_time_in_force(time_in_force, expire_time)?;
110
111 let init_order = OrderInitialized::new(
112 trader_id,
113 strategy_id,
114 instrument_id,
115 client_order_id,
116 order_side,
117 OrderType::TrailingStopLimit,
118 quantity,
119 time_in_force,
120 post_only,
121 reduce_only,
122 quote_quantity,
123 false,
124 init_id,
125 ts_init,
126 ts_init,
127 Some(price),
128 Some(trigger_price),
129 Some(trigger_type),
130 Some(limit_offset),
131 Some(trailing_offset),
132 Some(trailing_offset_type),
133 expire_time,
134 display_qty,
135 emulation_trigger,
136 trigger_instrument_id,
137 contingency_type,
138 order_list_id,
139 linked_order_ids,
140 parent_order_id,
141 exec_algorithm_id,
142 exec_algorithm_params,
143 exec_spawn_id,
144 tags,
145 );
146
147 Ok(Self {
148 core: OrderCore::new(init_order),
149 activation_price: None,
150 price,
151 trigger_price,
152 trigger_type,
153 limit_offset,
154 trailing_offset,
155 trailing_offset_type,
156 expire_time,
157 is_post_only: post_only,
158 display_qty,
159 trigger_instrument_id,
160 is_activated: false,
161 is_triggered: false,
162 ts_triggered: None,
163 })
164 }
165
166 #[allow(clippy::too_many_arguments)]
172 pub fn new(
173 trader_id: TraderId,
174 strategy_id: StrategyId,
175 instrument_id: InstrumentId,
176 client_order_id: ClientOrderId,
177 order_side: OrderSide,
178 quantity: Quantity,
179 price: Price,
180 trigger_price: Price,
181 trigger_type: TriggerType,
182 limit_offset: Decimal,
183 trailing_offset: Decimal,
184 trailing_offset_type: TrailingOffsetType,
185 time_in_force: TimeInForce,
186 expire_time: Option<UnixNanos>,
187 post_only: bool,
188 reduce_only: bool,
189 quote_quantity: bool,
190 display_qty: Option<Quantity>,
191 emulation_trigger: Option<TriggerType>,
192 trigger_instrument_id: Option<InstrumentId>,
193 contingency_type: Option<ContingencyType>,
194 order_list_id: Option<OrderListId>,
195 linked_order_ids: Option<Vec<ClientOrderId>>,
196 parent_order_id: Option<ClientOrderId>,
197 exec_algorithm_id: Option<ExecAlgorithmId>,
198 exec_algorithm_params: Option<IndexMap<Ustr, Ustr>>,
199 exec_spawn_id: Option<ClientOrderId>,
200 tags: Option<Vec<Ustr>>,
201 init_id: UUID4,
202 ts_init: UnixNanos,
203 ) -> Self {
204 Self::new_checked(
205 trader_id,
206 strategy_id,
207 instrument_id,
208 client_order_id,
209 order_side,
210 quantity,
211 price,
212 trigger_price,
213 trigger_type,
214 limit_offset,
215 trailing_offset,
216 trailing_offset_type,
217 time_in_force,
218 expire_time,
219 post_only,
220 reduce_only,
221 quote_quantity,
222 display_qty,
223 emulation_trigger,
224 trigger_instrument_id,
225 contingency_type,
226 order_list_id,
227 linked_order_ids,
228 parent_order_id,
229 exec_algorithm_id,
230 exec_algorithm_params,
231 exec_spawn_id,
232 tags,
233 init_id,
234 ts_init,
235 )
236 .expect(FAILED)
237 }
238
239 pub fn has_activation_price(&self) -> bool {
240 self.activation_price.is_some()
241 }
242
243 pub fn set_activated(&mut self) {
244 debug_assert!(!self.is_activated, "double activation");
245 self.is_activated = true;
246 }
247}
248
249impl Deref for TrailingStopLimitOrder {
250 type Target = OrderCore;
251 fn deref(&self) -> &Self::Target {
252 &self.core
253 }
254}
255
256impl DerefMut for TrailingStopLimitOrder {
257 fn deref_mut(&mut self) -> &mut Self::Target {
258 &mut self.core
259 }
260}
261
262impl Order for TrailingStopLimitOrder {
263 fn activation_price(&self) -> Option<Price> {
264 self.activation_price
265 }
266 fn into_any(self) -> OrderAny {
267 OrderAny::TrailingStopLimit(self)
268 }
269
270 fn status(&self) -> OrderStatus {
271 self.status
272 }
273
274 fn trader_id(&self) -> TraderId {
275 self.trader_id
276 }
277
278 fn strategy_id(&self) -> StrategyId {
279 self.strategy_id
280 }
281
282 fn instrument_id(&self) -> InstrumentId {
283 self.instrument_id
284 }
285
286 fn symbol(&self) -> Symbol {
287 self.instrument_id.symbol
288 }
289
290 fn venue(&self) -> Venue {
291 self.instrument_id.venue
292 }
293
294 fn client_order_id(&self) -> ClientOrderId {
295 self.client_order_id
296 }
297
298 fn venue_order_id(&self) -> Option<VenueOrderId> {
299 self.venue_order_id
300 }
301
302 fn position_id(&self) -> Option<PositionId> {
303 self.position_id
304 }
305
306 fn account_id(&self) -> Option<AccountId> {
307 self.account_id
308 }
309
310 fn last_trade_id(&self) -> Option<TradeId> {
311 self.last_trade_id
312 }
313
314 fn order_side(&self) -> OrderSide {
315 self.side
316 }
317
318 fn order_type(&self) -> OrderType {
319 self.order_type
320 }
321
322 fn quantity(&self) -> Quantity {
323 self.quantity
324 }
325
326 fn time_in_force(&self) -> TimeInForce {
327 self.time_in_force
328 }
329
330 fn expire_time(&self) -> Option<UnixNanos> {
331 self.expire_time
332 }
333
334 fn price(&self) -> Option<Price> {
335 Some(self.price)
336 }
337
338 fn trigger_price(&self) -> Option<Price> {
339 Some(self.trigger_price)
340 }
341
342 fn trigger_type(&self) -> Option<TriggerType> {
343 Some(self.trigger_type)
344 }
345
346 fn liquidity_side(&self) -> Option<LiquiditySide> {
347 self.liquidity_side
348 }
349
350 fn is_post_only(&self) -> bool {
351 self.is_post_only
352 }
353
354 fn is_reduce_only(&self) -> bool {
355 self.is_reduce_only
356 }
357
358 fn is_quote_quantity(&self) -> bool {
359 self.is_quote_quantity
360 }
361
362 fn has_price(&self) -> bool {
363 true
364 }
365
366 fn display_qty(&self) -> Option<Quantity> {
367 self.display_qty
368 }
369
370 fn limit_offset(&self) -> Option<Decimal> {
371 Some(self.limit_offset)
372 }
373
374 fn trailing_offset(&self) -> Option<Decimal> {
375 Some(self.trailing_offset)
376 }
377
378 fn trailing_offset_type(&self) -> Option<TrailingOffsetType> {
379 Some(self.trailing_offset_type)
380 }
381
382 fn emulation_trigger(&self) -> Option<TriggerType> {
383 self.emulation_trigger
384 }
385
386 fn trigger_instrument_id(&self) -> Option<InstrumentId> {
387 self.trigger_instrument_id
388 }
389
390 fn contingency_type(&self) -> Option<ContingencyType> {
391 self.contingency_type
392 }
393
394 fn order_list_id(&self) -> Option<OrderListId> {
395 self.order_list_id
396 }
397
398 fn linked_order_ids(&self) -> Option<&[ClientOrderId]> {
399 self.linked_order_ids.as_deref()
400 }
401
402 fn parent_order_id(&self) -> Option<ClientOrderId> {
403 self.parent_order_id
404 }
405
406 fn exec_algorithm_id(&self) -> Option<ExecAlgorithmId> {
407 self.exec_algorithm_id
408 }
409
410 fn exec_algorithm_params(&self) -> Option<&IndexMap<Ustr, Ustr>> {
411 self.exec_algorithm_params.as_ref()
412 }
413
414 fn exec_spawn_id(&self) -> Option<ClientOrderId> {
415 self.exec_spawn_id
416 }
417
418 fn tags(&self) -> Option<&[Ustr]> {
419 self.tags.as_deref()
420 }
421
422 fn filled_qty(&self) -> Quantity {
423 self.filled_qty
424 }
425
426 fn leaves_qty(&self) -> Quantity {
427 self.leaves_qty
428 }
429
430 fn avg_px(&self) -> Option<f64> {
431 self.avg_px
432 }
433
434 fn slippage(&self) -> Option<f64> {
435 self.slippage
436 }
437
438 fn init_id(&self) -> UUID4 {
439 self.init_id
440 }
441
442 fn ts_init(&self) -> UnixNanos {
443 self.ts_init
444 }
445
446 fn ts_submitted(&self) -> Option<UnixNanos> {
447 self.ts_submitted
448 }
449
450 fn ts_accepted(&self) -> Option<UnixNanos> {
451 self.ts_accepted
452 }
453
454 fn ts_closed(&self) -> Option<UnixNanos> {
455 self.ts_closed
456 }
457
458 fn ts_last(&self) -> UnixNanos {
459 self.ts_last
460 }
461
462 fn events(&self) -> Vec<&OrderEventAny> {
463 self.events.iter().collect()
464 }
465
466 fn venue_order_ids(&self) -> Vec<&VenueOrderId> {
467 self.venue_order_ids.iter().collect()
468 }
469
470 fn trade_ids(&self) -> Vec<&TradeId> {
471 self.trade_ids.iter().collect()
472 }
473
474 fn commissions(&self) -> &IndexMap<Currency, Money> {
475 &self.commissions
476 }
477
478 fn apply(&mut self, event: OrderEventAny) -> Result<(), OrderError> {
479 if let OrderEventAny::Updated(ref event) = event {
480 self.update(event);
481 }
482 let is_order_filled = matches!(event, OrderEventAny::Filled(_));
483
484 self.core.apply(event)?;
485
486 if is_order_filled {
487 self.core.set_slippage(self.price);
488 }
489
490 Ok(())
491 }
492
493 fn update(&mut self, event: &OrderUpdated) {
494 if let Some(price) = event.price {
495 self.price = price;
496 }
497 if let Some(trigger_price) = event.trigger_price {
498 self.trigger_price = trigger_price;
499 }
500 self.quantity = event.quantity;
501 self.leaves_qty = self.quantity - self.filled_qty;
502 }
503
504 fn is_triggered(&self) -> Option<bool> {
505 Some(self.is_triggered)
506 }
507
508 fn set_position_id(&mut self, position_id: Option<PositionId>) {
509 self.position_id = position_id;
510 }
511
512 fn set_quantity(&mut self, quantity: Quantity) {
513 self.quantity = quantity;
514 }
515
516 fn set_leaves_qty(&mut self, leaves_qty: Quantity) {
517 self.leaves_qty = leaves_qty;
518 }
519
520 fn set_emulation_trigger(&mut self, emulation_trigger: Option<TriggerType>) {
521 self.emulation_trigger = emulation_trigger;
522 }
523
524 fn set_is_quote_quantity(&mut self, is_quote_quantity: bool) {
525 self.is_quote_quantity = is_quote_quantity;
526 }
527
528 fn set_liquidity_side(&mut self, liquidity_side: LiquiditySide) {
529 self.liquidity_side = Some(liquidity_side)
530 }
531
532 fn would_reduce_only(&self, side: PositionSide, position_qty: Quantity) -> bool {
533 self.core.would_reduce_only(side, position_qty)
534 }
535
536 fn previous_status(&self) -> Option<OrderStatus> {
537 self.core.previous_status
538 }
539}
540
541impl Display for TrailingStopLimitOrder {
542 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
543 write!(
544 f,
545 "TrailingStopLimitOrder({} {} {} {} {}, status={}, client_order_id={}, venue_order_id={}, position_id={}, exec_algorithm_id={}, exec_spawn_id={}, tags={:?}, activation_price={:?}, is_activated={})",
546 self.side,
547 self.quantity.to_formatted_string(),
548 self.instrument_id,
549 self.order_type,
550 self.time_in_force,
551 self.status,
552 self.client_order_id,
553 self.venue_order_id
554 .map_or_else(|| "None".to_string(), |id| format!("{id}")),
555 self.position_id
556 .map_or_else(|| "None".to_string(), |id| format!("{id}")),
557 self.exec_algorithm_id
558 .map_or_else(|| "None".to_string(), |id| format!("{id}")),
559 self.exec_spawn_id
560 .map_or_else(|| "None".to_string(), |id| format!("{id}")),
561 self.tags,
562 self.activation_price,
563 self.is_activated
564 )
565 }
566}
567
568impl From<OrderInitialized> for TrailingStopLimitOrder {
569 fn from(event: OrderInitialized) -> Self {
570 Self::new(
571 event.trader_id,
572 event.strategy_id,
573 event.instrument_id,
574 event.client_order_id,
575 event.order_side,
576 event.quantity,
577 event
578 .price
579 .expect("Error initializing order: price is None"),
580 event
581 .trigger_price
582 .expect("Error initializing order: trigger_price is None"),
583 event
584 .trigger_type
585 .expect("Error initializing order: trigger_type is None"),
586 event.limit_offset.unwrap(),
587 event.trailing_offset.unwrap(),
588 event.trailing_offset_type.unwrap(),
589 event.time_in_force,
590 event.expire_time,
591 event.post_only,
592 event.reduce_only,
593 event.quote_quantity,
594 event.display_qty,
595 event.emulation_trigger,
596 event.trigger_instrument_id,
597 event.contingency_type,
598 event.order_list_id,
599 event.linked_order_ids,
600 event.parent_order_id,
601 event.exec_algorithm_id,
602 event.exec_algorithm_params,
603 event.exec_spawn_id,
604 event.tags,
605 event.event_id,
606 event.ts_event,
607 )
608 }
609}
610
611#[cfg(test)]
615mod tests {
616 use rstest::rstest;
617 use rust_decimal_macros::dec;
618
619 use super::*;
620 use crate::{
621 enums::{TimeInForce, TrailingOffsetType, TriggerType},
622 events::order::initialized::OrderInitializedBuilder,
623 identifiers::InstrumentId,
624 instruments::{CurrencyPair, stubs::*},
625 orders::{OrderTestBuilder, stubs::TestOrderStubs},
626 types::{Price, Quantity},
627 };
628
629 #[rstest]
630 fn test_initialize(_audusd_sim: CurrencyPair) {
631 let order = OrderTestBuilder::new(OrderType::TrailingStopLimit)
633 .instrument_id(_audusd_sim.id)
634 .side(OrderSide::Buy)
635 .price(Price::from("0.67500"))
636 .limit_offset(dec!(5))
637 .trigger_price(Price::from("0.68000"))
638 .trailing_offset(dec!(10))
639 .quantity(Quantity::from(1))
640 .build();
641
642 assert_eq!(order.trigger_price(), Some(Price::from("0.68000")));
643 assert_eq!(order.price(), Some(Price::from("0.67500")));
644 assert_eq!(order.time_in_force(), TimeInForce::Gtc);
645 assert_eq!(order.is_triggered(), Some(false));
646 assert_eq!(order.filled_qty(), Quantity::from(0));
647 assert_eq!(order.leaves_qty(), Quantity::from(1));
648 assert_eq!(order.display_qty(), None);
649 assert_eq!(order.trigger_instrument_id(), None);
650 assert_eq!(order.order_list_id(), None);
651 }
652
653 #[rstest]
654 fn test_display(_audusd_sim: CurrencyPair) {
655 let order = OrderTestBuilder::new(OrderType::TrailingStopLimit)
656 .instrument_id(_audusd_sim.id)
657 .side(OrderSide::Buy)
658 .price(Price::from("0.67500"))
659 .trigger_price(Price::from("0.68000"))
660 .trigger_type(TriggerType::LastPrice)
661 .limit_offset(dec!(5))
662 .trailing_offset(dec!(10))
663 .trailing_offset_type(TrailingOffsetType::Price)
664 .quantity(Quantity::from(1))
665 .build();
666
667 assert_eq!(
668 order.to_string(),
669 "TrailingStopLimitOrder(BUY 1 AUD/USD.SIM TRAILING_STOP_LIMIT GTC, status=INITIALIZED, client_order_id=O-19700101-000000-001-001-1, venue_order_id=None, position_id=None, exec_algorithm_id=None, exec_spawn_id=None, tags=None, activation_price=None, is_activated=false)"
670 );
671 }
672
673 #[rstest]
674 #[should_panic(expected = "Condition failed: `display_qty` may not exceed `quantity`")]
675 fn test_display_qty_gt_quantity_err(audusd_sim: CurrencyPair) {
676 OrderTestBuilder::new(OrderType::TrailingStopLimit)
677 .instrument_id(audusd_sim.id)
678 .side(OrderSide::Buy)
679 .price(Price::from("0.67500"))
680 .trigger_price(Price::from("0.68000"))
681 .trigger_type(TriggerType::LastPrice)
682 .limit_offset(dec!(5))
683 .trailing_offset(dec!(10))
684 .trailing_offset_type(TrailingOffsetType::Price)
685 .quantity(Quantity::from(1))
686 .display_qty(Quantity::from(2))
687 .build();
688 }
689
690 #[rstest]
691 #[should_panic(
692 expected = "Condition failed: invalid `Quantity` for 'quantity' not positive, was 0"
693 )]
694 fn test_quantity_zero_err(audusd_sim: CurrencyPair) {
695 OrderTestBuilder::new(OrderType::TrailingStopLimit)
696 .instrument_id(audusd_sim.id)
697 .side(OrderSide::Buy)
698 .price(Price::from("0.67500"))
699 .trigger_price(Price::from("0.68000"))
700 .trigger_type(TriggerType::LastPrice)
701 .limit_offset(dec!(5))
702 .trailing_offset(dec!(10))
703 .trailing_offset_type(TrailingOffsetType::Price)
704 .quantity(Quantity::from(0))
705 .build();
706 }
707
708 #[rstest]
709 #[should_panic(expected = "Condition failed: `expire_time` is required for `GTD` order")]
710 fn test_gtd_without_expire_err(audusd_sim: CurrencyPair) {
711 OrderTestBuilder::new(OrderType::TrailingStopLimit)
712 .instrument_id(audusd_sim.id)
713 .side(OrderSide::Buy)
714 .price(Price::from("0.67500"))
715 .trigger_price(Price::from("0.68000"))
716 .trigger_type(TriggerType::LastPrice)
717 .limit_offset(dec!(5))
718 .trailing_offset(dec!(10))
719 .trailing_offset_type(TrailingOffsetType::Price)
720 .time_in_force(TimeInForce::Gtd)
721 .quantity(Quantity::from(1))
722 .build();
723 }
724
725 #[test]
726 fn test_trailing_stop_limit_order_update() {
727 let order = OrderTestBuilder::new(OrderType::TrailingStopLimit)
728 .instrument_id(InstrumentId::from("BTC-USDT.BINANCE"))
729 .quantity(Quantity::from(10))
730 .price(Price::new(100.0, 2))
731 .trigger_price(Price::new(95.0, 2))
732 .limit_offset(dec!(2.0))
733 .trailing_offset(dec!(1.0))
734 .trailing_offset_type(TrailingOffsetType::Price)
735 .build();
736
737 let mut accepted_order = TestOrderStubs::make_accepted_order(&order);
738
739 let updated_trigger_price = Price::new(90.0, 2);
740 let updated_quantity = Quantity::from(5);
741
742 let event = OrderUpdated {
743 client_order_id: accepted_order.client_order_id(),
744 strategy_id: accepted_order.strategy_id(),
745 trigger_price: Some(updated_trigger_price),
746 quantity: updated_quantity,
747 ..Default::default()
748 };
749
750 accepted_order.apply(OrderEventAny::Updated(event)).unwrap();
751
752 assert_eq!(accepted_order.quantity(), updated_quantity);
753 assert_eq!(accepted_order.trigger_price(), Some(updated_trigger_price));
754 }
755
756 #[test]
757 fn test_trailing_stop_limit_order_trigger_instrument_id() {
758 let trigger_instrument_id = InstrumentId::from("ETH-USDT.BINANCE");
759 let order = OrderTestBuilder::new(OrderType::TrailingStopLimit)
760 .instrument_id(InstrumentId::from("BTC-USDT.BINANCE"))
761 .quantity(Quantity::from(10))
762 .price(Price::new(100.0, 2))
763 .trigger_price(Price::new(95.0, 2))
764 .limit_offset(dec!(2.0))
765 .trailing_offset(dec!(1.0))
766 .trailing_offset_type(TrailingOffsetType::Price)
767 .trigger_instrument_id(trigger_instrument_id)
768 .build();
769
770 assert_eq!(order.trigger_instrument_id(), Some(trigger_instrument_id));
771 }
772
773 #[test]
774 fn test_trailing_stop_limit_order_from_order_initialized() {
775 let order_initialized = OrderInitializedBuilder::default()
776 .order_type(OrderType::TrailingStopLimit)
777 .price(Some(Price::new(100.0, 2)))
778 .trigger_price(Some(Price::new(95.0, 2)))
779 .trigger_type(Some(TriggerType::Default))
780 .limit_offset(Some(dec!(2.0)))
781 .trailing_offset(Some(dec!(1.0)))
782 .trailing_offset_type(Some(TrailingOffsetType::Price))
783 .build()
784 .unwrap();
785
786 let order: TrailingStopLimitOrder = order_initialized.clone().into();
787
788 assert_eq!(order.trader_id(), order_initialized.trader_id);
789 assert_eq!(order.strategy_id(), order_initialized.strategy_id);
790 assert_eq!(order.instrument_id(), order_initialized.instrument_id);
791 assert_eq!(order.client_order_id(), order_initialized.client_order_id);
792 assert_eq!(order.order_side(), order_initialized.order_side);
793 assert_eq!(order.quantity(), order_initialized.quantity);
794 assert_eq!(order.price, order_initialized.price.unwrap());
795 assert_eq!(
796 order.trigger_price,
797 order_initialized.trigger_price.unwrap()
798 );
799 assert_eq!(order.trigger_type, order_initialized.trigger_type.unwrap());
800 assert_eq!(order.limit_offset, order_initialized.limit_offset.unwrap());
801 assert_eq!(
802 order.trailing_offset,
803 order_initialized.trailing_offset.unwrap()
804 );
805 assert_eq!(
806 order.trailing_offset_type,
807 order_initialized.trailing_offset_type.unwrap()
808 );
809 assert_eq!(order.time_in_force(), order_initialized.time_in_force);
810 assert_eq!(order.expire_time(), order_initialized.expire_time);
811 }
812}