@neabyte/candlestick-cli
Version:
Beautiful terminal candlestick charts with real-time trading data. Create stunning ASCII art charts directly in your terminal with support for live market data, custom colors, and professional trading visualization.
1 lines • 1.24 kB
JavaScript
import{LABELS}from"../constants.js";import{fnum,formatPrice}from"../utils/core.js";export class InfoBar{name;labels;constructor(e){this.name=e,this.labels={...LABELS}}formatPrice=e=>formatPrice(e);renderPriceField=(e,r)=>e?`${e}: ${this.formatPrice(r)}`:"";renderAverage(e){return this.renderPriceField(this.labels.average,e.average)}renderHighest(e){return this.renderPriceField(this.labels.highest,e.maxPrice)}renderLowest(e){return this.renderPriceField(this.labels.lowest,e.minPrice)}renderPrice(e){return this.renderPriceField(this.labels.price,e.lastPrice)}renderVariation(e){if(!this.labels.variation)return"";const{variation:r}=e,t=r>=0?"+":"",i=fnum(r);return`${this.labels.variation}: ${t}${i}%`}renderVolume(e){if(!this.labels.volume)return"";const r=Math.floor(e.cumulativeVolume).toLocaleString();return`${this.labels.volume}: ${r}`}render(e,r){const t=[];this.name&&t.push(this.name);const i=this.renderPrice(e);i&&t.push(i);const s=this.renderHighest(e);s&&t.push(s);const n=this.renderLowest(e);n&&t.push(n);const a=this.renderVariation(e);a&&t.push(a);const o=this.renderAverage(e);o&&t.push(o);const l=this.renderVolume(e);l&&t.push(l);const h=t.join(" | "),c=Math.max(0,Math.floor((r-h.length)/2));return" ".repeat(c)+h}}