-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathMessages.Securities.cs
More file actions
1084 lines (978 loc) · 55.9 KB
/
Messages.Securities.cs
File metadata and controls
1084 lines (978 loc) · 55.9 KB
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
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using QuantConnect.Data;
using QuantConnect.Securities;
using QuantConnect.Securities.Positions;
using static QuantConnect.StringExtensions;
namespace QuantConnect
{
/// <summary>
/// Provides user-facing message construction methods and static messages for the <see cref="Securities"/> namespace
/// </summary>
public static partial class Messages
{
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.AccountEvent"/> class and its consumers or related classes
/// </summary>
public static class AccountEvent
{
/// <summary>
/// Returns a string message containing basic information about the given accountEvent
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ToString(Securities.AccountEvent accountEvent)
{
return Invariant($"Account {accountEvent.CurrencySymbol} Balance: {accountEvent.CashBalance:0.00}");
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.BuyingPowerModel"/> class and its consumers or related classes
/// </summary>
public static class BuyingPowerModel
{
/// <summary>
/// String message saying: Initial margin requirement must be between 0 and 1
/// </summary>
public static string InvalidInitialMarginRequirement = "Initial margin requirement must be between 0 and 1";
/// <summary>
/// String messsage saying: Maintenance margin requirement must be between 0 and 1
/// </summary>
public static string InvalidMaintenanceMarginRequirement = "Maintenance margin requirement must be between 0 and 1";
/// <summary>
/// String message saying: Free Buying Power Percent requirement must be between 0 and 1
/// </summary>
public static string InvalidFreeBuyingPowerPercentRequirement = "Free Buying Power Percent requirement must be between 0 and 1";
/// <summary>
/// String message saying: Leverage must be greater than or equal to 1
/// </summary>
public static string InvalidLeverage = "Leverage must be greater than or equal to 1.";
/// <summary>
/// Returns a string message saying the order associated with the id of the given order is null
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string InsufficientBuyingPowerDueToNullOrderTicket(Orders.Order order)
{
return Invariant($"Null order ticket for id: {order.Id}");
}
/// <summary>
/// Returns a string mesage containing information about the order ID, the initial margin and
/// the free margin
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string InsufficientBuyingPowerDueToUnsufficientMargin(Orders.Order order,
decimal initialMarginRequiredForRemainderOfOrder, decimal freeMargin)
{
return Invariant($@"Id: {order.Id}, Initial Margin: {
initialMarginRequiredForRemainderOfOrder.Normalize()}, Free Margin: {freeMargin.Normalize()}");
}
/// <summary>
/// Returns a string message saying the given target order margin is less than the given minimum value
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string TargetOrderMarginNotAboveMinimum(decimal absDifferenceOfMargin, decimal minimumValue)
{
return Invariant($"The target order margin {absDifferenceOfMargin} is less than the minimum {minimumValue}.");
}
/// <summary>
/// Returns a string message warning the user that the Portfolio rebalance result ignored as it resulted in
/// a single share trade recommendation which can generate high fees.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string TargetOrderMarginNotAboveMinimum()
{
return "Warning: Portfolio rebalance result ignored as it resulted in a single share trade recommendation which can generate high fees." +
" To disable minimum order size checks please set Settings.MinimumOrderMarginPortfolioPercentage = 0.";
}
/// <summary>
/// Returns a string message saying that the order quantity is less that the lot size of the given security
/// and that it has been rounded to zero
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string OrderQuantityLessThanLotSize(Securities.Security security, decimal targetOrderMargin)
{
return Invariant($@"The order quantity is less than the lot size of {
security.SymbolProperties.LotSize} and has been rounded to zero. Target order margin {targetOrderMargin}. ");
}
/// <summary>
/// Returns a string message saying GetMaximumOrderQuantityForTargetBuyingPower failed to converge on the target margin.
/// It also contains useful information to reproduce the issue
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string FailedToConvergeOnTheTargetMargin(GetMaximumOrderQuantityForTargetBuyingPowerParameters parameters,
decimal signedTargetFinalMarginValue, decimal orderFees)
{
return Invariant($@"GetMaximumOrderQuantityForTargetBuyingPower failed to converge on the target margin: {
signedTargetFinalMarginValue}; the following information can be used to reproduce the issue. Total Portfolio Cash: {
parameters.Portfolio.Cash}; Security : {parameters.Security.Symbol.ID}; Price : {parameters.Security.Close}; Leverage: {
parameters.Security.Leverage}; Order Fee: {orderFees}; Lot Size: {
parameters.Security.SymbolProperties.LotSize}; Current Holdings: {parameters.Security.Holdings.Quantity} @ {
parameters.Security.Holdings.AveragePrice}; Target Percentage: %{parameters.TargetBuyingPower * 100};");
}
/// <summary>
/// Returns a string message containing basic information related with the underlying security such as the price,
/// the holdings and the average price of them
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string FailedToConvergeOnTheTargetMarginUnderlyingSecurityInfo(Securities.Security underlying)
{
return Invariant($@"Underlying Security: {underlying.Symbol.ID}; Underlying Price: {
underlying.Close}; Underlying Holdings: {underlying.Holdings.Quantity} @ {underlying.Holdings.AveragePrice};");
}
/// <summary>
/// Returns a string message saying the margin is being adjusted in the wrong direction. It also provides useful information to
/// reproduce the issue
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string MarginBeingAdjustedInTheWrongDirection(decimal targetMargin, decimal marginForOneUnit, Securities.Security security)
{
return Invariant(
$@"Margin is being adjusted in the wrong direction. Reproduce this issue with the following variables, Target Margin: {
targetMargin}; MarginForOneUnit: {marginForOneUnit}; Security Holdings: {security.Holdings.Quantity} @ {
security.Holdings.AveragePrice}; LotSize: {security.SymbolProperties.LotSize}; Price: {security.Close}; Leverage: {
security.Leverage}");
}
/// <summary>
/// Returns a string message containing basic information related with the underlying security such as the price,
/// the holdings and the average price of them
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string MarginBeingAdjustedInTheWrongDirectionUnderlyingSecurityInfo(Securities.Security underlying)
{
return Invariant($@"Underlying Security: {underlying.Symbol.ID}; Underlying Price: {
underlying.Close}; Underlying Holdings: {underlying.Holdings.Quantity} @ {underlying.Holdings.AveragePrice};");
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.Positions.PositionGroupBuyingPowerModel"/> class and its consumers or related classes
/// </summary>
public static class PositionGroupBuyingPowerModel
{
/// <summary>
/// String message saying: No buying power used, delta cannot be applied
/// </summary>
public static string DeltaCannotBeApplied = "No buying power used, delta cannot be applied";
/// <summary>
/// Returns a string message saying the zero initial margin requirement was computed
/// for the given position group
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ComputedZeroInitialMargin(IPositionGroup positionGroup)
{
return Invariant($"Computed zero initial margin requirement for {positionGroup.GetUserFriendlyName()}.");
}
/// <summary>
/// Returns a string message saying the position group order quantity has been rounded to zero
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string PositionGroupQuantityRoundedToZero(decimal targetOrderMargin)
{
return Invariant($"The position group order quantity has been rounded to zero. Target order margin {targetOrderMargin}.");
}
/// <summary>
/// Returns a string message saying the process to converge on the given target margin failed
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string FailedToConvergeOnTargetMargin(decimal targetMargin, decimal positionGroupQuantity, decimal orderFees,
GetMaximumLotsForTargetBuyingPowerParameters parameters)
{
return Invariant($@"Failed to converge on the target margin: {targetMargin}; the following information can be used to reproduce the issue. Total Portfolio Cash: {parameters.Portfolio.Cash}; Position group: {parameters.PositionGroup.GetUserFriendlyName()}; Position group order quantity: {positionGroupQuantity} Order Fee: {orderFees}; Current Holdings: {parameters.PositionGroup.Quantity}; Target Percentage: %{parameters.TargetBuyingPower * 100};");
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.Cash"/> class and its consumers or related classes
/// </summary>
public static class Cash
{
/// <summary>
/// String message saying: Cash symbols cannot be null or empty
/// </summary>
public static string NullOrEmptyCashSymbol = "Cash symbols cannot be null or empty.";
/// <summary>
/// Returns a string message saying no tradeable pair was found for the given currency symbol. It also mentions
/// that the given account currency will be set to zero
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string NoTradablePairFoundForCurrencyConversion(string cashCurrencySymbol, string accountCurrency,
IEnumerable<KeyValuePair<SecurityType, string>> marketMap)
{
return Invariant($@"No tradeable pair was found for currency {cashCurrencySymbol}, conversion rate to account currency ({
accountCurrency}) will be set to zero. Markets: [{string.Join(",", marketMap.Select(x => $"{x.Key}:{x.Value}"))}]");
}
/// <summary>
/// Returns a string message saying the security symbol is being added for cash currency feed (this comes from the
/// given cash currency symbol)
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string AddingSecuritySymbolForCashCurrencyFeed(QuantConnect.Symbol symbol, string cashCurrencySymbol)
{
return Invariant($"Adding {symbol.Value} {symbol.ID.Market} for cash {cashCurrencySymbol} currency feed");
}
/// <summary>
/// Parses the given Cash object into a string containing basic information about it
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ToString(Securities.Cash cash, string accountCurrency)
{
// round the conversion rate for output
var rate = cash.ConversionRate;
rate = rate < 1000 ? rate.RoundToSignificantDigits(5) : Math.Round(rate, 2);
return Invariant($@"{cash.Symbol}: {cash.CurrencySymbol}{cash.Amount,15:0.00} @ {rate,10:0.00####} = {
QuantConnect.Currencies.GetCurrencySymbol(accountCurrency)}{Math.Round(cash.ValueInAccountCurrency, 2)}");
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.CashBook"/> class and its consumers or related classes
/// </summary>
public static class CashBook
{
/// <summary>
/// String message saying: Unexpected request for NullCurrency Cash instance
/// </summary>
public static string UnexpectedRequestForNullCurrency = "Unexpected request for NullCurrency Cash instance";
/// <summary>
/// Returns a string message saying the conversion rate for the given currency is not available
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ConversionRateNotFound(string currency)
{
return Invariant($"The conversion rate for {currency} is not available.");
}
/// <summary>
/// Parses the given CashBook into a string mesage with basic information about it
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ToString(Securities.CashBook cashBook)
{
var sb = new StringBuilder();
sb.AppendLine(Invariant($"Symbol {"Quantity",13} {"Conversion",10} = Value in {cashBook.AccountCurrency}"));
foreach (var value in cashBook.Values)
{
sb.AppendLine(value.ToString(cashBook.AccountCurrency));
}
sb.AppendLine("-------------------------------------------------");
sb.AppendLine(Invariant($@"CashBook Total Value: {
QuantConnect.Currencies.GetCurrencySymbol(cashBook.AccountCurrency)}{
Math.Round(cashBook.TotalValueInAccountCurrency, 2).ToStringInvariant()}"));
return sb.ToString();
}
/// <summary>
/// Returns a string message saying the given cash symbol was not found
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string CashSymbolNotFound(string symbol)
{
return $"This cash symbol ({symbol}) was not found in your cash book.";
}
/// <summary>
/// Returns a string message saying it was impossible to remove the cash book record
/// for the given symbol
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string FailedToRemoveRecord(string symbol)
{
return $"Failed to remove the cash book record for symbol {symbol}";
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.CashBuyingPowerModel"/> class and its consumers or related classes
/// </summary>
public static class CashBuyingPowerModel
{
/// <summary>
/// String message saying: CashBuyingPowerModel does not allow setting leverage. Cash accounts have no leverage
/// </summary>
public static string UnsupportedLeverage = "CashBuyingPowerModel does not allow setting leverage. Cash accounts have no leverage.";
/// <summary>
/// String message saying: The CashBuyingPowerModel does not require GetMaximumOrderQuantityForDeltaBuyingPower
/// </summary>
public static string GetMaximumOrderQuantityForDeltaBuyingPowerNotImplemented =
$@"The {nameof(CashBuyingPowerModel)} does not require '{
nameof(Securities.CashBuyingPowerModel.GetMaximumOrderQuantityForDeltaBuyingPower)}'.";
/// <summary>
/// String message saying: The cash model does not allow shorting
/// </summary>
public static string ShortingNotSupported = "The cash model does not allow shorting.";
/// <summary>
/// String message saying: The security type must be Crypto or Forex
/// </summary>
public static string InvalidSecurity = $"The security type must be {nameof(SecurityType.Crypto)}or {nameof(SecurityType.Forex)}.";
/// <summary>
/// Returns a string message saying: The security is not supported by this cash model. It also mentioned that
/// currently just crypt and forex securities are supported
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string UnsupportedSecurity(Securities.Security security)
{
return $@"The '{security.Symbol.Value}' security is not supported by this cash model. Currently only {
nameof(SecurityType.Crypto)} and {nameof(SecurityType.Forex)} are supported.";
}
/// <summary>
/// Returns a string message saying Cash Modeling trading does not permit short holdings as well as portfolio
/// holdings and an advise to ensure the user is selling only what it has
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string SellOrderShortHoldingsNotSupported(decimal totalQuantity, decimal openOrdersReservedQuantity, decimal orderQuantity,
IBaseCurrencySymbol baseCurrency)
{
return Invariant($@"Your portfolio holds {totalQuantity.Normalize()} {
baseCurrency.BaseCurrency.Symbol}, {openOrdersReservedQuantity.Normalize()} {
baseCurrency.BaseCurrency.Symbol} of which are reserved for open orders, but your Sell order is for {
orderQuantity.Normalize()} {baseCurrency.BaseCurrency.Symbol
}. Cash Modeling trading does not permit short holdings so ensure you only sell what you have, including any additional open orders.");
}
/// <summary>
/// Returns a string message containing the portfolio holdings, the buy order and the maximum buying power
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string BuyOrderQuantityGreaterThanMaxForBuyingPower(decimal totalQuantity, decimal maximumQuantity,
decimal openOrdersReservedQuantity, decimal orderQuantity, IBaseCurrencySymbol baseCurrency, Securities.Security security,
Orders.Order order)
{
return Invariant($@"Your portfolio holds {totalQuantity.Normalize()} {
security.QuoteCurrency.Symbol}, {openOrdersReservedQuantity.Normalize()} {
security.QuoteCurrency.Symbol} of which are reserved for open orders, but your Buy order is for {
order.AbsoluteQuantity.Normalize()} {baseCurrency.BaseCurrency.Symbol}. Your order requires a total value of {
orderQuantity.Normalize()} {security.QuoteCurrency.Symbol}, but only a total value of {
Math.Abs(maximumQuantity).Normalize()} {security.QuoteCurrency.Symbol} is available.");
}
/// <summary>
/// Returns a string message saying the internal cash feed required for converting the quote currency, from the given security,
/// to the target account currency, from the given portfolio, does not have any data
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string NoDataInInternalCashFeedYet(Securities.Security security, Securities.SecurityPortfolioManager portfolio)
{
return Invariant($@"The internal cash feed required for converting {security.QuoteCurrency.Symbol} to {
portfolio.CashBook.AccountCurrency} does not have any data yet (or market may be closed).");
}
/// <summary>
/// Returns a string mesasge saying the contract multiplier for the given security is zero
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ZeroContractMultiplier(Securities.Security security)
{
return $@"The contract multiplier for the {
security.Symbol.Value} security is zero. The symbol properties database may be out of date.";
}
/// <summary>
/// Returns a string message saying the order quantity is less than the lot size for the given security
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string OrderQuantityLessThanLotSize(Securities.Security security)
{
return Invariant($@"The order quantity is less than the lot size of {
security.SymbolProperties.LotSize} and has been rounded to zero.");
}
/// <summary>
/// Returns a string message containing information about the target order value, the order fees and
/// the order quantity
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string OrderQuantityLessThanLotSizeOrderDetails(decimal targetOrderValue, decimal orderQuantity, decimal orderFees)
{
return Invariant($"Target order value {targetOrderValue}. Order fees {orderFees}. Order quantity {orderQuantity}.");
}
/// <summary>
/// Returns a string message saying GetMaximumOrderQuantityForTargetBuyingPower failed to converge to
/// the given target order value
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string FailedToConvergeOnTargetOrderValue(decimal targetOrderValue, decimal currentOrderValue, decimal orderQuantity,
decimal orderFees, Securities.Security security)
{
return Invariant($@"GetMaximumOrderQuantityForTargetBuyingPower failed to converge to target order value {
targetOrderValue}. Current order value is {currentOrderValue}. Order quantity {orderQuantity}. Lot size is {
security.SymbolProperties.LotSize}. Order fees {orderFees}. Security symbol {security.Symbol}");
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.DefaultMarginCallModel"/> class and its consumers or related classes
/// </summary>
public static class DefaultMarginCallModel
{
/// <summary>
/// String message saying: Margin Call
/// </summary>
public static string MarginCallOrderTag = "Margin Call";
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.DynamicSecurityData"/> class and its consumers or related classes
/// </summary>
public static class DynamicSecurityData
{
/// <summary>
/// String message saying: DynamicSecurityData is a view of the SecurityCache. It is readonly, properties can not bet set
/// </summary>
public static string PropertiesCannotBeSet =
"DynamicSecurityData is a view of the SecurityCache. It is readonly, properties can not be set";
/// <summary>
/// Returns a string message saying no property exists with the given name
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string PropertyNotFound(string name)
{
return $"Property with name '{name}' does not exist.";
}
/// <summary>
/// Returns a string message saying a list of the given type was expected but the one found was of the given data type
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string UnexpectedTypesForGetAll(Type type, object data)
{
return $"Expected a list with type '{type.GetBetterTypeName()}' but found type '{data.GetType().GetBetterTypeName()}";
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.EquityPriceVariationModel"/> class and its consumers or related classes
/// </summary>
public static class EquityPriceVariationModel
{
/// <summary>
/// Returns a string message saying the type of the given security was invalid
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string InvalidSecurityType(Securities.Security security)
{
return Invariant($"Invalid SecurityType: {security.Type}");
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.ErrorCurrencyConverter"/> class and its consumers or related classes
/// </summary>
public static class ErrorCurrencyConverter
{
/// <summary>
/// String message saying: Unexpected usage of ErrorCurrencyConverter.AccountCurrency
/// </summary>
public static string AccountCurrencyUnexpectedUsage = "Unexpected usage of ErrorCurrencyConverter.AccountCurrency";
/// <summary>
/// String message saying: This method purposefully throws as a proof that a test does not depend on a currency converter
/// </summary>
public static string ConvertToAccountCurrencyPurposefullyThrow =
$@"This method purposefully throws as a proof that a test does not depend on {
nameof(ICurrencyConverter)}. If this exception is encountered, it means the test DOES depend on {
nameof(ICurrencyConverter)} and should be properly updated to use a real implementation of {nameof(ICurrencyConverter)}.";
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.FuncSecuritySeeder"/> class and its consumers or related classes
/// </summary>
public static class FuncSecuritySeeder
{
/// <summary>
/// Returns a string message with basic information about the given BaseData object
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string SeededSecurityInfo(BaseData seedData)
{
return $"Seeded security: {seedData.Symbol.Value}: {seedData.GetType()} {seedData.Value}";
}
/// <summary>
/// Returns a string message saying it was impossible to seed the given security
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string UnableToSeedSecurity(Securities.Security security)
{
return $"Unable to seed security: {security.Symbol.Value}";
}
/// <summary>
/// Returns a string message saying it was impossible to seed price for the given security
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string UnableToSecurityPrice(Securities.Security security)
{
return $"Could not seed price for security {security.Symbol}";
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.IdentityCurrencyConverter"/> class and its consumers or related classes
/// </summary>
public static class IdentityCurrencyConverter
{
/// <summary>
/// String message saying: The IdentityCurrencyConverter can only handle CashAmounts in units of the account currency
/// </summary>
public static string UnableToHandleCashInNonAccountCurrency =
$"The {nameof(Securities.IdentityCurrencyConverter)} can only handle CashAmounts in units of the account currency";
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.InitialMarginParameters"/> class and its consumers or related classes
/// </summary>
public static class InitialMarginParameters
{
/// <summary>
/// String message saying: ForUnderlying is only invokable for IDerivativeSecurity (Option|Future)
/// </summary>
public static string ForUnderlyingOnlyInvokableForIDerivativeSecurity =
"ForUnderlying is only invokable for IDerivativeSecurity (Option|Future)";
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.LocalMarketHours"/> class and its consumers or related classes
/// </summary>
public static class LocalMarketHours
{
/// <summary>
/// Parses the given LocalMarketHours object into a string message containing basic information about it
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ToString(Securities.LocalMarketHours instance)
{
if (instance.IsClosedAllDay)
{
return "Closed All Day";
}
if (instance.IsOpenAllDay)
{
return "Open All Day";
}
return Invariant($"{instance.DayOfWeek}: {string.Join(" | ", instance.Segments)}");
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.MaintenanceMarginParameters"/> class and its consumers or related classes
/// </summary>
public static class MaintenanceMarginParameters
{
/// <summary>
/// String message saying: ForUnderlying is only invokable for IDerivativeSecurity
/// </summary>
public static string ForUnderlyingOnlyInvokableForIDerivativeSecurity =
"ForUnderlying is only invokable for IDerivativeSecurity (Option|Future)";
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.MarketHoursDatabase"/> class and its consumers or related classes
/// </summary>
public static class MarketHoursDatabase
{
/// <summary>
/// String message saying: Future.Usa market type is no longer supported as we mapped each ticker to its actual exchange
/// </summary>
public static string FutureUsaMarketTypeNoLongerSupported =
"Future.Usa market type is no longer supported as we mapped each ticker to its actual exchange. " +
"Please find your specific market in the symbol-properties database.";
/// <summary>
/// Returns a string message saying it was impossible to locate exchange hours for the given key. It also
/// mentiones the available keys
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ExchangeHoursNotFound(Securities.SecurityDatabaseKey key,
IEnumerable<Securities.SecurityDatabaseKey> availableKeys = null)
{
var keys = "";
if (availableKeys != null)
{
keys = " Available keys: " + string.Join(", ", availableKeys);
}
return $"Unable to locate exchange hours for {key}.{keys}";
}
/// <summary>
/// Returns a string message that suggests the given market based on the provided ticker
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string SuggestedMarketBasedOnTicker(string market)
{
return $"Suggested market based on the provided ticker 'Market.{market.ToUpperInvariant()}'.";
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.MarketHoursSegment"/> class and its consumers or related classes
/// </summary>
public static class MarketHoursSegment
{
/// <summary>
/// String message saying: Extended market open time must be less than or equal to market open time
/// </summary>
public static string InvalidExtendedMarketOpenTime = "Extended market open time must be less than or equal to market open time.";
/// <summary>
/// String message saying: Market close time must be after market open time
/// </summary>
public static string InvalidMarketCloseTime = "Market close time must be after market open time.";
/// <summary>
/// String message saying: Extended market close time must be greater than or equal to market close time
/// </summary>
public static string InvalidExtendedMarketCloseTime = "Extended market close time must be greater than or equal to market close time.";
/// <summary>
/// Parses a MarketHourSegment object into a string message containing basic information about it
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ToString(Securities.MarketHoursSegment instance)
{
return $"{instance.State}: {instance.Start.ToStringInvariant(null)}-{instance.End.ToStringInvariant(null)}";
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.RegisteredSecurityDataTypesProvider"/> class and its consumers or related classes
/// </summary>
public static class RegisteredSecurityDataTypesProvider
{
/// <summary>
/// Returns a string message saying two different types were detected trying to register the same type name. It also
/// mentions the two different types
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string TwoDifferentTypesDetectedForTheSameTypeName(Type type, Type existingType)
{
return $"Two different types were detected trying to register the same type name: {existingType} - {type}";
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.Security"/> class and its consumers or related classes
/// </summary>
public static class Security
{
/// <summary>
/// String message saying: Security requires a valid SymbolProperties instance
/// </summary>
public static string ValidSymbolPropertiesInstanceRequired = "Security requires a valid SymbolProperties instance.";
/// <summary>
/// String message saying: symbolProperties.QuoteCurrency must match the quoteCurrency.Symbol
/// </summary>
public static string UnmatchingQuoteCurrencies = "symbolProperties.QuoteCurrency must match the quoteCurrency.Symbol";
/// <summary>
/// String message saying: Security.SetLocalTimeKeeper(LocalTimeKeeper) must be called in order to use the LocalTime property
/// </summary>
public static string SetLocalTimeKeeperMustBeCalledBeforeUsingLocalTime =
"Security.SetLocalTimeKeeper(LocalTimeKeeper) must be called in order to use the LocalTime property.";
/// <summary>
/// String message saying: Symbols must match
/// </summary>
public static string UnmatchingSymbols = "Symbols must match.";
/// <summary>
/// String message saying: ExchangeTimeZones must match
/// </summary>
public static string UnmatchingExchangeTimeZones = "ExchangeTimeZones must match.";
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.SecurityDatabaseKey"/> class and its consumers or related classes
/// </summary>
public static class SecurityDatabaseKey
{
/// <summary>
/// Returns a string message saying the specified and given key was not in the expected format
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string KeyNotInExpectedFormat(string key)
{
return $"The specified key was not in the expected format: {key}";
}
/// <summary>
/// Parses a SecurityDatabaseKey into a string message with basic information about it
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ToString(Securities.SecurityDatabaseKey instance)
{
return Invariant($"{instance.SecurityType}-{instance.Market}-{instance.Symbol}");
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.SecurityDefinitionSymbolResolver"/> class and its consumers or related classes
/// </summary>
public static class SecurityDefinitionSymbolResolver
{
/// <summary>
/// Returns a string message saying no security definitions data have been loaded from the given file
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string NoSecurityDefinitionsLoaded(string securitiesDefinitionKey)
{
return $"No security definitions data loaded from file: {securitiesDefinitionKey}";
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.SecurityExchangeHours"/> class and its consumers or related classes
/// </summary>
public static class SecurityExchangeHours
{
/// <summary>
/// Returns an error message when the next market open could not be located within two weeks.
/// Includes additional guidance if the market is always open (e.g., crypto assets).
/// </summary>
public static string UnableToLocateNextMarketOpenInTwoWeeks(bool isMarketAlwaysOpen)
{
var message = "Unable to locate next market open within two weeks.";
if (!isMarketAlwaysOpen)
{
return message;
}
message += " Market is always open for this asset, this can happen e.g. if using TimeRules AfterMarketOpen for a crypto asset. " +
"An alternative would be TimeRules.At(), TimeRules.Every(), TimeRules.Midnight or TimeRules.Noon instead";
return message;
}
/// <summary>
/// Returns an error message when the next market close could not be located within two weeks.
/// Includes additional guidance if the market is always open (e.g., crypto assets).
/// </summary>
public static string UnableToLocateNextMarketCloseInTwoWeeks(bool isMarketAlwaysOpen)
{
var message = "Unable to locate next market close within two weeks.";
if (!isMarketAlwaysOpen)
{
return message;
}
message += " Market is always open for this asset, this can happen e.g. if using TimeRules BeforeMarketClose for a crypto asset. " +
"An alternative would be TimeRules.At(), TimeRules.Every(), TimeRules.Midnight or TimeRules.Noon instead";
return message;
}
/// <summary>
/// Returns a string message saying it did not find last market open for the given local date time. It also mentions
/// if the market is always open or not
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string LastMarketOpenNotFound(DateTime localDateTime, bool isMarketAlwaysOpen)
{
return $"Did not find last market open for {localDateTime}. IsMarketAlwaysOpen: {isMarketAlwaysOpen}";
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.SecurityHolding"/> class and its consumers or related classes
/// </summary>
public static class SecurityHolding
{
/// <summary>
/// Parses the given SecurityHolding object into a string message containing basic information about it
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ToString(Securities.SecurityHolding instance)
{
return Invariant($"{instance.Symbol.Value}: {instance.Quantity} @ {instance.AveragePrice}");
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.SecurityManager"/> class and its consumers or related classes
/// </summary>
public static class SecurityManager
{
/// <summary>
/// Returns a string message saying the given symbol was not found in the user security list
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string SymbolNotFoundInSecurities(QuantConnect.Symbol symbol)
{
return Invariant($@"This asset symbol ({
symbol}) was not found in your security list. Please add this security or check it exists before using it with 'Securities.ContainsKey(""{
QuantConnect.SymbolCache.GetTicker(symbol)}"")'");
}
/// <summary>
/// Returns a string message saying the given symbol could not be overwritten
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string UnableToOverwriteSecurity(QuantConnect.Symbol symbol)
{
return Invariant($"Unable to overwrite existing Security: {symbol}");
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.SecurityPortfolioManager"/> class and its consumers or related classes
/// </summary>
public static class SecurityPortfolioManager
{
/// <summary>
/// Returns a string message saying Portfolio object is an adaptor for Security Manager and that to add a new asset
/// the required data should added during initialization
/// </summary>
public static string DictionaryAddNotImplemented =
"Portfolio object is an adaptor for Security Manager. To add a new asset add the required data during initialization.";
/// <summary>
/// Returns a string message saying the Portfolio object object is an adaptor for Security Manager and cannot be cleared
/// </summary>
public static string DictionaryClearNotImplemented = "Portfolio object is an adaptor for Security Manager and cannot be cleared.";
/// <summary>
/// Returns a string message saying the Portfolio object is an adaptor for Security Manager and objects cannot be removed
/// </summary>
public static string DictionaryRemoveNotImplemented = "Portfolio object is an adaptor for Security Manager and objects cannot be removed.";
/// <summary>
/// Returns a string message saying the AccountCurrency cannot be changed after adding a Security and that the method
/// SetAccountCurrency() should be moved before AddSecurity()
/// </summary>
public static string CannotChangeAccountCurrencyAfterAddingSecurity =
"Cannot change AccountCurrency after adding a Security. Please move SetAccountCurrency() before AddSecurity().";
/// <summary>
/// Returns a string message saying the AccountCurrency cannot be changed after setting cash and that the method
/// SetAccountCurrency() should be moved before SetCash()
/// </summary>
public static string CannotChangeAccountCurrencyAfterSettingCash =
"Cannot change AccountCurrency after setting cash. Please move SetAccountCurrency() before SetCash().";
/// <summary>
/// Returns a string message saying the AccountCurrency has been changed after setting cash, reporting the
/// remaining amount held in the previous account currency
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string AccountCurrencyChangedAfterSettingCash(Securities.Cash previousCash)
{
return Invariant($"Account currency was changed after SetCash() was called. Algorithm still holds {previousCash.Amount} {previousCash.Symbol} in the previous account currency.");
}
/// <summary>
/// Returns a string message saying the account currency starting cash has been updated from a previous amount to a new one
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string AccountCurrencyCashUpdated(string accountCurrency, decimal previousAmount, decimal newAmount)
{
return Invariant($"Account currency cash updated to {newAmount} {accountCurrency} from {previousAmount} {accountCurrency}.");
}
/// <summary>
/// Returns a string message saying the AccountCurrency has already been set and that the new value for this property
/// will be ignored
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string AccountCurrencyAlreadySet(Securities.CashBook cashBook, string newAccountCurrency)
{
return $"account currency has already been set to {cashBook.AccountCurrency}. Will ignore new value {newAccountCurrency}";
}
/// <summary>
/// Returns a string message saying the AccountCurrency is being set to the given account currency
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string SettingAccountCurrency(string accountCurrency)
{
return $"setting account currency to {accountCurrency}";
}
/// <summary>
/// Returns a string message saying the total margin information, this is, the total margin used as well as the
/// margin remaining
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string TotalMarginInformation(decimal totalMarginUsed, decimal marginRemaining)
{
return Invariant($"Total margin information: TotalMarginUsed: {totalMarginUsed:F2}, MarginRemaining: {marginRemaining:F2}");
}
/// <summary>
/// Returns a string message saying the order request margin information, this is, the margin used and the margin remaining
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string OrderRequestMarginInformation(decimal marginUsed, decimal marginRemaining)
{
return Invariant($"Order request margin information: MarginUsed: {marginUsed:F2}, MarginRemaining: {marginRemaining:F2}");
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.SecurityService"/> class and its consumers or related classes
/// </summary>
public static class SecurityService
{
/// <summary>
/// Returns a string message saying the given Symbol could not be found in the Symbol Properties Database
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string SymbolNotFoundInSymbolPropertiesDatabase(QuantConnect.Symbol symbol)
{
return $"{symbol.SecurityType} '{symbol.Value}' symbol could not be found in the database for {symbol.ID.Market} market";
}
}
/// <summary>
/// Provides user-facing messages for the <see cref="Securities.SecurityTransactionManager"/> class and its consumers or related classes
/// </summary>
public static class SecurityTransactionManager
{
/// <summary>
/// Returns a string message saying CancelOpenOrders operation is not allowed in Initialize or during warm up
/// </summary>
public static string CancelOpenOrdersNotAllowedOnInitializeOrWarmUp =
"This operation is not allowed in Initialize or during warm up: CancelOpenOrders. Please move this code to the OnWarmupFinished() method.";
/// <summary>
/// Returns a string message saying the order was canceled by the CancelOpenOrders() at the given time
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string OrderCanceledByCancelOpenOrders(DateTime time)
{
return Invariant($"Canceled by CancelOpenOrders() at {time:o}");
}
/// <summary>
/// Returns a string message saying the ticket for the given order ID could not be localized
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string UnableToLocateOrderTicket(int orderId)
{
return Invariant($"Unable to locate ticket for order: {orderId}");
}