Commit 818abea4 authored by Brian Long's avatar Brian Long
Browse files

fixed TD ameritrade option parser; added logging

parent 64a65e35
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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)
+1 −1
Original line number Diff line number Diff line
@@ -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
					}
				}
+11 −2
Original line number Diff line number Diff line
package com.inteligr8.buxfer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.inteligr8.buxfer.model.Transaction;
import com.inteligr8.polygon.PolygonPublicRestApi;

@@ -15,6 +18,7 @@ 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 {
		try {
			return new SofiInvestTransaction(buxferTx, this.papi);
		} catch (IllegalArgumentException iae) {
			this.logger.trace("Not a SoFi tx: {}", buxferTx.getId());
			throw iae;
		}
	}

}
+14 −4
Original line number Diff line number Diff line
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);
+2 −2
Original line number Diff line number Diff line
@@ -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) {
Loading