Skip to content

Commit 9a93e1a

Browse files
committed
remove SecurityType.getSecurity()
1 parent d647fbb commit 9a93e1a

File tree

3 files changed

+22
-27
lines changed

3 files changed

+22
-27
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public class Security {
4242
example = "NL0009805522, USDRUB_TOM или Si-12.21", required = true)
4343
private final String id;
4444

45+
@NotNull
46+
@Schema(description = "Тип ценной бумаги", example = "STOCK", required = true)
47+
private final SecurityType type;
48+
4549
//@Nullable
4650
@Schema(description = "ISIN акций и облигаций (опционально)", example = "NL0009805522", nullable = true)
4751
private final String isin;

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public class SecurityQuote {
5050
@Schema(description = "Инструмент", example = "NL0009805522", required = true)
5151
private final String security;
5252

53+
@NotNull
54+
@Schema(description = "Тип", example = "STOCK", required = true)
55+
private final SecurityType securityType;
56+
5357
@NotNull
5458
@Schema(description = "Время", example = "2021-01-01T19:00:00+03:00", required = true)
5559
private final Instant timestamp;
@@ -79,15 +83,12 @@ public class SecurityQuote {
7983
@JsonIgnore
8084
@Schema(hidden = true)
8185
public BigDecimal getCleanPriceInCurrency() {
82-
SecurityType type = SecurityType.getSecurityType(security);
83-
if (type == DERIVATIVE) {
86+
if (securityType == DERIVATIVE) {
8487
return price;
88+
} else if (price == null && accruedInterest == null) {
89+
return quote; // for stocks, currency pairs, asset
8590
} else {
86-
if (price == null && accruedInterest == null) {
87-
return quote; // for stocks, currency pairs, asset
88-
} else {
89-
return price; // for bonds
90-
}
91+
return price; // for bonds
9192
}
9293
}
9394

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

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,14 @@ public enum SecurityType {
2626

2727
STOCK("акция"),
2828
BOND("облигация"),
29-
STOCK_OR_BOND("акция/облигация"), // нельзя сказать точно акция или облигация
29+
STOCK_OR_BOND("акция/облигация"), // not exactly known: STOCK or BOND
3030
DERIVATIVE("срочный контракт"),
31-
CURRENCY_PAIR("валюта"),
31+
CURRENCY_PAIR("валютная пара"),
3232
ASSET("произвольный актив");
3333

34-
public static final String ASSET_PREFIX = "ASSET:";
3534
@Getter
3635
private final String description;
3736

38-
public static SecurityType getSecurityType(Security security) {
39-
return getSecurityType(security.getId());
40-
}
41-
42-
public static SecurityType getSecurityType(String security) {
43-
int length = security.length();
44-
if (length == 12 && security.indexOf('-') == -1) {
45-
return STOCK_OR_BOND;
46-
} else if (length == 6 || (length > 7 && security.charAt(6) == '_')) { // USDRUB_TOM or USDRUB_TOD or USDRUB
47-
return CURRENCY_PAIR;
48-
} else if (security.startsWith(ASSET_PREFIX)) {
49-
return ASSET;
50-
}
51-
// фьючерс всегда с дефисом, например Si-12.21, опцион может быть MXI-6.21M170621CA3000 или MM3000BF1
52-
return DERIVATIVE;
53-
}
54-
5537
/**
5638
* Returns currency pairs, for example USDRUB, EURRUB
5739
*/
@@ -63,4 +45,12 @@ public static String getCurrencyPair(String contract) {
6345
public boolean isStockOrBond() {
6446
return this == STOCK || this == BOND || this == STOCK_OR_BOND;
6547
}
48+
49+
public boolean isStock() {
50+
return this == STOCK || this == STOCK_OR_BOND;
51+
}
52+
53+
public boolean isBond() {
54+
return this == BOND || this == STOCK_OR_BOND;
55+
}
6656
}

0 commit comments

Comments
 (0)