fixed TD ameritrade option parser; added logging
This commit is contained in:
parent
64a65e35ee
commit
818abea4dc
@ -47,14 +47,14 @@ public class CLI {
|
||||
static void help(Options options, String extraCommand, List<String> extraLines) {
|
||||
System.out.println("A set of Buxfer tools");
|
||||
System.out.print("usage: java -jar buxfer-cli-*.jar");
|
||||
System.out.print(" ( InvestDetail | InvestGL | Writer )");
|
||||
System.out.print(" ( InvestDetail | InvestPL | Writer )");
|
||||
if (extraCommand != null)
|
||||
System.out.print(" " + extraCommand);
|
||||
System.out.println();
|
||||
HelpFormatter help = new HelpFormatter();
|
||||
help.printOptions(new PrintWriter(System.out, true), 120, options, 3, 3);
|
||||
System.out.println("InvestDetail: Reformats descriptions and sets the appropriate transaction types for investments");
|
||||
System.out.println(" InvestGL: After 'InvestDetail', compute gains as transactions and reconcile");
|
||||
System.out.println(" InvestPL: After 'InvestDetail', compute profit/loss as transactions and reconciles where appropriate");
|
||||
System.out.println(" Writer: Writes transactions to external file");
|
||||
if (extraLines != null)
|
||||
for (String extraLine : extraLines)
|
||||
|
@ -78,7 +78,7 @@ public class InvestNormalizeCLI {
|
||||
"Investment / Security / " + ptx.getSecuritySymbol(), null);
|
||||
return 1;
|
||||
} catch (IllegalArgumentException iae) {
|
||||
logger.trace("failed to parse: " + iae.getMessage(), iae);
|
||||
logger.trace("failed to parse");
|
||||
// try another
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.inteligr8.buxfer;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.inteligr8.buxfer.model.Transaction;
|
||||
import com.inteligr8.polygon.PolygonPublicRestApi;
|
||||
|
||||
@ -14,7 +17,8 @@ public class SofiInvestParser implements BuxferTransactionParser {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
private final PolygonPublicRestApi papi;
|
||||
|
||||
private SofiInvestParser(PolygonPublicRestApi papi) {
|
||||
@ -23,7 +27,12 @@ public class SofiInvestParser implements BuxferTransactionParser {
|
||||
|
||||
@Override
|
||||
public ParsedTransaction parse(Transaction buxferTx) throws InterruptedException {
|
||||
return new SofiInvestTransaction(buxferTx, this.papi);
|
||||
try {
|
||||
return new SofiInvestTransaction(buxferTx, this.papi);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
this.logger.trace("Not a SoFi tx: {}", buxferTx.getId());
|
||||
throw iae;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.inteligr8.buxfer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -8,8 +10,9 @@ import com.inteligr8.buxfer.model.Transaction.Type;
|
||||
|
||||
public class TdAmeritradeDividendTransaction implements ParsedTransaction {
|
||||
|
||||
private final Pattern descriptionFormat =
|
||||
Pattern.compile("(Qualified|Ordinary) Dividend \\(([A-Za-z]+)\\)");
|
||||
private final List<Pattern> descriptionFormats = Arrays.asList(
|
||||
Pattern.compile("(Qualified|Ordinary) Dividend \\(([A-Za-z]+)\\)"),
|
||||
Pattern.compile("(Qualified|Ordinary) Dividend~([A-Za-z]+)"));
|
||||
|
||||
private final Transaction tx;
|
||||
private final String symbol;
|
||||
@ -18,8 +21,15 @@ public class TdAmeritradeDividendTransaction implements ParsedTransaction {
|
||||
public TdAmeritradeDividendTransaction(Transaction tx) {
|
||||
this.tx = tx;
|
||||
|
||||
Matcher matcher = this.descriptionFormat.matcher(tx.getDescription());
|
||||
if (!matcher.find())
|
||||
Matcher matcher = null;
|
||||
for (Pattern descriptionFormat : this.descriptionFormats) {
|
||||
matcher = descriptionFormat.matcher(tx.getDescription());
|
||||
if (matcher.find())
|
||||
break;
|
||||
matcher = null;
|
||||
}
|
||||
|
||||
if (matcher == null)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
String dividendType = matcher.group(1);
|
||||
|
@ -71,10 +71,10 @@ public class TdAmeritradeOptionTransaction implements ParsedTransaction {
|
||||
return this.determineExpirationDate(
|
||||
Integer.parseInt(strikeYearStr),
|
||||
this.parseStrikeMonth(strikeMonthStr),
|
||||
Integer.parseInt(strikeDayStr));
|
||||
strikeDayStr);
|
||||
}
|
||||
|
||||
private LocalDate determineExpirationDate(int strikeYear, Month strikeMonth, int strikeDay) {
|
||||
private LocalDate determineExpirationDate(int strikeYear, Month strikeMonth, String strikeDay) {
|
||||
try {
|
||||
return LocalDate.of(Integer.valueOf(strikeYear), strikeMonth, Integer.valueOf(strikeDay));
|
||||
} catch (NumberFormatException nfe) {
|
||||
|
@ -1,16 +1,21 @@
|
||||
package com.inteligr8.buxfer;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.inteligr8.buxfer.model.Transaction;
|
||||
|
||||
public class TdAmeritradeParser implements BuxferTransactionParser {
|
||||
|
||||
|
||||
private static final TdAmeritradeParser INSTANCE = new TdAmeritradeParser();
|
||||
|
||||
public static TdAmeritradeParser getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private TdAmeritradeParser() {
|
||||
}
|
||||
@ -20,10 +25,19 @@ public class TdAmeritradeParser implements BuxferTransactionParser {
|
||||
try {
|
||||
return new TdAmeritradeOptionTransaction(buxferTx);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
this.logger.trace("Not a TD Ameritrade option tx: {}", buxferTx.getId());
|
||||
|
||||
try {
|
||||
return new TdAmeritradeStockTransaction(buxferTx);
|
||||
} catch (IllegalArgumentException iae2) {
|
||||
return new TdAmeritradeDividendTransaction(buxferTx);
|
||||
this.logger.trace("Not a TD Ameritrade stock tx: {}", buxferTx.getId());
|
||||
|
||||
try {
|
||||
return new TdAmeritradeDividendTransaction(buxferTx);
|
||||
} catch (IllegalArgumentException iae3) {
|
||||
this.logger.trace("Not a TD Ameritrade dividend tx: {}", buxferTx.getId());
|
||||
throw iae3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user