ibapi 5.3.0

An unofficial Rust client for the Interactive Brokers TWS API: market data, orders, and account data, with async (Tokio) and blocking clients for TWS and IB Gateway.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
//! Builder structs for IB algorithmic order strategies.
//!
//! Type-safe builders for every IBKR-documented algo strategy: VWAP, TWAP,
//! Percentage of Volume (and its Price/Size/Time variants), Arrival Price,
//! Adaptive, Close Price, Dark Ice, Accumulate/Distribute (AD and AccuDistr),
//! Balance Impact Risk, and Minimise Impact.

use super::types::ValidationError;
use crate::contracts::TagValue;
use crate::ToField;

/// Minimum allowed participation rate (10%).
pub const MIN_PCT_VOL: f64 = 0.1;
/// Maximum allowed participation rate (50%).
pub const MAX_PCT_VOL: f64 = 0.5;

/// Validate percentage is within IB's allowed range.
fn validate_pct_vol(field: &'static str, value: f64) -> Result<(), ValidationError> {
    if !(MIN_PCT_VOL..=MAX_PCT_VOL).contains(&value) {
        Err(ValidationError::InvalidPercentage {
            field,
            value,
            min: MIN_PCT_VOL,
            max: MAX_PCT_VOL,
        })
    } else {
        Ok(())
    }
}

/// Append `tag`/`value` to `params` when `value` is set.
fn push_param_if_some(params: &mut Vec<TagValue>, tag: &str, value: Option<String>) {
    if let Some(value) = value {
        params.push(TagValue { tag: tag.to_string(), value });
    }
}

/// Validate `value` against the PctVol range, then append it as `tag` when set.
fn push_pct_vol_if_some(params: &mut Vec<TagValue>, field: &'static str, tag: &str, value: Option<f64>) -> Result<(), ValidationError> {
    if let Some(v) = value {
        validate_pct_vol(field, v)?;
    }
    push_param_if_some(params, tag, value.map(|v| v.to_string()));
    Ok(())
}

/// Build params for a "windowed PctVol" strategy: a base/end participation
/// rate plus optional active-window times. Shared by `PctVolSizeBuilder`
/// (`"PctVolSz"`) and `PctVolTimeBuilder` (`"PctVolTm"`), which differ only
/// in which dimension drives the rate ramp - the on-wire encoding is the
/// same shape.
fn build_windowed_pct_vol(
    strategy: &'static str,
    start_pct_vol: Option<f64>,
    end_pct_vol: Option<f64>,
    start_time: Option<String>,
    end_time: Option<String>,
    no_take_liq: Option<bool>,
) -> Result<AlgoParams, ValidationError> {
    let mut params = Vec::new();

    push_pct_vol_if_some(&mut params, "start_pct_vol", "startPctVol", start_pct_vol)?;
    push_pct_vol_if_some(&mut params, "end_pct_vol", "endPctVol", end_pct_vol)?;
    push_param_if_some(&mut params, "startTime", start_time);
    push_param_if_some(&mut params, "endTime", end_time);
    push_param_if_some(&mut params, "noTakeLiq", no_take_liq.map(|v| v.to_field()));

    Ok(AlgoParams {
        strategy: strategy.to_string(),
        params,
    })
}

/// Parameters for an algorithmic order strategy.
#[derive(Debug, Clone, Default)]
pub struct AlgoParams {
    /// The algorithm strategy name (e.g., "Vwap", "Twap")
    pub strategy: String,
    /// The algorithm parameters as tag-value pairs
    pub params: Vec<TagValue>,
}

impl From<String> for AlgoParams {
    fn from(strategy: String) -> Self {
        Self {
            strategy,
            params: Vec::new(),
        }
    }
}

impl From<&str> for AlgoParams {
    fn from(strategy: &str) -> Self {
        Self {
            strategy: strategy.to_string(),
            params: Vec::new(),
        }
    }
}

// === VWAP Builder ===

/// Builder for VWAP (Volume Weighted Average Price) algorithmic orders.
///
/// VWAP seeks to achieve the volume-weighted average price from order
/// submission to market close.
///
/// # Example
///
/// ```no_run
/// use ibapi::orders::builder::vwap;
///
/// let algo = vwap()
///     .max_pct_vol(0.2)
///     .start_time("09:00:00 US/Eastern")
///     .end_time("16:00:00 US/Eastern")
///     .build()?;
/// # Ok::<(), ibapi::orders::builder::ValidationError>(())
/// ```
#[derive(Debug, Clone, Default)]
#[must_use = "VwapBuilder does nothing until you call .build()"]
pub struct VwapBuilder {
    max_pct_vol: Option<f64>,
    start_time: Option<String>,
    end_time: Option<String>,
    allow_past_end_time: Option<bool>,
    no_take_liq: Option<bool>,
    speed_up: Option<bool>,
}

impl VwapBuilder {
    /// Create a new VWAP builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set maximum participation rate (must be 10-50% per IB requirements).
    pub fn max_pct_vol(mut self, pct: f64) -> Self {
        self.max_pct_vol = Some(pct);
        self
    }

    /// Set start time (format: "HH:MM:SS TZ", e.g., "09:00:00 US/Eastern").
    pub fn start_time(mut self, time: impl Into<String>) -> Self {
        self.start_time = Some(time.into());
        self
    }

    /// Set end time (format: "HH:MM:SS TZ", e.g., "16:00:00 US/Eastern").
    pub fn end_time(mut self, time: impl Into<String>) -> Self {
        self.end_time = Some(time.into());
        self
    }

