Skip to main content

A pythonic package for working with market data

Project description

Untitled

📈 Candlestick Library

Candlestick is a high‑performance, strongly‑typed Python library for working with financial chart data — including candlesticks (OHLCV) and indicators. Designed with flexibility and performance in mind, it integrates seamlessly with Pandas, NumPy, and other data‑science tools.

Whether you're building backtesting engines, streaming chart visualizations, or performing market analysis, Candlestick provides a clean, structured, and reliable foundation for managing time‑series financial data.


🚀 Quick Start

from py_candlestick import Chart, Candle

candles = [
    Candle(timestamp=1700000000, open=1.2, high=1.3, low=1.1, close=1.25, volume=1500),
    Candle(timestamp=1700000600, open=1.25, high=1.32, low=1.2, close=1.28, volume=2100),
]

chart = Chart(candles)
print(len(chart))               # number of candles
print(chart.to_dataframe())    # convert to Pandas DataFrame

🔥 Key Features

  • ✅ Strongly‑typed Candle and Chart classes
  • ✅ Fast NumPy‑backed data operations
  • ✅ Easy conversion to/from Pandas DataFrames
  • ✅ Built‑in indicator registration
  • ✅ CSV and MT5 data import utilities
  • ✅ Safe chart updates with sequencing and timestamp validation
  • ✅ Convenient Python slicing & iteration

🕯️ Candle Class

Each candlestick is represented by the immutable Candle class:

Candle(
    timestamp: float,
    open: float,
    high: float,
    low: float,
    close: float,
    volume: float
)

Candle Highlights

  • Immutable (frozen=True)
  • Time‑aware with date_time property
  • Helpers: is_bullish(), is_bearish(), is_undecided()
  • Conversions: as_dict(), as_tuple(), from_dict()
  • Length (len(candle)) equals high‑low range

Example:

c = Candle(timestamp=1700000000, open=1.2, high=1.3, low=1.1, close=1.25, volume=1000)
print(c.is_bullish())  # True
print(c.range_())      # 0.2

📊 Chart Class

Chart stores a sequence of candles and optional computed indicators.

Creating a Chart

chart = Chart(candles)

Converting to DataFrame

df = chart.to_dataframe(include_timeframe=True, include_symbol=True)

Adding Indicators

Indicators are expected to return an Indicator object with name and NumPy values.

def sma_indicator(candles):
    closes = [c.close for c in candles]
    values = np.convolve(closes, np.ones(5)/5, mode='valid')
    return Indicator(name="sma5", values=values)

chart = Chart(candles, indicator_calculators=[sma_indicator])

Chart Updating

update_chart() adds only new candles (based on timestamp).

chart.update_chart(new_candles)

If an update handler is passed:

def on_update(c):
    print("Chart updated!", len(c))

chart = Chart(candles, on_chart_update=on_update)
chart.update_chart(new_candles)

📥 Importing Market Data

From CSV

chart = Chart.from_csv("data.csv")

CSV must contain:

timestamp,open,high,low,close,volume

From Pandas DataFrame

chart = Chart.from_pd_dataframe(df)

From MT5 Raw Data

chart = Chart.from_mt5_data(mt5_array, symbol=my_symbol, timeframe=my_tf)

📦 NumPy Integration

Convert to a stacked matrix of series:

arr = chart.to_ndarray()

Output shape:

(num_candles, num_features)

Where features = timestamp, open, high, low, close, volume, + indicators.


🧩 Slicing & Iteration

first_10 = chart[:10]
last_candle = chart[-1]
for c in chart:
    print(c.close)

🤝 Contributing

Pull requests, issues, and improvements are welcome! The project is designed to be clean, readable, and extensible.


📄 License

MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_candlestick-0.1.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_candlestick-0.1.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file py_candlestick-0.1.0.tar.gz.

File metadata

  • Download URL: py_candlestick-0.1.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for py_candlestick-0.1.0.tar.gz
Algorithm Hash digest
SHA256 057068e557c21033fdb159c432be2b174c6315318cc2cb9d1b28803e4046c8b6
MD5 3d17255063730c4179344b278fa11a00
BLAKE2b-256 e596f0903e9c76b3950cad1d810dab08c64b79c1c6778cf9ce3a696d26fed1ff

See more details on using hashes here.

File details

Details for the file py_candlestick-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py_candlestick-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for py_candlestick-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a8968222e7c76e0633822ed1dc56c361c5dc893a6b62d7feb0129691942ce1d
MD5 a1b0a0a649af43b376478c97a210392a
BLAKE2b-256 9ec9e2c6e50f5856bebaa92558df08ee4fbd3d3f7668077610e4b7bab33e007e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page