Skip to content

Commit 89cc748

Browse files
committed
add security types: stock, bond, asset
1 parent 9bfbe74 commit 89cc748

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/main/java/org/spacious_team/broker/pojo/SecurityQuote.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class SecurityQuote {
5656

5757
@NotNull
5858
@Schema(description = "Котировка (для облигаций - в процентах, деривативы - в пунктах)", example = "4800.20", required = true)
59-
private final BigDecimal quote; // for stock and currency pair in currency, for bond - in percent, for derivative - in quote
59+
private final BigDecimal quote; // for stock, currency pair and asset in currency, for bond - in percent, for derivative - in quote
6060

6161
//@Nullable
6262
@Schema(description = "Котировка (в валюте, только для облигаций и деривативов)", example = "1020.30", nullable = true)
@@ -83,7 +83,7 @@ public BigDecimal getCleanPriceInCurrency() {
8383
return price;
8484
} else {
8585
if (price == null && accruedInterest == null) {
86-
return quote; // for stocks and currency pairs
86+
return quote; // for stocks, currency pairs, asset
8787
} else {
8888
return price; // for bonds
8989
}

src/main/java/org/spacious_team/broker/pojo/SecurityType.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424
@RequiredArgsConstructor
2525
public 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

Comments
 (0)