    /// Allow trading past the end time.
    pub fn allow_past_end_time(mut self, allow: bool) -> Self {
        self.allow_past_end_time = Some(allow);
        self
    }

    /// Passive only - do not take liquidity.
    pub fn no_take_liq(mut self, no_take: bool) -> Self {
        self.no_take_liq = Some(no_take);
        self
    }

    /// Speed up execution in momentum.
    pub fn speed_up(mut self, speed_up: bool) -> Self {
        self.speed_up = Some(speed_up);
        self
    }

    /// Build the algo parameters.
    ///
    /// Returns an error if `max_pct_vol` is set but outside the 10-50% range.
    pub fn build(self) -> Result<AlgoParams, ValidationError> {
        let mut params = Vec::new();

        push_pct_vol_if_some(&mut params, "max_pct_vol", "maxPctVol", self.max_pct_vol)?;
        push_param_if_some(&mut params, "startTime", self.start_time);
        push_param_if_some(&mut params, "endTime", self.end_time);
        push_param_if_some(&mut params, "allowPastEndTime", self.allow_past_end_time.map(|v| v.to_field()));
        push_param_if_some(&mut params, "noTakeLiq", self.no_take_liq.map(|v| v.to_field()));
        push_param_if_some(&mut params, "speedUp", self.speed_up.map(|v| v.to_field()));

        Ok(AlgoParams {
            strategy: "Vwap".to_string(),
            params,
        })
    }
}
// === TWAP Builder ===

/// Strategy type for TWAP orders.
#[derive(Debug, Clone, Copy, Default)]
pub enum TwapStrategyType {
    /// Default TWAP strategy
    #[default]
    Marketable,
    /// Match midpoint
    MatchingMidpoint,
    /// Match same side
    MatchingSameSide,
    /// Match last
    MatchingLast,
}

impl TwapStrategyType {
    fn as_str(&self) -> &'static str {
        match self {
            TwapStrategyType::Marketable => "Marketable",
            TwapStrategyType::MatchingMidpoint => "Matching Midpoint",
            TwapStrategyType::MatchingSameSide => "Matching Same Side",
            TwapStrategyType::MatchingLast => "Matching Last",
        }
    }
}

/// Builder for TWAP (Time Weighted Average Price) algorithmic orders.
///
/// TWAP seeks to achieve the time-weighted average price.
///
/// # Example
///
/// ```no_run
/// use ibapi::orders::builder::twap;
///
/// let algo = twap()
///     .start_time("09:00:00 US/Eastern")
///     .end_time("16:00:00 US/Eastern")
///     .build()?;
/// # Ok::<(), ibapi::orders::builder::ValidationError>(())
/// ```
#[derive(Debug, Clone, Default)]
#[must_use = "TwapBuilder does nothing until you call .build()"]
pub struct TwapBuilder {
    strategy_type: Option<TwapStrategyType>,
    start_time: Option<String>,
    end_time: Option<String>,
    allow_past_end_time: Option<bool>,
}

impl TwapBuilder {
    /// Create a new TWAP builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set the TWAP strategy type.
    pub fn strategy_type(mut self, strategy: TwapStrategyType) -> Self {
        self.strategy_type = Some(strategy);
        self
    }

    /// Set start time (format: "HH:MM:SS TZ", e.g., "09:00:00 US/Eastern").
    pub fn start_time(mut self, time: impl Into<String>) -> Self {
        self.start_time = Some(time.into());
        self
    }

    /// Set end time (format: "HH:MM:SS TZ", e.g., "16:00:00 US/Eastern").
    pub fn end_time(mut self, time: impl Into<String>) -> Self {
        self.end_time = Some(time.into());
        self
    }

    /// Allow trading past the end time.
    pub fn allow_past_end_time(mut self, allow: bool) -> Self {
        self.allow_past_end_time = Some(allow);
        self
    }

    /// Build the algo parameters.
    pub fn build(self) -> Result<AlgoParams, ValidationError> {
        let mut params = Vec::new();

        push_param_if_some(&mut params, "strategyType", self.strategy_type.map(|v| v.as_str().to_string()));
        push_param_if_some(&mut params, "startTime", self.start_time);
        push_param_if_some(&mut params, "endTime", self.end_time);
        push_param_if_some(&mut params, "allowPastEndTime", self.allow_past_end_time.map(|v| v.to_field()));

        Ok(AlgoParams {
            strategy: "Twap".to_string(),
            params,
        })
    }
}
// === Percentage of Volume Builder ===

/// Builder for Percentage of Volume (PctVol) algorithmic orders.
///
/// Controls participation rate to minimize market impact.
///
/// # Example
///
/// ```no_run
/// use ibapi::orders::builder::pct_vol;
///
/// let algo = pct_vol()
///     .pct_vol(0.1)
///     .start_time("09:00:00 US/Eastern")
///     .end_time("16:00:00 US/Eastern")
///     .build()?;
/// # Ok::<(), ibapi::orders::builder::ValidationError>(())
/// ```
#[derive(Debug, Clone, Default)]
#[must_use = "PctVolBuilder does nothing until you call .build()"]
pub struct PctVolBuilder {
    pct_vol: Option<f64>,
    start_time: Option<String>,
    end_time: Option<String>,
    no_take_liq: Option<bool>,
}

