Skip to content

Commit

Permalink
Merge pull request #23 from spacious-team/develop
Browse files Browse the repository at this point in the history
Релиз 2021.11
  • Loading branch information
vananiev authored Dec 29, 2021
2 parents b43bb6f + 22d3bea commit f34fec5
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 92 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.18</version>
<version>1.18.22</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
Expand All @@ -86,13 +86,13 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.0</version>
<version>2.13.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.1.6</version>
<version>2.1.11</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/org/spacious_team/broker/pojo/Security.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@
@EqualsAndHashCode(cacheStrategy = LAZY)
@Schema(name = "Инструмент", description = "Акция, облигация, валютная пара, фьючерс или опцион")
public class Security {
// update to nullable after change to Integer
//@Nullable // autoincrement
@Schema(description = "Внутренний идентификатор инструмента", example = "123", required = true)
private final Integer id;

@NotNull
@Schema(description = "Внутренний идентификатор инструмента (для акций и облигаций - ISIN, валютный пары и срочных контрактов - название)",
example = "NL0009805522, USDRUB_TOM или Si-12.21", required = true)
private final String id;
@Schema(description = "Тип ценной бумаги", example = "STOCK", required = true)
private final SecurityType type;

//@Nullable
@Schema(description = "ISIN акций и облигаций (опционально)", example = "NL0009805522", nullable = true)
private final String isin;

//@Nullable
@Schema(description = "Тикер (опционально)", example = "YNDX", nullable = true)
@Schema(description = "Тикер (опционально)", example = "YNDX, USDRUB_TOM или Si-12.21", nullable = true)
private final String ticker;

//@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
@Schema(name = "Свойства инструмента", description = "Информация об инструменте")
public class SecurityDescription {
@NotNull
@Schema(description = "Внутренний идентификатор инструмента", example = "NL0009805522, USDRUB_TOM или Si-12.21", required = true)
private final String security;
@Schema(description = "Внутренний идентификатор инструмента", example = "123", required = true)
private final int security;

//@Nullable
@Schema(description = "Сектор экономики (опционально)", example = "Финансы", nullable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public class SecurityEventCashFlow {
private final Instant timestamp;

@NotNull
@Schema(description = "Инструмент", example = "NL0009805522", required = true)
private final String security;
@Schema(description = "Инструмент", example = "123", required = true)
private final int security;

@NotNull
@Schema(description = "Количество бумаг (контрактов)", example = "10", required = true)
Expand All @@ -81,7 +81,7 @@ public static boolean checkEquality(SecurityEventCashFlow cash1, SecurityEventCa
return cash1.getPortfolio().equals(cash2.getPortfolio()) &&
cash1.getTimestamp().equals(cash2.getTimestamp()) &&
cash1.getEventType().equals(cash2.getEventType()) &&
cash1.getSecurity().equals(cash2.getSecurity());
cash1.getSecurity() == cash2.getSecurity();
}

/**
Expand Down
23 changes: 10 additions & 13 deletions src/main/java/org/spacious_team/broker/pojo/SecurityQuote.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public class SecurityQuote {
private final Integer id;

@NotNull
@Schema(description = "Инструмент", example = "NL0009805522", required = true)
private final String security;
@Schema(description = "Инструмент", example = "123", required = true)
private final int security;

@NotNull
@Schema(description = "Время", example = "2021-01-01T19:00:00+03:00", required = true)
Expand Down Expand Up @@ -78,16 +78,13 @@ public class SecurityQuote {
*/
@JsonIgnore
@Schema(hidden = true)
public BigDecimal getCleanPriceInCurrency() {
SecurityType type = SecurityType.getSecurityType(security);
if (type == DERIVATIVE) {
return price;
public BigDecimal getCleanPriceInCurrency(boolean isDerivative) {
if (isDerivative) {
return price; // for future and option always use price, also in case of price == null
} else if (price == null && accruedInterest == null) {
return quote; // for stocks, currency pairs, asset
} else {
if (price == null && accruedInterest == null) {
return quote; // for stocks, currency pairs, asset
} else {
return price; // for bonds
}
return price; // for bonds
}
}

Expand All @@ -96,8 +93,8 @@ public BigDecimal getCleanPriceInCurrency() {
*/
@JsonIgnore
@Schema(hidden = true)
public BigDecimal getDirtyPriceInCurrency() {
BigDecimal cleanPrice = getCleanPriceInCurrency();
public BigDecimal getDirtyPriceInCurrency(boolean isDerivative) {
BigDecimal cleanPrice = getCleanPriceInCurrency(isDerivative);
return (cleanPrice == null || accruedInterest == null) ? cleanPrice : cleanPrice.add(accruedInterest);
}
}
30 changes: 10 additions & 20 deletions src/main/java/org/spacious_team/broker/pojo/SecurityType.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,14 @@ public enum SecurityType {

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

public static final String ASSET_PREFIX = "ASSET:";
@Getter
private final String description;

public static SecurityType getSecurityType(Security security) {
return getSecurityType(security.getId());
}

public static SecurityType getSecurityType(String security) {
int length = security.length();
if (length == 12 && security.indexOf('-') == -1) {
return STOCK_OR_BOND;
} else if (length == 6 || (length > 7 && security.charAt(6) == '_')) { // USDRUB_TOM or USDRUB_TOD or USDRUB
return CURRENCY_PAIR;
} else if (security.startsWith(ASSET_PREFIX)) {
return ASSET;
}
// фьючерс всегда с дефисом, например Si-12.21, опцион может быть MXI-6.21M170621CA3000 или MM3000BF1
return DERIVATIVE;
}

/**
* Returns currency pairs, for example USDRUB, EURRUB
*/
Expand All @@ -63,4 +45,12 @@ public static String getCurrencyPair(String contract) {
public boolean isStockOrBond() {
return this == STOCK || this == BOND || this == STOCK_OR_BOND;
}

public boolean isStock() {
return this == STOCK || this == STOCK_OR_BOND;
}

public boolean isBond() {
return this == BOND || this == STOCK_OR_BOND;
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/spacious_team/broker/pojo/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public class Transaction {
private final String portfolio;

@NotNull
@Schema(description = "Инструмент", example = "NL0009805522", required = true)
private final String security;
@Schema(description = "Инструмент", example = "123", required = true)
private final int security;

@NotNull
@Schema(description = "Время сделки", example = "2021-01-23T12:00:00+03:00", required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class TransactionCashFlow {
@NotNull
@JsonProperty("transaction-id")
@Schema(description = "Внутренний идентификатор сделки", example = "123", required = true)
private final Integer transactionId;
private final int transactionId;

@NotNull
@JsonProperty("event-type")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public abstract class AbstractBrokerReportFactory implements BrokerReportFactory
/**
* @param expectedFileNamePattern used for fast report check without input stream reading
*/
protected boolean canCreate(Pattern expectedFileNamePattern, String excelFileName, InputStream is) {
return expectedFileNamePattern.matcher(excelFileName).matches();
protected boolean canCreate(Pattern expectedFileNamePattern, String fileName, InputStream is) {
return expectedFileNamePattern.matcher(fileName).matches();
}

/**
Expand All @@ -40,7 +40,7 @@ protected boolean canCreate(Pattern expectedFileNamePattern, String excelFileNam
* @return broker report if can parse or null
* @throws IllegalArgumentException if InputStream is not supports mark
*/
protected BrokerReport create(String excelFileName,
protected BrokerReport create(String fileName,
InputStream is,
BiFunction<String, InputStream, BrokerReport> brokerReportProvider) {
if (!is.markSupported()) {
Expand All @@ -50,7 +50,7 @@ protected BrokerReport create(String excelFileName,
is.mark(Integer.MAX_VALUE);
Exception exception = null;
try {
return brokerReportProvider.apply(excelFileName, is);
return brokerReportProvider.apply(fileName, is);
} catch (Exception e) {
exception = e;
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
import static lombok.EqualsAndHashCode.CacheStrategy.LAZY;

@Getter
@SuperBuilder
@SuperBuilder(toBuilder = true)
@ToString
@EqualsAndHashCode(cacheStrategy = LAZY)
public abstract class AbstractTransaction {
protected static final BigDecimal minValue = BigDecimal.valueOf(0.01);
protected final Integer id;
protected final String tradeId;
protected final String portfolio;
protected final String security;
protected final int security;
protected final Instant timestamp;
protected final int count;
protected final BigDecimal value; // стоиомсть в валюце цены
Expand Down Expand Up @@ -92,4 +92,6 @@ protected Optional<TransactionCashFlow> getCommissionCashFlow() {
}
return Optional.empty();
}

public abstract AbstractTransactionBuilder<? extends AbstractTransaction, ? extends AbstractTransactionBuilder<?, ?>> toBuilder();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public interface BrokerReportFactory {
* @return false when can't parse, true when parsing maybe possible
* @throws IllegalArgumentException if InputStream is not supports mark
*/
boolean canCreate(String excelFileName, InputStream is);
boolean canCreate(String fileName, InputStream is);

/**
* Checks input stream and returns broker report if can, otherwise reset input stream mark to original position
* and returns null
* @return broker report if can parse or null
* @throws IllegalArgumentException if InputStream is not supports mark
*/
BrokerReport create(String excelFileName, InputStream is);
BrokerReport create(String fileName, InputStream is);

String getBrokerName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import static lombok.EqualsAndHashCode.CacheStrategy.LAZY;

@Getter
@SuperBuilder
@SuperBuilder(toBuilder = true)
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true, cacheStrategy = LAZY)
public class DerivativeTransaction extends AbstractTransaction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import static lombok.EqualsAndHashCode.CacheStrategy.LAZY;

@SuperBuilder
@SuperBuilder(toBuilder = true)
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true, cacheStrategy = LAZY)
public class ForeignExchangeTransaction extends AbstractTransaction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import static lombok.EqualsAndHashCode.CacheStrategy.LAZY;

@Getter
@SuperBuilder
@SuperBuilder(toBuilder = true)
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true, cacheStrategy = LAZY)
public class SecurityTransaction extends AbstractTransaction {
Expand Down
Loading

0 comments on commit f34fec5

Please sign in to comment.