Complete API documentation for Candlestick-CLI.
- Chart Class
- ChartData Class
- ChartRenderer Class
- YAxis Class
- VolumePane Class
- InfoBar Class
- CandleSet Class
- CCXTProvider Class
- Export Functions
- Utility Functions
- Constants
- Error Types
- Types
Main chart class for creating and rendering candlestick charts.
new Chart(candles: Candles, options?: ChartOptions)Parameters:
candles: Candles- Array of candle dataoptions?: ChartOptions- Optional configuration
ChartOptions:
interface ChartOptions {
title?: string // Chart title (default: 'My chart')
width?: number // Chart width (default: 0 for auto)
height?: number // Chart height (default: 0 for auto)
rendererClass?: typeof ChartRenderer // Custom renderer class
}render(): Promise<string>- Renders the chart to a string representationdraw(): Promise<void>- Renders the chart to console output
setBearColor(r: number, g: number, b: number): void- Set bearish candle color (RGB values 0-255)setBullColor(r: number, g: number, b: number): void- Set bullish candle color (RGB values 0-255)setVolBearColor(r: number, g: number, b: number): void- Set volume bearish color (RGB values 0-255)setVolBullColor(r: number, g: number, b: number): void- Set volume bullish color (RGB values 0-255)
setVolumePaneEnabled(enabled: boolean): void- Enable or disable volume pane displaysetVolumePaneHeight(height: number): void- Set volume pane height in lines
setHighlight(price: string, color: ColorValue): void- Highlight specific price level with colorsetName(name: string): void- Set chart name/titlesetMargins(top?: number, right?: number, bottom?: number, left?: number): void- Set chart margins
updateCandles(candles: Candles, reset?: boolean): void- Update chart with new candle data
updateSize(width: number, height: number): void- Update chart dimensionsupdateSizeFromTerminal(): void- Update size from current terminal dimensionsenableAutoResize(interval?: number): void- Enable automatic terminal size followingdisableAutoResize(): void- Disable automatic terminal size following
setScalingMode(mode: 'fit' | 'fixed' | 'price'): void- Set chart scaling modesetPriceRange(minPrice: number, maxPrice: number): void- Set price range for price-based scalingsetTimeRange(startIndex: number, endIndex: number): void- Set time range for fixed scalingfitToData(): void- Fit chart to display all data points
Market data provider for fetching real-time cryptocurrency data using CCXT library.
new CCXTProvider()Creates a new CCXT provider instance configured for Binance futures trading.
fetchOHLCV(symbol?: string, timeframe?: string, limit?: number): Promise<Candles>- Fetch OHLCV data from exchangefetch4H(symbol?: string, limit?: number): Promise<Candles>- Fetch 4-hour timeframe datafetch1D(symbol?: string, limit?: number): Promise<Candles>- Fetch 1-day timeframe data
getLatestPrice(symbol?: string): Promise<number>- Get latest price for symbolgetMarketInfo(symbol?: string): Promise<MarketInfo>- Get market information
MarketInfo:
interface MarketInfo {
symbol: string
base: string
quote: string
precision: Record<string, unknown>
limits: Record<string, unknown>
}Export chart to text file with optional color preservation.
Parameters:
chart: Chart- Chart instance to exportoutputPath: string- Output file pathpreserveColors?: boolean- Whether to preserve ANSI color codes (default: false)
Example:
import { exportToText } from '@neabyte/candlestick-cli'
await exportToText(chart, 'chart.txt')
await exportToText(chart, 'chart.txt', true) // Preserve colorsExport chart to PNG image with customizable settings.
Parameters:
chart: Chart- Chart instance to exportoptions: ExportOptions- Export configuration
ExportOptions:
interface ExportOptions {
outputPath: string
background?: 'light' | 'dark' // Background theme (default: 'dark')
}Example:
import { exportToImage } from '@neabyte/candlestick-cli'
await exportToImage(chart, {
outputPath: 'chart.png',
background: 'light'
})Auto-detect export format based on file extension.
Parameters:
chart: Chart- Chart instance to exportoutputPath: string- Output file path (.txt or .png)options?: Partial<ExportOptions>- Optional export options
Example:
import { exportChart } from '@neabyte/candlestick-cli'
await exportChart(chart, 'chart.txt') // Text export
await exportChart(chart, 'chart.png') // Image exportfnum(number: number): string- Format number with commasroundPrice(price: number): number- Round price to 2 decimal placesformatPrice(price: number): string- Format price with commas and 2 decimals
parseCandlesFromCsv(content: string): Candles- Parse candles from CSV contentparseCandlesFromJson(content: string): Candles- Parse candles from JSON content
Example:
import { fnum, formatPrice, parseCandlesFromCsv } from '@neabyte/candlestick-cli'
const formatted = fnum(1234.56) // "1,234.56"
const price = formatPrice(50000) // "50,000.00"
const candles = parseCandlesFromCsv(csvContent)Chart rendering constants including margins, dimensions, and formatting options.
Default labels and text constants used throughout the application.
Default color definitions for chart elements.
ANSI color reset code for terminal output.
Example:
import { CONSTANTS, LABELS, COLORS, RESET_COLOR } from '@neabyte/candlestick-cli'
console.log(`${COLORS.RED}Error${RESET_COLOR}`)Error thrown when OHLC data validation fails.
Error thrown when market data fetching or processing fails.
Error thrown when chart rendering fails.
Error thrown when input validation fails.
Error thrown when terminal operations fail.
Error thrown when configuration is invalid.
Enum of all error types.
Example:
import { MarketDataError, ConfigurationError } from '@neabyte/candlestick-cli'
try {
const data = await provider.fetchOHLCV('BTC/USDT')
} catch (error) {
if (error instanceof MarketDataError) {
console.error('Market data error:', error.message)
}
}Individual candle data structure.
interface Candle {
open: number
high: number
low: number
close: number
volume: number
timestamp: number
type: CandleType
}Array of candle data.
type Candles = Candle[]Candle type enumeration.
type CandleType = 1 | -1 // 1 for bullish, -1 for bearishRGB color tuple.
type RGBColor = [number, number, number]Color value union type.
type ColorValue = string | RGBColor | numberPrice highlighting configuration.
type ChartHighlights = Record<string, ColorValue>Chart label configuration.
type ChartLabels = Record<string, string>Chart constants configuration.
type ChartConstants = Record<string, unknown>Statistics for a set of candles.
interface CandleSetStats {
count: number
high: number
low: number
open: number
close: number
volume: number
}Chart dimension configuration.
interface ChartDimensions {
width: number
height: number
}Terminal size information.
interface TerminalSize {
width: number
height: number
}Export configuration options.
interface ExportOptions {
outputPath: string
background?: 'light' | 'dark'
}Market data structure for CCXT integration.
interface MarketData {
open: number
high: number
low: number
close: number
volume: number
timestamp: number
}