impl PctVolBuilder {
    /// Create a new PctVol builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set target participation rate (must be 10-50% per IB requirements).
    pub fn pct_vol(mut self, pct: f64) -> Self {
        self.pct_vol = Some(pct);
        self
    }

    /// Set start time (format: "HH:MM:SS TZ", e.g., "09:00:00 US/Eastern").
    pub fn start_time(mut self, time: impl Into<String>) -> Self {
        self.start_time = Some(time.into());
        self
    }

    /// Set end time (format: "HH:MM:SS TZ", e.g., "16:00:00 US/Eastern").
    pub fn end_time(mut self, time: impl Into<String>) -> Self {
        self.end_time = Some(time.into());
        self
    }

    /// Passive only - do not take liquidity.
    pub fn no_take_liq(mut self, no_take: bool) -> Self {
        self.no_take_liq = Some(no_take);
        self
    }

    /// Build the algo parameters.
    ///
    /// Returns an error if `pct_vol` is set but outside the 10-50% range.
    pub fn build(self) -> Result<AlgoParams, ValidationError> {
        let mut params = Vec::new();

        push_pct_vol_if_some(&mut params, "pct_vol", "pctVol", self.pct_vol)?;
        push_param_if_some(&mut params, "startTime", self.start_time);
        push_param_if_some(&mut params, "endTime", self.end_time);
        push_param_if_some(&mut params, "noTakeLiq", self.no_take_liq.map(|v| v.to_field()));

        Ok(AlgoParams {
            strategy: "PctVol".to_string(),
            params,
        })
    }
}
// === Arrival Price Builder ===

/// Risk aversion level for Arrival Price orders.
#[derive(Debug, Clone, Copy, Default)]
pub enum RiskAversion {
    /// Get Done - complete order quickly
    GetDone,
    /// Aggressive - favor speed over price
    Aggressive,
    /// Neutral - balance speed and price
    #[default]
    Neutral,
    /// Passive - favor price over speed
    Passive,
}

impl RiskAversion {
    fn as_str(&self) -> &'static str {
        match self {
            RiskAversion::GetDone => "Get Done",
            RiskAversion::Aggressive => "Aggressive",
            RiskAversion::Neutral => "Neutral",
            RiskAversion::Passive => "Passive",
        }
    }
}

/// Builder for Arrival Price algorithmic orders.
///
/// Achieves the bid/ask midpoint at order arrival time.
///
/// # Example
///
/// ```no_run
/// use ibapi::orders::builder::{arrival_price, RiskAversion};
///
/// let algo = arrival_price()
///     .max_pct_vol(0.1)
///     .risk_aversion(RiskAversion::Neutral)
///     .start_time("09:00:00 US/Eastern")
///     .end_time("16:00:00 US/Eastern")
///     .build()?;
/// # Ok::<(), ibapi::orders::builder::ValidationError>(())
/// ```
#[derive(Debug, Clone, Default)]
#[must_use = "ArrivalPriceBuilder does nothing until you call .build()"]
pub struct ArrivalPriceBuilder {
    max_pct_vol: Option<f64>,
    risk_aversion: Option<RiskAversion>,
    start_time: Option<String>,
    end_time: Option<String>,
    force_completion: Option<bool>,
    allow_past_end_time: Option<bool>,
}

impl ArrivalPriceBuilder {
    /// Create a new Arrival Price builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set maximum participation rate (must be 10-50% per IB requirements).
    pub fn max_pct_vol(mut self, pct: f64) -> Self {
        self.max_pct_vol = Some(pct);
        self
    }

    /// Set risk aversion level.
    pub fn risk_aversion(mut self, risk: RiskAversion) -> Self {
        self.risk_aversion = Some(risk);
        self
    }

    /// Set start time (format: "HH:MM:SS TZ", e.g., "09:00:00 US/Eastern").
    pub fn start_time(mut self, time: impl Into<String>) -> Self {
        self.start_time = Some(time.into());
        self
    }

    /// Set end time (format: "HH:MM:SS TZ", e.g., "16:00:00 US/Eastern").
    pub fn end_time(mut self, time: impl Into<String>) -> Self {
        self.end_time = Some(time.into());
        self
    }

    /// Force completion by end time.
    pub fn force_completion(mut self, force: bool) -> Self {
        self.force_completion = Some(force);
        self
    }

    /// Allow trading past the end time.
    pub fn allow_past_end_time(mut self, allow: bool) -> Self {
        self.allow_past_end_time = Some(allow);
        self
    }

    /// Build the algo parameters.
    ///
    /// Returns an error if `max_pct_vol` is set but outside the 10-50% range.
    pub fn build(self) -> Result<AlgoParams, ValidationError> {
        let mut params = Vec::new();

        push_pct_vol_if_some(&mut params, "max_pct_vol", "maxPctVol", self.max_pct_vol)?;
        push_param_if_some(&mut params, "riskAversion", self.risk_aversion.map(|v| v.as_str().to_string()));
        push_param_if_some(&mut params, "startTime", self.start_time);
        push_param_if_some(&mut params, "endTime", self.end_time);
        push_param_if_some(&mut params, "forceCompletion", self.force_completion.map(|v| v.to_field()));
        push_param_if_some(&mut params, "allowPastEndTime", self.allow_past_end_time.map(|v| v.to_field()));

        Ok(AlgoParams {
            strategy: "ArrivalPx".to_string(),
            params,
        })
    }
}
// === Adaptive Builder ===

