Skip to content

samirelanduk/django-candlestick

Repository files navigation

django-candlestick

django-candlestick is a django library for storing price data for stocks, assets, currencies, and other tradeable instruments.

Setup

Install:

$ pip install django-candlestick

Add to installed apps:

INSTALLED_APPS = [
    ...
    "candlestick"
    ...
]

Migrate:

$ python manage.py migrate

You now have a database of tradeable instruments and their prices.

Use

Manual

from candlestick.models import Instrument, Bar

apple = Instrument.objects.create(
    symbol="AAPL", name="Apple, Inc.", currency="USD", timezone="US/Eastern"
)
bar = Bar.objects.create(
    open="320.13", low="319.88", high="321.4", close="320.17", volume=3115337,
    timestamp=1579887000, resolution="H", instrument=apple
)
print(bar.datetime) # 2020-01-24 12:30:00-05:00

From YAHOO

apple.fetch(resolution="M") # Gets all bars for the month resolution
apple.update(resolution="H") # Gets new bars for the H resolution

At command line

To fetch bars for an instrument:

$ python manage.py fetch AAPL D

To update bars for an instrument:

$ python manage.py update AAPL D

To update bars for multiple instruments:

$ python manage.py update AAPL,AMZN D

To update bars for all instruments:

$ python manage.py update all D