Skip to content

Commit b397f10

Browse files
authored
Merge pull request #20 from spacious-team/imvestbook-gh-380
Не определять тип ЦБ по ее id
2 parents d647fbb + 31abf18 commit b397f10

File tree

5 files changed

+28
-37
lines changed

5 files changed

+28
-37
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 & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,13 @@ public class SecurityQuote {
7878
*/
7979
@JsonIgnore
8080
@Schema(hidden = true)
81-
public BigDecimal getCleanPriceInCurrency() {
82-
SecurityType type = SecurityType.getSecurityType(security);
83-
if (type == DERIVATIVE) {
84-
return price;
81+
public BigDecimal getCleanPriceInCurrency(boolean isDerivative) {
82+
if (isDerivative) {
83+
return price; // for future and option always use price, also in case of price == null
84+
} else if (price == null && accruedInterest == null) {
85+
return quote; // for stocks, currency pairs, asset
8586
} else {
86-
if (price == null && accruedInterest == null) {
87-
return quote; // for stocks, currency pairs, asset
88-
} else {
89-
return price; // for bonds
90-
}
87+
return price; // for bonds
9188
}
9289
}
9390

@@ -96,8 +93,8 @@ public BigDecimal getCleanPriceInCurrency() {
9693
*/
9794
@JsonIgnore
9895
@Schema(hidden = true)
99-
public BigDecimal getDirtyPriceInCurrency() {
100-
BigDecimal cleanPrice = getCleanPriceInCurrency();
96+
public BigDecimal getDirtyPriceInCurrency(boolean isDerivative) {
97+
BigDecimal cleanPrice = getCleanPriceInCurrency(isDerivative);
10198
return (cleanPrice == null || accruedInterest == null) ? cleanPrice : cleanPrice.add(accruedInterest);
10299
}
103100
}

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
}

src/main/java/org/spacious_team/broker/report_parser/api/AbstractBrokerReportFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public abstract class AbstractBrokerReportFactory implements BrokerReportFactory
2929
/**
3030
* @param expectedFileNamePattern used for fast report check without input stream reading
3131
*/
32-
protected boolean canCreate(Pattern expectedFileNamePattern, String excelFileName, InputStream is) {
33-
return expectedFileNamePattern.matcher(excelFileName).matches();
32+
protected boolean canCreate(Pattern expectedFileNamePattern, String fileName, InputStream is) {
33+
return expectedFileNamePattern.matcher(fileName).matches();
3434
}
3535

3636
/**
@@ -40,7 +40,7 @@ protected boolean canCreate(Pattern expectedFileNamePattern, String excelFileNam
4040
* @return broker report if can parse or null
4141
* @throws IllegalArgumentException if InputStream is not supports mark
4242
*/
43-
protected BrokerReport create(String excelFileName,
43+
protected BrokerReport create(String fileName,
4444
InputStream is,
4545
BiFunction<String, InputStream, BrokerReport> brokerReportProvider) {
4646
if (!is.markSupported()) {
@@ -50,7 +50,7 @@ protected BrokerReport create(String excelFileName,
5050
is.mark(Integer.MAX_VALUE);
5151
Exception exception = null;
5252
try {
53-
return brokerReportProvider.apply(excelFileName, is);
53+
return brokerReportProvider.apply(fileName, is);
5454
} catch (Exception e) {
5555
exception = e;
5656
return null;

src/main/java/org/spacious_team/broker/report_parser/api/BrokerReportFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ public interface BrokerReportFactory {
2828
* @return false when can't parse, true when parsing maybe possible
2929
* @throws IllegalArgumentException if InputStream is not supports mark
3030
*/
31-
boolean canCreate(String excelFileName, InputStream is);
31+
boolean canCreate(String fileName, InputStream is);
3232

3333
/**
3434
* Checks input stream and returns broker report if can, otherwise reset input stream mark to original position
3535
* and returns null
3636
* @return broker report if can parse or null
3737
* @throws IllegalArgumentException if InputStream is not supports mark
3838
*/
39-
BrokerReport create(String excelFileName, InputStream is);
39+
BrokerReport create(String fileName, InputStream is);
4040

4141
String getBrokerName();
4242
}

0 commit comments

Comments
 (0)