/// Urgency priority for Adaptive algorithmic orders.
#[derive(Debug, Clone, Copy, Default)]
pub enum AdaptivePriority {
    /// Urgent - complete quickly, less concerned with price improvement
    Urgent,
    /// Normal - balanced execution speed and price improvement
    #[default]
    Normal,
    /// Patient - prefer price improvement, accept slower execution
    Patient,
}

impl AdaptivePriority {
    fn as_str(&self) -> &'static str {
        match self {
            AdaptivePriority::Urgent => "Urgent",
            AdaptivePriority::Normal => "Normal",
            AdaptivePriority::Patient => "Patient",
        }
    }
}

/// Builder for Adaptive algorithmic orders.
///
/// Combines IB's Smart Routing with user-defined urgency to balance
/// execution speed against price improvement.
///
/// # Example
///
/// ```no_run
/// use ibapi::orders::builder::{adaptive, AdaptivePriority};
///
/// let algo = adaptive()
///     .priority(AdaptivePriority::Normal)
///     .build()?;
/// # Ok::<(), ibapi::orders::builder::ValidationError>(())
/// ```
#[derive(Debug, Clone, Default)]
#[must_use = "AdaptiveBuilder does nothing until you call .build()"]
pub struct AdaptiveBuilder {
    priority: Option<AdaptivePriority>,
}

impl AdaptiveBuilder {
    /// Create a new Adaptive builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set the urgency priority.
    pub fn priority(mut self, priority: AdaptivePriority) -> Self {
        self.priority = Some(priority);
        self
    }

    /// Build the algo parameters.
    pub fn build(self) -> Result<AlgoParams, ValidationError> {
        let mut params = Vec::new();

        push_param_if_some(&mut params, "adaptivePriority", self.priority.map(|v| v.as_str().to_string()));

        Ok(AlgoParams {
            strategy: "Adaptive".to_string(),
            params,
        })
    }
}
// === Close Price Builder ===

/// Builder for Close Price (ClosePx) algorithmic orders.
///
/// Minimizes slippage relative to the closing auction price.
///
/// # Example
///
/// ```no_run
/// use ibapi::orders::builder::{close_price, RiskAversion};
///
/// let algo = close_price()
///     .max_pct_vol(0.2)
///     .risk_aversion(RiskAversion::Neutral)
///     .start_time("15:30:00 US/Eastern")
///     .force_completion(true)
///     .build()?;
/// # Ok::<(), ibapi::orders::builder::ValidationError>(())
/// ```
#[derive(Debug, Clone, Default)]
#[must_use = "ClosePriceBuilder does nothing until you call .build()"]
pub struct ClosePriceBuilder {
    max_pct_vol: Option<f64>,
    risk_aversion: Option<RiskAversion>,
    start_time: Option<String>,
    force_completion: Option<bool>,
}

impl ClosePriceBuilder {
    /// Create a new Close Price builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set maximum participation rate (must be 10-50% per IB requirements).
    pub fn max_pct_vol(mut self, pct: f64) -> Self {
        self.max_pct_vol = Some(pct);
        self
    }

    /// Set risk aversion level.
    pub fn risk_aversion(mut self, risk: RiskAversion) -> Self {
        self.risk_aversion = Some(risk);
        self
    }

    /// Set start time (format: "HH:MM:SS TZ", e.g., "15:30:00 US/Eastern").
    pub fn start_time(mut self, time: impl Into<String>) -> Self {
        self.start_time = Some(time.into());
        self
    }

    /// Force completion by the close.
    pub fn force_completion(mut self, force: bool) -> Self {
        self.force_completion = Some(force);
        self
    }

    /// Build the algo parameters.
    ///
    /// Returns an error if `max_pct_vol` is set but outside the 10-50% range.
    pub fn build(self) -> Result<AlgoParams, ValidationError> {
        let mut params = Vec::new();

        push_pct_vol_if_some(&mut params, "max_pct_vol", "maxPctVol", self.max_pct_vol)?;
        push_param_if_some(&mut params, "riskAversion", self.risk_aversion.map(|v| v.as_str().to_string()));
        push_param_if_some(&mut params, "startTime", self.start_time);
        push_param_if_some(&mut params, "forceCompletion", self.force_completion.map(|v| v.to_field()));

        Ok(AlgoParams {
            strategy: "ClosePx".to_string(),
            params,
        })
    }
}
// === Dark Ice Builder ===

/// Builder for Dark Ice algorithmic orders.
///
/// Hidden order with randomized display sizes - the user-supplied display
/// size is randomized in increments to camouflage the actual order size.
///
/// # Example
///
/// ```no_run
/// use ibapi::orders::builder::dark_ice;
///
/// let algo = dark_ice()
///     .display_size(100)
///     .start_time("09:30:00 US/Eastern")
///     .end_time("16:00:00 US/Eastern")
///     .build()?;
/// # Ok::<(), ibapi::orders::builder::ValidationError>(())
/// ```
#[derive(Debug, Clone, Default)]
#[must_use = "DarkIceBuilder does nothing until you call .build()"]
pub struct DarkIceBuilder {
    display_size: Option<i32>,
    start_time: Option<String>,
    end_time: Option<String>,
    allow_past_end_time: Option<bool>,
}

impl DarkIceBuilder {
    /// Create a new Dark Ice builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set the display size (the visible portion of the order).
    pub fn display_size(mut self, size: i32) -> Self {
        self.display_size = Some(size);
        self
    }

