2424@ RequiredArgsConstructor
2525public enum SecurityType {
2626
27- STOCK_OR_BOND ("акция/облигация" ),
27+ STOCK ("акция" ),
28+ BOND ("облигация" ),
29+ STOCK_OR_BOND ("акция/облигация" ), // нельзя сказать точно акция или облигация
2830 DERIVATIVE ("срочный контракт" ),
29- CURRENCY_PAIR ("валюта" );
31+ CURRENCY_PAIR ("валюта" ),
32+ ASSET ("произвольный актив" );
3033
3134 @ Getter
3235 private final String description ;
@@ -35,15 +38,20 @@ public static SecurityType getSecurityType(Security security) {
3538 return getSecurityType (security .getId ());
3639 }
3740
41+ /**
42+ * Для правильного определения дериватива наименование должно быть представлено в полном формате с дефисом, например "Si-3.22"
43+ */
3844 public static SecurityType getSecurityType (String security ) {
3945 int length = security .length ();
40- if (length == 12 && security .indexOf ('-' ) == -1 ) {
46+ int dashPosition = security .indexOf ('-' );
47+ if (length == 12 && dashPosition == -1 ) {
4148 return STOCK_OR_BOND ;
4249 } else if (length == 6 || (length > 7 && security .charAt (6 ) == '_' )) { // USDRUB_TOM or USDRUB_TOD or USDRUB
4350 return CURRENCY_PAIR ;
44- } else {
51+ } else if ( dashPosition != - 1 ) {
4552 return DERIVATIVE ;
4653 }
54+ return ASSET ;
4755 }
4856
4957 /**
@@ -53,4 +61,8 @@ public static String getCurrencyPair(String contract) {
5361 return (contract .length () == 6 ) ? contract :
5462 contract .substring (0 , Math .min (6 , contract .length ()));
5563 }
64+
65+ public boolean isStockOrBond () {
66+ return this == STOCK || this == BOND || this == STOCK_OR_BOND ;
67+ }
5668}
0 commit comments