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
6 changes: 5 additions & 1 deletion src/crypto.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,11 @@ function priceLine(snapshot, quote) {
const bits = [bone(price(last, quote))];
if (change) {
const paint = changeTone(change.percent);
bits.push(paint(`${change.absolute >= 0 ? "+" : ""}${price(change.absolute, quote, { like: last })}`), paint(`(${pct(change.percent)})`));
// Sign the magnitude, don't let price() sign it: a signed price puts the
// minus after the currency mark ("$-186.36"), so a down move reads unlike
// the up move's "+$186.36". The sign leads, the way pct() already signs.
const signed = `${change.absolute >= 0 ? "+" : "-"}${price(Math.abs(Number(change.absolute)), quote, { like: last })}`;
bits.push(paint(signed), paint(`(${pct(change.percent)})`));
}
const feed = [
snapshot?.delayed === false ? "live" : snapshot?.delayed === true ? "delayed" : null,
Expand Down
14 changes: 14 additions & 0 deletions test/crypto.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ test("the report renders the live stamp, the score and the disclaimer", () => {
assert.match(out, /Research aid, not advice\./);
});

test("a down move signs the change like the up move, mark and all", () => {
const render = (absolute, percent) => renderCrypto("report", {
symbol: "ETH/USD", quote: "USD",
snapshot: { latestTrade: { price: 3200.55 }, change: { absolute, percent } },
}, { columns: 88 }).replace(/\x1b\[[0-9;]*m/g, "");

const down = render(-186.363, -5.5);
assert.match(down, /-\$186\.36/, "the sign leads the currency mark, not follows it");
assert.doesNotMatch(down, /\$-186\.36/, "a currency mark must never sit after the minus");

const up = render(186.363, 5.5);
assert.match(up, /\+\$186\.36/, "an up move keeps its leading plus");
});

test("--limit on bars is honoured here, because upstream does not honour it", () => {
// The API treats limit as a page size over its own window, so a renderer that
// just printed everything would silently break the flag's promise.
Expand Down
Loading