Skip to content

Commit

Permalink
Merge pull request #17 from spacious-team/develop
Browse files Browse the repository at this point in the history
Релиз 2021.9
  • Loading branch information
vananiev authored Nov 21, 2021
2 parents 87346ab + 9bfbe74 commit dcbe3d5
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<groupId>org.spacious-team</groupId>
<artifactId>broker-report-parser-api</artifactId>
<version>2021.8</version>
<version>2021.9</version>
<packaging>jar</packaging>

<name>Broker Report Parser API</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

public enum PortfolioPropertyType {
TOTAL_ASSETS_RUB,
TOTAL_ASSETS_USD, // use one of TOTAL_ASSETS_RUB or TOTAL_ASSETS_USD
TOTAL_ASSETS_USD, // if TOTAL_ASSETS_RUB and TOTAL_ASSETS_USD exists for same date, total assets is sum of them
CASH
}
8 changes: 7 additions & 1 deletion src/main/java/org/spacious_team/broker/pojo/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.spacious_team.broker.pojo;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.EqualsAndHashCode;
Expand All @@ -37,9 +38,14 @@
@EqualsAndHashCode(cacheStrategy = LAZY)
@Schema(name = "Сделка")
public class Transaction {
//@Nullable // autoincrement
@Schema(description = "Внутренний идентификатор сделки", example = "123", required = true)
private final Integer id;

@NotNull
@JsonProperty("trade-id")
@Schema(description = "Номер сделки в системе учета брокера", example = "123SP", required = true)
private final String id;
private final String tradeId;

@NotNull
@Schema(description = "Номер счета в системе учета брокера", example = "10200I", required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
@EqualsAndHashCode(cacheStrategy = LAZY)
@Schema(name = "Движение ДС по сделке")
public class TransactionCashFlow {
@NotNull
@JsonProperty("transaction-id")
@Schema(description = "Номер сделки в системе учета брокера", example = "123SP", required = true)
private final String transactionId;
//@Nullable // autoincrement
@Schema(description = "Внутренний идентификатор записи", example = "1", required = true)
private final Integer id;

@NotNull
@Schema(description = "Номер счета в системе учета брокера", example = "10200I", required = true)
private final String portfolio;
@JsonProperty("transaction-id")
@Schema(description = "Внутренний идентификатор сделки", example = "123", required = true)
private final Integer transactionId;

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
@EqualsAndHashCode(cacheStrategy = LAZY)
public abstract class AbstractTransaction {
protected static final BigDecimal minValue = BigDecimal.valueOf(0.01);
protected final String transactionId;
protected final Integer id;
protected final String tradeId;
protected final String portfolio;
protected final String security;
protected final Instant timestamp;
Expand All @@ -52,7 +53,8 @@ public abstract class AbstractTransaction {

public Transaction getTransaction() {
return Transaction.builder()
.id(transactionId)
.id(id)
.tradeId(tradeId)
.portfolio(portfolio)
.security(security)
.timestamp(timestamp)
Expand All @@ -70,8 +72,7 @@ public List<TransactionCashFlow> getTransactionCashFlows() {
protected Optional<TransactionCashFlow> getValueCashFlow(CashFlowType type) {
if (value != null && value.abs().compareTo(minValue) >= 0) {
return Optional.of(TransactionCashFlow.builder()
.transactionId(transactionId)
.portfolio(portfolio)
.transactionId(id)
.eventType(type)
.value(value)
.currency(valueCurrency)
Expand All @@ -83,8 +84,7 @@ protected Optional<TransactionCashFlow> getValueCashFlow(CashFlowType type) {
protected Optional<TransactionCashFlow> getCommissionCashFlow() {
if (commission != null && commission.abs().compareTo(minValue) >= 0) {
return Optional.of(TransactionCashFlow.builder()
.transactionId(transactionId)
.portfolio(portfolio)
.transactionId(id)
.eventType(CashFlowType.COMMISSION)
.value(commission)
.currency(commissionCurrency)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@

public interface BrokerReportFactory {

/**
* Fast check if this factory can't parse report.
* Method should always reset input stream mark to original position.
* @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);

/**
* Checks input stream and returns broker report if can, otherwise reset input stream mark to original position
* and returns null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public List<TransactionCashFlow> getTransactionCashFlows() {
protected Optional<TransactionCashFlow> getValueInPointsCashFlow() {
if (valueInPoints != null) {
return Optional.of(TransactionCashFlow.builder()
.transactionId(transactionId)
.portfolio(portfolio)
.transactionId(id)
.eventType(CashFlowType.DERIVATIVE_QUOTE)
.value(valueInPoints)
.currency(QUOTE_CURRENCY)
Expand All @@ -65,8 +64,7 @@ protected Optional<TransactionCashFlow> getValueInPointsCashFlow() {
protected Optional<TransactionCashFlow> getValueCashFlow(CashFlowType type) {
if (value != null) {
return Optional.of(TransactionCashFlow.builder()
.transactionId(transactionId)
.portfolio(portfolio)
.transactionId(id)
.eventType(type)
.value(value)
.currency(valueCurrency)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ private Optional<TransactionCashFlow> getAccruedInterestCashFlow() {
// for securities accrued interest = 0
if (accruedInterest != null && accruedInterest.abs().compareTo(minValue) >= 0) {
return Optional.of(TransactionCashFlow.builder()
.transactionId(transactionId)
.portfolio(portfolio)
.transactionId(id)
.eventType(CashFlowType.ACCRUED_INTEREST)
.value(accruedInterest)
.currency(valueCurrency)
Expand Down

0 comments on commit dcbe3d5

Please sign in to comment.