    /// Set start time (format: "HH:MM:SS TZ", e.g., "09:30:00 US/Eastern").
    pub fn start_time(mut self, time: impl Into<String>) -> Self {
        self.start_time = Some(time.into());
        self
    }

    /// Set end time (format: "HH:MM:SS TZ", e.g., "16:00:00 US/Eastern").
    pub fn end_time(mut self, time: impl Into<String>) -> Self {
        self.end_time = Some(time.into());
        self
    }

    /// Allow trading past the end time.
    pub fn allow_past_end_time(mut self, allow: bool) -> Self {
        self.allow_past_end_time = Some(allow);
        self
    }

    /// Build the algo parameters.
    pub fn build(self) -> Result<AlgoParams, ValidationError> {
        let mut params = Vec::new();

        push_param_if_some(&mut params, "displaySize", self.display_size.map(|v| v.to_string()));
        push_param_if_some(&mut params, "startTime", self.start_time);
        push_param_if_some(&mut params, "endTime", self.end_time);
        push_param_if_some(&mut params, "allowPastEndTime", self.allow_past_end_time.map(|v| v.to_field()));

        Ok(AlgoParams {
            strategy: "DarkIce".to_string(),
            params,
        })
    }
}
// === Accumulate/Distribute Builder ===

/// Builder for Accumulate/Distribute (AD) algorithmic orders.
///
/// Slices an order into random increments at random intervals to disguise
/// trading intent.
///
/// # Example
///
/// ```no_run
/// use ibapi::orders::builder::accumulate_distribute;
///
/// let algo = accumulate_distribute()
///     .component_size(100)
///     .time_between_orders(60)
///     .randomize_time_20(true)
///     .randomize_size_55(true)
///     .build()?;
/// # Ok::<(), ibapi::orders::builder::ValidationError>(())
/// ```
#[derive(Debug, Clone, Default)]
#[must_use = "AccumulateDistributeBuilder does nothing until you call .build()"]
pub struct AccumulateDistributeBuilder {
    component_size: Option<i32>,
    time_between_orders: Option<i32>,
    randomize_time_20: Option<bool>,
    randomize_size_55: Option<bool>,
    give_up: Option<i32>,
    catch_up: Option<bool>,
    wait_for_fill: Option<bool>,
    active_time_start: Option<String>,
    active_time_end: Option<String>,
}

impl AccumulateDistributeBuilder {
    /// Create a new Accumulate/Distribute builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set the size of each component slice.
    pub fn component_size(mut self, size: i32) -> Self {
        self.component_size = Some(size);
        self
    }

    /// Set the seconds between component orders.
    pub fn time_between_orders(mut self, seconds: i32) -> Self {
        self.time_between_orders = Some(seconds);
        self
    }

    /// Randomize the time interval by ±20%.
    pub fn randomize_time_20(mut self, randomize: bool) -> Self {
        self.randomize_time_20 = Some(randomize);
        self
    }

    /// Randomize the component size by ±55%.
    pub fn randomize_size_55(mut self, randomize: bool) -> Self {
        self.randomize_size_55 = Some(randomize);
        self
    }

    /// Set the give-up account.
    pub fn give_up(mut self, give_up: i32) -> Self {
        self.give_up = Some(give_up);
        self
    }

    /// Catch up in time if the algo falls behind.
    pub fn catch_up(mut self, catch_up: bool) -> Self {
        self.catch_up = Some(catch_up);
        self
    }

    /// Wait for the previous component to fill before submitting the next.
    pub fn wait_for_fill(mut self, wait: bool) -> Self {
        self.wait_for_fill = Some(wait);
        self
    }

    /// Set the active period start time (format: "YYYYMMDD-HH:MM:SS TZ").
    pub fn active_time_start(mut self, time: impl Into<String>) -> Self {
        self.active_time_start = Some(time.into());
        self
    }

    /// Set the active period end time (format: "YYYYMMDD-HH:MM:SS TZ").
    pub fn active_time_end(mut self, time: impl Into<String>) -> Self {
        self.active_time_end = Some(time.into());
        self
    }

    /// Build the algo parameters.
    pub fn build(self) -> Result<AlgoParams, ValidationError> {
        let mut params = Vec::new();

        push_param_if_some(&mut params, "componentSize", self.component_size.map(|v| v.to_string()));
        push_param_if_some(&mut params, "timeBetweenOrders", self.time_between_orders.map(|v| v.to_string()));
        push_param_if_some(&mut params, "randomizeTime20", self.randomize_time_20.map(|v| v.to_field()));
        push_param_if_some(&mut params, "randomizeSize55", self.randomize_size_55.map(|v| v.to_field()));
        push_param_if_some(&mut params, "giveUp", self.give_up.map(|v| v.to_string()));
        push_param_if_some(&mut params, "catchUp", self.catch_up.map(|v| v.to_field()));
        push_param_if_some(&mut params, "waitForFill", self.wait_for_fill.map(|v| v.to_field()));
        push_param_if_some(&mut params, "activeTimeStart", self.active_time_start);
        push_param_if_some(&mut params, "activeTimeEnd", self.active_time_end);

        Ok(AlgoParams {
            strategy: "AD".to_string(),
            params,
        })
    }
}
// === Balance Impact Risk Builder ===

