bashplotlib icon indicating copy to clipboard operation
bashplotlib copied to clipboard

Console candlestick plot

Open c0indev3l opened this issue 11 years ago • 2 comments

Hello,

I'm looking for a python script to draw candlestick plot inside a text user interface (ncurses or urwid).

Could you help me to do that ?

For now I've done a script which download from Yahoo Finance GOOG OHLCV data (and put data into a SQLite cache)

You need pandas, requests and requests-cache

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import requests

import requests_cache

expire_after = None #15*60 # expire_after=delay_second or None
requests_cache.install_cache('req_cache', backend='sqlite', expire_after=expire_after)

from StringIO import StringIO

import pandas as pd

def get_ohlcv_data(size, offset=0):
    url = "http://ichart.finance.yahoo.com/table.csv?s=GOOG"
    req = requests.get(url)
    #print(req.content)
    io = StringIO(req.content)
    df = pd.read_csv(io, sep=',', parse_dates=['Date'])
    df = df.rename(columns={
        'Date': 'date',
        'Open': 'open',
        'High': 'high',
        'Low': 'low',
        'Close': 'close',
        'Volume': 'volume',
        'Adj Close': 'adj close',
    })
    df = df.set_index('date')
    df = df[offset:size+offset][::-1]
    return(df)

def main():
    df = get_ohlcv_data(50, 0)
    print(df)
    print(df.dtypes)

    inc = df['close'] > df['open']
    dec = df['close'] < df['open']

if __name__ == "__main__":
    main()

An other sofware provide something similar http://prof7bit.github.io/goxtool/

but I really want to isolate plot to be standalone.

It will be nice if bashplotlib could provide such feature.

Kind regards

c0indev3l avatar Mar 03 '14 09:03 c0indev3l

haha cool i'll take a look

glamp avatar Apr 15 '14 15:04 glamp

ideally it will be nice if it could be integrate as a widget into urwid using inheritance of widget http://urwid.org/reference/widget.html see speedometer example http://excess.org/speedometer/ so we could have events...

c0indev3l avatar Apr 15 '14 16:04 c0indev3l