Package: ohlc
Ohlc: Types + Tools for Open-High-Low-Close ValuesOhlc providesOhlc, anamedtuplefor storing and efficiently processing
open-high-low-close data, used for financial charts and calculations.
It also provides tools for processing, generating, and visualizing lists ofOhlcvalues in the console.InstallationpipinstallohlcUsing the Data TypefromohlcimportOhlco=Ohlc.from_values([2,5,4,7,11,7,2,9,5])# Ohlc(open=2, high=11, low=2, close=5)o.spread()# 9o=Ohlc(3,4,1,2)# Ohlc(open=3, high=4, low=1, close=2)o==(3,4,1,2)# True -- Yeay! It is a regular tuple!o1=Ohlc.from_values(range(5,15))# Ohlc(open=5, high=14, low=5, close=14)o2=Ohlc.from_values(range(14,3,-1),prev=o1)# Ohlc(open=14, high=14, low=4, close=4)o3=Ohlc.from_values(range(5,20),prev=o2)# Ohlc(open=5, high=19, low=5, close=19)o3.heikin()# compute Heikin-Ashi candle from Ohlc chain# Ohlc(open=9.0, high=19, low=5, close=12.0)Formatting Valuesforoin[o1,o2,o3]:print(o.format())# 5.000000 14.000000 5.000000 14.000000# 14.000000 14.000000 4.000000 4.000000# 5.000000 19.000000 5.000000 19.000000print(o.format(sep=','))# 5.000000,19.000000,5.000000,19.000000print(o.format(sep='',fmt='{:d}\n'))# 5# 19# 5# 19Transformation + Aggregationo1# Ohlc(open=5, high=14, low=5, close=14)o1.transform(scale=1.25,offset=1)# Ohlc(open=7.5, high=18.75, low=7.5, close=18.75)]agg=o.from_ohlc_list([o1,o2,o3])# Ohlc(open=5, high=19, low=4, close=19)Ohlc PlottingFor plotting, the classohlc.candles.CandleCanvasprovides raw colored console output
using terminal colors, but also supports styled output for embedding inUrwidconsole apps.A simpe plotter powered by Urwid +Widdywidgets
can be started using the providedohlccommand.# start the ohlc candlestick visualization using random values, heikin-ashi candles,# price action bars (colors), and the chart title: 'Candles'ohlc--pab--ha--random--title'Candles'Omitting most options produces classic candle stick charts.ohlc--random--title'Classic Candles'When plotting in interactive mode do not use/dev/stdin(this is already used by Urwid).
Use a file or file descriptor as the positionalinputargument toohlc.# plot some input dataohlc<(echo-e"8 11 7 4 5\n5 4 8 6\n6\n6 5\n5 6 1 4")--title"Input"Non-Interactive ModeThere is also a non-interactive mode using the option-nor--non-interactivethat just reads the input to the end plots the end of the input stream using the
given or available screen width. This mode also supports/dev/stdinas input.echo-e"8 11 7 4 5\n5 4 8 6\n6\n6 5\n5 6 1 4"|ohlc-n--title"Input"-W23-H8# ┌─────────────────────┐# ││        ┌ 11.00     │# │╽╷       ├ 8.50      │# │┃┃╹┃╽    ├ 6.00      │# │╵╵  ╿    └ 3.50      │# │┌─────┐   max:11.00  │# │0     1   last:4.00  │# └─────────────────────┘ToolsThe commandohlc-inputcomputes anOhlctuple for each input line and pipes out the four values.ohlc-input<(echo23434;echo45689;echo10876)# 2.000000 4.000000 2.000000 4.000000# 4.000000 9.000000 4.000000 9.000000# 10.000000 10.000000 6.000000 6.000000The commandohlc-randomgenerates and prints randomOhlcvalues.ohlc-random--data_rate1# 0.100000 0.100000 0.073059 0.076472# 0.076472 0.106526 0.073043 0.104767# 0.104767 0.146023 0.098335 0.142284# 0.142284 0.169882 0.118809 0.162817# 0.162817 0.164071 0.131635 0.140002# 0.140002 0.140246 0.111727 0.124778DevelopmentFirst fork and clone the repo. Then run the tests.make# clean up and run all testsYou may need to install some tools and modules, i.e.,flake8,pytest,twine,urwid,
and maybe others until all tests run through (seerequirements.txt)For packaging and local distribution you can build a Python wheel.makebuild# build Python wheelPackagingAdvanced packaging is only required from project maintainers.
For packaging the project for PyPi, please seesetup.mk.Pull requestsare welcome!Change Log2018:       inital PoC and experiments + Py2 Py3 backport magic2019-05-04: removed Python2 support and makepy dependency, added non-interactive mode2023-10-13: updated scripts and fixed broken refresh on MacOSProject StatusThe project is in low maintenance mode. Do not use it in production.
I use it only for personal prototypes and to demo the power of terminal apps.Open Issues (by priority)project: cleanup upstream dependencies (widdy) and make them optional if possible (urwid)project: move custom argparse to separate packageproject: add Pypi flagsbug: try detect unicode support and fallback to ASCII (e.g., in default iTerm2 on OSX)example: BTC Ticker or Custom Symbol Tickerusability: react on urwid resizing eventsmusthave: add or allow addingdatetimetoOhlctuplesproject: add CI/CDfeature: draw correct time axisfeature: set candle interval (5m 15m 30m 1h 4h, 6h, 1d, 3d, 1w, 1M, etc.)feature: add axis labelsfeature: support for bright color schemefeature: scrolling over all cached datafeature: interactively shrink/grow the canvas (adjust top/bottom padding)feature: allow setting the cache sizefeature: allow seeking over input filesfeature: monitor CPU usage and reduce redraw (big + fast charts are still very expensive)example: Iteractive Tickerexample: MultiChart Appexample: MultiChart Tickersexample: Interactive MultiChart Tickersfeature: indiator overlays (RSI, EMA12, EMA26, etc.)feature: indicators bars below chart (price action colored volume bars)