/// Builder for Balance Impact Risk algorithmic orders.
///
/// Balances market impact against the risk of adverse price movement.
///
/// # Example
///
/// ```no_run
/// use ibapi::orders::builder::{balance_impact_risk, RiskAversion};
///
/// let algo = balance_impact_risk()
///     .max_pct_vol(0.2)
///     .risk_aversion(RiskAversion::Neutral)
///     .force_completion(true)
///     .build()?;
/// # Ok::<(), ibapi::orders::builder::ValidationError>(())
/// ```
#[derive(Debug, Clone, Default)]
#[must_use = "BalanceImpactRiskBuilder does nothing until you call .build()"]
pub struct BalanceImpactRiskBuilder {
    max_pct_vol: Option<f64>,
    risk_aversion: Option<RiskAversion>,
    force_completion: Option<bool>,
}

impl BalanceImpactRiskBuilder {
    /// Create a new Balance Impact Risk builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set maximum participation rate (must be 10-50% per IB requirements).
    pub fn max_pct_vol(mut self, pct: f64) -> Self {
        self.max_pct_vol = Some(pct);
        self
    }

    /// Set risk aversion level.
    pub fn risk_aversion(mut self, risk: RiskAversion) -> Self {
        self.risk_aversion = Some(risk);
        self
    }

    /// Force completion of the order.
    pub fn force_completion(mut self, force: bool) -> Self {
        self.force_completion = Some(force);
        self
    }

    /// Build the algo parameters.
    ///
    /// Returns an error if `max_pct_vol` is set but outside the 10-50% range.
    pub fn build(self) -> Result<AlgoParams, ValidationError> {
        let mut params = Vec::new();

        push_pct_vol_if_some(&mut params, "max_pct_vol", "maxPctVol", self.max_pct_vol)?;
        push_param_if_some(&mut params, "riskAversion", self.risk_aversion.map(|v| v.as_str().to_string()));
        push_param_if_some(&mut params, "forceCompletion", self.force_completion.map(|v| v.to_field()));

        Ok(AlgoParams {
            strategy: "BalanceImpactRisk".to_string(),
            params,
        })
    }
}
// === Minimise Impact Builder ===

/// Builder for Minimise Impact (MinImpact) algorithmic orders.
///
/// Slices the order to achieve the market average with minimal impact.
///
/// # Example
///
/// ```no_run
/// use ibapi::orders::builder::minimise_impact;
///
/// let algo = minimise_impact()
///     .max_pct_vol(0.2)
///     .build()?;
/// # Ok::<(), ibapi::orders::builder::ValidationError>(())
/// ```
#[derive(Debug, Clone, Default)]
#[must_use = "MinimiseImpactBuilder does nothing until you call .build()"]
pub struct MinimiseImpactBuilder {
    max_pct_vol: Option<f64>,
}

impl MinimiseImpactBuilder {
    /// Create a new Minimise Impact builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set maximum participation rate (must be 10-50% per IB requirements).
    pub fn max_pct_vol(mut self, pct: f64) -> Self {
        self.max_pct_vol = Some(pct);
        self
    }

    /// Build the algo parameters.
    ///
    /// Returns an error if `max_pct_vol` is set but outside the 10-50% range.
    pub fn build(self) -> Result<AlgoParams, ValidationError> {
        let mut params = Vec::new();

        push_pct_vol_if_some(&mut params, "max_pct_vol", "maxPctVol", self.max_pct_vol)?;

        Ok(AlgoParams {
            strategy: "MinImpact".to_string(),
            params,
        })
    }
}
// === Price Variant Percentage of Volume Builder ===

/// Builder for Price Variant Percentage of Volume (PctVolPx) algorithmic orders.
///
/// Participation rate varies with the market price: tracks at `pct_vol`,
/// adjusts by `delta_pct_vol` as price moves, and stays bounded by
/// `min_pct_vol_4_px` / `max_pct_vol_4_px`. All four percentage fields are
/// validated to IB's 10-50% range.
///
/// # Example
///
/// ```no_run
/// use ibapi::orders::builder::pct_vol_price;
///
/// let algo = pct_vol_price()
///     .pct_vol(0.2)
///     .delta_pct_vol(0.1)
///     .min_pct_vol_4_px(0.1)
///     .max_pct_vol_4_px(0.4)
///     .start_time("09:30:00 US/Eastern")
///     .end_time("16:00:00 US/Eastern")
///     .build()?;
/// # Ok::<(), ibapi::orders::builder::ValidationError>(())
/// ```
#[derive(Debug, Clone, Default)]
#[must_use = "PctVolPriceBuilder does nothing until you call .build()"]
pub struct PctVolPriceBuilder {
    pct_vol: Option<f64>,
    delta_pct_vol: Option<f64>,
    min_pct_vol_4_px: Option<f64>,
    max_pct_vol_4_px: Option<f64>,
    start_time: Option<String>,
    end_time: Option<String>,
    no_take_liq: Option<bool>,
}

impl PctVolPriceBuilder {
    /// Create a new PctVolPx builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set the base participation rate (must be 10-50% per IB requirements).
    pub fn pct_vol(mut self, pct: f64) -> Self {
        self.pct_vol = Some(pct);
        self
    }

    /// Set the rate delta applied as price moves (must be 10-50%).
    pub fn delta_pct_vol(mut self, delta: f64) -> Self {
        self.delta_pct_vol = Some(delta);
        self
    }

    /// Set the minimum participation rate bound (must be 10-50%).
    pub fn min_pct_vol_4_px(mut self, pct: f64) -> Self {
        self.min_pct_vol_4_px = Some(pct);
        self
    }

