Skip to content

Commit

Permalink
Fix Schwab converter (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
dickwolff committed May 31, 2024
1 parent 62de843 commit 2e0ac3b
Show file tree
Hide file tree
Showing 13 changed files with 568 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

- [ ] Added relevant changes to README (if applicable)
- [ ] Added relevant test(s)
- [ ] Updated GitVersion file
- [ ] Updated GitVersion file and corresponding version in `package.json`

## Related issue (if applicable)

Expand Down
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
next-version: 0.13.0
next-version: 0.13.2
assembly-informational-format: "{NuGetVersion}"
mode: ContinuousDeployment
branches:
Expand Down
3 changes: 2 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const config: Config.InitialOptions = {
'/src/manual.ts',
'/src/watcher.ts',
'/src/converter.ts'],
coverageReporters: ['text', 'cobertura', 'html']
coverageReporters: ['text', 'cobertura', 'html'],
setupFiles: ["<rootDir>/src/testing/testEnvVars.js"]
};

export default config;
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "export-to-ghostfolio",
"version": "1.0.0",
"version": "0.13.2",
"type": "module",
"description": "Convert multiple broker exports to Ghostfolio import",
"scripts": {
Expand All @@ -16,11 +16,11 @@
"devDependencies": {
"@types/cacache": "^17.0.2",
"@types/jest": "^29.5.11",
"@types/node": "^20.12.8",
"@types/node": "^20.12.12",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"ts-jest": "^29.1.3",
"ts-node": "^10.9.2",
"tsx": "^4.9.3",
"tsx": "^4.10.5",
"typescript": "^5.4.5"
},
"dependencies": {
Expand All @@ -29,7 +29,7 @@
"chokidar": "^3.6.0",
"cli-progress": "^3.12.0",
"closest-match": "^1.3.3",
"csv-parse": "^5.5.5",
"csv-parse": "^5.5.6",
"dayjs": "^1.11.11",
"dotenv": "^16.4.5",
"yahoo-finance2": "^2.11.2"
Expand Down
3 changes: 3 additions & 0 deletions samples/schwab-export.csv
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,7 @@ Date,Action,Symbol,Description,Quantity,Price,Fees & Comm,Amount
01/03/2023,Reinvest Shares,TCPC,BLACKROCK TCP CAPITAL CO,10.0443,$13.17,,-$132.25
"09/08/2023","Sell","SNAXX","SCHWAB VALUE ADVANTAGE MONEY ULTRA","500,135","$1.00","","$500135.00"
"10/18/2023","Wire Sent","","WIRED FUNDS DISBURSED","","","","-$100000.00"
"04/08/2024","MoneyLink Transfer","","Tfr BANK OF AMERICA, N, XXXX YYYYYY ZZZ","","","","-$30.00"
"11/07/2023","Internal Transfer","","TDA TO DW&O TRANSFER","","","","$7.06"
"11/07/2023","Non-Qualified Div","","TDA TRAN - NON-TAXABLE DIVIDENDS (CMF)","","","","$72.06"
Transactions Total,,,,,,,"-$26,582.91"
4 changes: 4 additions & 0 deletions src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ import { Trading212Converter } from "./converters/trading212Converter";
import { XtbConverter } from "./converters/xtbConverter";
import { BitvavoConverter } from "./converters/bitvavoConverter";

import packageInfo from "../package.json";

async function createAndRunConverter(converterType: string, inputFilePath: string, outputFilePath: string, completionCallback: CallableFunction, errorCallback: CallableFunction) {

// Verify if Ghostolio account ID is set (because without it there can be no valid output).
if (!process.env.GHOSTFOLIO_ACCOUNT_ID) {
return errorCallback(new Error("Environment variable GHOSTFOLIO_ACCOUNT_ID not set!"));
}

console.log(`[i] Starting Export to Ghostfolio v${packageInfo.version}`);

// If DEBUG_LOGGING is enabled, set spaces to 2 else null for easier to read JSON output.
const spaces = process.env.DEBUG_LOGGING === "true" ? 2 : null;
Expand Down
2 changes: 1 addition & 1 deletion src/converters/abstractconverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export abstract class AbstractConverter {
{
stopOnComplete: true,
forceRedraw: true,
format: "{bar} {percentage}% | ETA {eta}s | Duration: {duration}s | {value}/{total}"
format: "[i] {bar} {percentage}% | ETA {eta}s | Duration: {duration}s | {value}/{total}"
},
cliProgress.Presets.shades_classic);
}
Expand Down
2 changes: 1 addition & 1 deletion src/converters/schwabConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("schwabConverter", () => {
// Assert
expect(actualExport).toBeTruthy();
expect(actualExport.activities.length).toBeGreaterThan(0);
expect(actualExport.activities.length).toBe(98);
expect(actualExport.activities.length).toBe(99);

done();
}, () => { done.fail("Should not have an error!"); });
Expand Down
8 changes: 6 additions & 2 deletions src/converters/schwabConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export class SchwabConverter extends AbstractConverter {
else if (action.indexOf("sell") > -1) {
return "sell";
}
else if (action.indexOf("non-qual") > -1) {
return "cash";
}
else if (action.indexOf("dividend") > -1 ||
action.indexOf("qual") > -1 ||
action.endsWith("reinvest")) {
Expand Down Expand Up @@ -101,8 +104,9 @@ export class SchwabConverter extends AbstractConverter {
continue;
}

// Custody fees or interest do not have a security, so add those immediately.
// Custody fees, cash or interest do not have a security, so add those immediately.
if (record.action.toLocaleLowerCase() === "fee" ||
record.action.toLocaleLowerCase() === "cash" ||
record.action.toLocaleLowerCase() === "interest") {

const feeAmount = Math.abs(record.amount);
Expand Down Expand Up @@ -192,7 +196,7 @@ export class SchwabConverter extends AbstractConverter {
return true;
}

const ignoredRecordTypes = ["credit", "journal"];
const ignoredRecordTypes = ["credit", "journal", "transfer"];

let ignore = ignoredRecordTypes.some(t => record.action.toLocaleLowerCase().indexOf(t) > -1);

Expand Down
Loading

0 comments on commit 2e0ac3b

Please sign in to comment.