Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/commands/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,18 @@ export function registerResourceCommands(program: Command): void {
let accounts: Account[] = [];
let ids = accountIds;
if (ids.length === 0) {
accounts = await allAccounts();
const [all, { data: connections }] = await Promise.all([allAccounts(), client.listConnections()]);
const bankingConnections = new Set(
connections.filter((c) => c.category === "banking").map((c) => c.id),
);
accounts = all.filter((a) => bankingConnections.has(a.connectionId));
ids = accounts.map((a) => a.id);
if (ids.length === 0) return console.log("No accounts found.");
if (ids.length === 0) {
return console.log(
"No banking accounts found. Balances cover banking accounts only — " +
`use ${pc.bold("redbark holdings")} for brokerage.`,
);
}
}
const { data } = await client.listBalances(ids);
if (json()) return printJson(data);
Expand Down Expand Up @@ -161,7 +170,7 @@ export function registerResourceCommands(program: Command): void {
console.log(
table(data, [
{ header: "symbol", value: (h) => h.symbol },
{ header: "name", value: (h) => truncate(h.name, 32) },
{ header: "name", value: (h) => (h.name === null ? null : truncate(h.name, 32)) },
{ header: "qty", value: (h) => h.quantity, align: "right" },
{ header: "price", value: (h) => money(h.currentPrice), align: "right" },
{ header: "value", value: (h) => money(h.marketValue, h.currency), align: "right" },
Expand Down
2 changes: 1 addition & 1 deletion src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function visibleWidth(s: string): number {
}

export function money(amount: string | null, currency?: string | null): string {
if (amount === null || amount === undefined) return "";
if (amount === null || amount === undefined) return pc.dim("—");
const n = Number(amount);
if (Number.isNaN(n)) return amount;
const formatted = n.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
Expand Down
20 changes: 10 additions & 10 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,31 @@ export interface Holding {
accountId: string;
accountName: string;
symbol: string;
name: string;
exchange: string;
name: string | null;
exchange: string | null;
currency: string;
quantity: string;
averagePrice: string;
currentPrice: string;
marketValue: string;
unrealizedPnl: string;
averagePrice: string | null;
currentPrice: string | null;
marketValue: string | null;
unrealizedPnl: string | null;
}

export interface Trade {
id: string;
accountId: string;
accountName: string;
symbol: string;
name: string;
name: string | null;
type: string;
quantity: string;
price: string;
currency: string;
totalAmount: string;
fees: string;
fees: string | null;
tradeDate: string;
settlementDate: string;
description: string;
settlementDate: string | null;
description: string | null;
}

export interface RateLimitInfo {
Expand Down
4 changes: 2 additions & 2 deletions test/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ describe("money", () => {
test("passes through non-numeric strings", () => {
expect(strip(money("n/a"))).toBe("n/a");
});
test("empty for null", () => {
expect(money(null)).toBe("");
test("renders null as a dash", () => {
expect(strip(money(null))).toBe("—");
});
});

Expand Down
Loading