    /// Set the maximum participation rate bound (must be 10-50%).
    pub fn max_pct_vol_4_px(mut self, pct: f64) -> Self {
        self.max_pct_vol_4_px = Some(pct);
        self
    }

    /// Set start time (format: "HH:MM:SS TZ", e.g., "09:30:00 US/Eastern").
    pub fn start_time(mut self, time: impl Into<String>) -> Self {
        self.start_time = Some(time.into());
        self
    }

    /// Set end time (format: "HH:MM:SS TZ", e.g., "16:00:00 US/Eastern").
    pub fn end_time(mut self, time: impl Into<String>) -> Self {
        self.end_time = Some(time.into());
        self
    }

    /// Passive only - do not take liquidity.
    pub fn no_take_liq(mut self, no_take: bool) -> Self {
        self.no_take_liq = Some(no_take);
        self
    }

    /// Build the algo parameters.
    ///
    /// Returns an error if any of `pct_vol`, `delta_pct_vol`,
    /// `min_pct_vol_4_px`, or `max_pct_vol_4_px` is set but outside IB's
    /// 10-50% range.
    pub fn build(self) -> Result<AlgoParams, ValidationError> {
        let mut params = Vec::new();

        push_pct_vol_if_some(&mut params, "pct_vol", "pctVol", self.pct_vol)?;
        push_pct_vol_if_some(&mut params, "delta_pct_vol", "deltaPctVol", self.delta_pct_vol)?;
        push_pct_vol_if_some(&mut params, "min_pct_vol_4_px", "minPctVol4Px", self.min_pct_vol_4_px)?;
        push_pct_vol_if_some(&mut params, "max_pct_vol_4_px", "maxPctVol4Px", self.max_pct_vol_4_px)?;
        push_param_if_some(&mut params, "startTime", self.start_time);
        push_param_if_some(&mut params, "endTime", self.end_time);
        push_param_if_some(&mut params, "noTakeLiq", self.no_take_liq.map(|v| v.to_field()));

        Ok(AlgoParams {
            strategy: "PctVolPx".to_string(),
            params,
        })
    }
}
// === Size Variant Percentage of Volume Builder ===

/// Builder for Size Variant Percentage of Volume (PctVolSz) algorithmic orders.
///
/// Participation rate varies linearly from `start_pct_vol` to `end_pct_vol`
/// as the order is filled.
///
/// # Example
///
/// ```no_run
/// use ibapi::orders::builder::pct_vol_size;
///
/// let algo = pct_vol_size()
///     .start_pct_vol(0.1)
///     .end_pct_vol(0.4)
///     .start_time("09:30:00 US/Eastern")
///     .end_time("16:00:00 US/Eastern")
///     .build()?;
/// # Ok::<(), ibapi::orders::builder::ValidationError>(())
/// ```
#[derive(Debug, Clone, Default)]
#[must_use = "PctVolSizeBuilder does nothing until you call .build()"]
pub struct PctVolSizeBuilder {
    start_pct_vol: Option<f64>,
    end_pct_vol: Option<f64>,
    start_time: Option<String>,
    end_time: Option<String>,
    no_take_liq: Option<bool>,
}

impl PctVolSizeBuilder {
    /// Create a new PctVolSz builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set the participation rate at the start (must be 10-50%).
    pub fn start_pct_vol(mut self, pct: f64) -> Self {
        self.start_pct_vol = Some(pct);
        self
    }

    /// Set the participation rate at the end (must be 10-50%).
    pub fn end_pct_vol(mut self, pct: f64) -> Self {
        self.end_pct_vol = Some(pct);
        self
    }

    /// Set start time (format: "HH:MM:SS TZ", e.g., "09:30:00 US/Eastern").
    pub fn start_time(mut self, time: impl Into<String>) -> Self {
        self.start_time = Some(time.into());
        self
    }

    /// Set end time (format: "HH:MM:SS TZ", e.g., "16:00:00 US/Eastern").
    pub fn end_time(mut self, time: impl Into<String>) -> Self {
        self.end_time = Some(time.into());
        self
    }

    /// Passive only - do not take liquidity.
    pub fn no_take_liq(mut self, no_take: bool) -> Self {
        self.no_take_liq = Some(no_take);
        self
    }

    /// Build the algo parameters.
    ///
    /// Returns an error if `start_pct_vol` or `end_pct_vol` is set but
    /// outside the 10-50% range.
    pub fn build(self) -> Result<AlgoParams, ValidationError> {
        build_windowed_pct_vol(
            "PctVolSz",
            self.start_pct_vol,
            self.end_pct_vol,
            self.start_time,
            self.end_time,
            self.no_take_liq,
        )
    }
}

// === Time Variant Percentage of Volume Builder ===

/// Builder for Time Variant Percentage of Volume (PctVolTm) algorithmic orders.
///
/// Participation rate varies linearly from `start_pct_vol` to `end_pct_vol`
/// over the active time window.
///
/// # Example
///
/// ```no_run
/// use ibapi::orders::builder::pct_vol_time;
///
/// let algo = pct_vol_time()
///     .start_pct_vol(0.1)
///     .end_pct_vol(0.4)
///     .start_time("09:30:00 US/Eastern")
///     .end_time("16:00:00 US/Eastern")
///     .build()?;
/// # Ok::<(), ibapi::orders::builder::ValidationError>(())
/// ```
#[derive(Debug, Clone, Default)]
#[must_use = "PctVolTimeBuilder does nothing until you call .build()"]
pub struct PctVolTimeBuilder {
    start_pct_vol: Option<f64>,
    end_pct_vol: Option<f64>,
    start_time: Option<String>,
    end_time: Option<String>,
    no_take_liq: Option<bool>,
}

