UNPKG

@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 4.1 kB
import{DEFAULT_TITLE}from"./types.js";export async function parseArgs(){const e=process.argv.slice(2),t={title:DEFAULT_TITLE,timeframe:"1h",limit:1e3,width:0,height:0,volume:!0,volumeHeight:8,background:"dark",watch:!1,interval:30};for(let a=0;a<e.length;a++){const l=e[a],n=e[a+1];if("--help"===l&&(await showHelp(),process.exit(0)),"--no-volume"!==l)if("--watch"!==l)if("--no-watch"!==l){if(n){switch(l){case"--file":case"-f":t.file=n;break;case"--symbol":case"-s":t.symbol=n;break;case"--timeframe":t.timeframe=n;break;case"--limit":t.limit=parseInt(n);break;case"--title":case"-t":t.title=n;break;case"--width":case"-w":t.width=parseInt(n);break;case"--height":case"-h":t.height=parseInt(n);break;case"--bear-color":t.bearColor=n;break;case"--bull-color":t.bullColor=n;break;case"--volume-height":t.volumeHeight=parseInt(n);break;case"--output":case"-o":t.output=n;break;case"--background":t.background=n;break;case"--interval":t.interval=parseInt(n)}a++}}else t.watch=!1;else t.watch=!0;else t.volume=!1}return t}async function showHelp(){const{default:e}=await import("figlet"),t=e.textSync("Candlestick-CLI",{font:"Slant",horizontalLayout:"fitted",verticalLayout:"default"});console.log(t),console.log('\nUsage: candlestick-cli [options]\n\nData Source Options:\n -f, --file <path> Path to CSV or JSON file\n -s, --symbol <symbol> Trading symbol for live data (e.g., BTC/USDT, BTC/USDT:USDT)\n --timeframe <timeframe> Timeframe for live data (1m, 5m, 15m, 1h, 4h, 1d, 1w, 1M, default: 1h)\n --limit <number> Number of candles to fetch (default: 1000)\n\nChart Options:\n -t, --title <title> Chart title (default: "Candlestick Chart")\n -w, --width <number> Chart width (0 for auto)\n -h, --height <number> Chart height (0 for auto)\n --bear-color <color> Bearish candle color (hex or RGB)\n --bull-color <color> Bullish candle color (hex or RGB)\n --no-volume Disable volume pane\n --volume-height <number> Volume pane height (default: 8)\n\nWatch Mode (Live Data):\n --watch Enable watch mode for live updates\n --interval <seconds> Update interval in seconds (default: 30)\n\nExport Options:\n -o, --output <path> Export chart to file (PNG, TXT)\n\n --background <theme> Background theme: light or dark (default: dark)\n\nOther:\n --help Show this help\n\nExamples:\n # File-based charts\n candlestick-cli -f data.csv -t "BTC/USDT"\n candlestick-cli -f data.json --bear-color "#ff6b6b" --bull-color "#51cf66"\n \n # Live market data (single snapshot by default)\n candlestick-cli -s BTC/USDT --timeframe 4h --limit 200\n candlestick-cli -s ETH/USDT --timeframe 1d --limit 100 -t "Ethereum Daily"\n candlestick-cli -s BTC/USDT --bear-color "#a55eea" --bull-color "#feca57"\n \n # Watch mode (explicitly enabled)\n candlestick-cli -s BTC/USDT --timeframe 1h --watch\n candlestick-cli -s ETH/USDT --timeframe 15m --watch --interval 10 --limit 50\n \n # Perpetual futures\n candlestick-cli -s BTC/USDT:USDT --timeframe 1h --limit 150\n candlestick-cli -s ETH/USDT:USDT --timeframe 15m --limit 300\n \n # Export examples\n candlestick-cli -s BTC/USDT -o chart.png --background light\n candlestick-cli -f data.csv -o chart.txt\n candlestick-cli -s ETH/USDT -o chart.png --background dark\n\nFile Formats:\n CSV: Should have columns: open,high,low,close,volume,timestamp\n JSON: Array of objects with: open,high,low,close,volume,timestamp\n\nExport Formats:\n PNG: High-quality image export with colors\n TXT: Plain text export\n\nSupported Timeframes:\n 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, 1M\n\nWatch Mode:\n Use --watch flag to enable live updates.\n Charts update every 30 seconds (customizable with --interval).\n Press Ctrl+C to stop watching.\n\nNote: Colors work in terminals with color support (like VSCode\'s integrated terminal).\nIf colors appear gray in your system terminal, export to PNG to see full colors.\n\nLimits:\n Minimum: 5 candles, Maximum: 10,000 candles\n')}