impl PctVolTimeBuilder {
    /// Create a new PctVolTm builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set the participation rate at the start (must be 10-50%).
    pub fn start_pct_vol(mut self, pct: f64) -> Self {
        self.start_pct_vol = Some(pct);
        self
    }

    /// Set the participation rate at the end (must be 10-50%).
    pub fn end_pct_vol(mut self, pct: f64) -> Self {
        self.end_pct_vol = Some(pct);
        self
    }

    /// Set start time (format: "HH:MM:SS TZ", e.g., "09:30:00 US/Eastern").
    pub fn start_time(mut self, time: impl Into<String>) -> Self {
        self.start_time = Some(time.into());
        self
    }

    /// Set end time (format: "HH:MM:SS TZ", e.g., "16:00:00 US/Eastern").
    pub fn end_time(mut self, time: impl Into<String>) -> Self {
        self.end_time = Some(time.into());
        self
    }

    /// Passive only - do not take liquidity.
    pub fn no_take_liq(mut self, no_take: bool) -> Self {
        self.no_take_liq = Some(no_take);
        self
    }

    /// Build the algo parameters.
    ///
    /// Returns an error if `start_pct_vol` or `end_pct_vol` is set but
    /// outside the 10-50% range.
    pub fn build(self) -> Result<AlgoParams, ValidationError> {
        build_windowed_pct_vol(
            "PctVolTm",
            self.start_pct_vol,
            self.end_pct_vol,
            self.start_time,
            self.end_time,
            self.no_take_liq,
        )
    }
}

// === AccuDistr Builder ===

/// Builder for AccuDistr algorithmic orders.
///
/// AccuDistr is a separate IBKR algorithm from `AD` (Accumulate/Distribute).
/// It exposes a smaller set of parameters and adds an explicit time zone
/// (`active_time_tz`) and a `route_order_type` knob. Strategy string on the
/// wire is `"AccuDistr"`.
///
/// `route_order_type` is a free-form string per IBKR's sample code (typical
/// values: `"LMT"`, `"MKT"`, `"REL"`). The IBKR algo docs page does not
/// enumerate the parameters of this algo; the parameter shape is taken from
/// the canonical Testbed sample (`samples/CSharp/Testbed/AvailableAlgoParams.cs`).
///
/// # Example
///
/// ```no_run
/// use ibapi::orders::builder::accu_distr;
///
/// let algo = accu_distr()
///     .time_between_orders(60)
///     .route_order_type("LMT")
///     .component_size(100)
///     .active_time_start("20260101-09:30:00")
///     .active_time_end("20260101-16:00:00")
///     .active_time_tz("US/Eastern")
///     .build()?;
/// # Ok::<(), ibapi::orders::builder::ValidationError>(())
/// ```
#[derive(Debug, Clone, Default)]
#[must_use = "AccuDistrBuilder does nothing until you call .build()"]
pub struct AccuDistrBuilder {
    time_between_orders: Option<i32>,
    route_order_type: Option<String>,
    component_size: Option<i32>,
    active_time_start: Option<String>,
    active_time_end: Option<String>,
    active_time_tz: Option<String>,
}

impl AccuDistrBuilder {
    /// Create a new AccuDistr builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set the seconds between component orders.
    pub fn time_between_orders(mut self, seconds: i32) -> Self {
        self.time_between_orders = Some(seconds);
        self
    }

    /// Set the route order type (e.g., "LMT", "MKT", "REL").
    pub fn route_order_type(mut self, order_type: impl Into<String>) -> Self {
        self.route_order_type = Some(order_type.into());
        self
    }

    /// Set the size of each component slice.
    pub fn component_size(mut self, size: i32) -> Self {
        self.component_size = Some(size);
        self
    }

    /// Set the active period start time (format: "YYYYMMDD-HH:MM:SS").
    pub fn active_time_start(mut self, time: impl Into<String>) -> Self {
        self.active_time_start = Some(time.into());
        self
    }

    /// Set the active period end time (format: "YYYYMMDD-HH:MM:SS").
    pub fn active_time_end(mut self, time: impl Into<String>) -> Self {
        self.active_time_end = Some(time.into());
        self
    }

    /// Set the time zone for `active_time_start` / `active_time_end`
    /// (e.g., "US/Eastern", "GMT").
    pub fn active_time_tz(mut self, tz: impl Into<String>) -> Self {
        self.active_time_tz = Some(tz.into());
        self
    }

    /// Build the algo parameters.
    pub fn build(self) -> Result<AlgoParams, ValidationError> {
        let mut params = Vec::new();

        push_param_if_some(&mut params, "timeBetweenOrders", self.time_between_orders.map(|v| v.to_string()));
        push_param_if_some(&mut params, "routeOrderType", self.route_order_type);
        push_param_if_some(&mut params, "componentSize", self.component_size.map(|v| v.to_string()));
        push_param_if_some(&mut params, "activeTimeStart", self.active_time_start);
        push_param_if_some(&mut params, "activeTimeEnd", self.active_time_end);
        push_param_if_some(&mut params, "activeTimeTz", self.active_time_tz);

        Ok(AlgoParams {
            strategy: "AccuDistr".to_string(),
            params,
        })
    }
}
#[cfg(test)]
#[path = "algo_builders_tests.rs"]
mod tests;