Simple stock db with tools.
Project description
pystockdb
Database for stocks based on pony.orm. This package provides an create, sync and update tool.
At the moment we are only support a few stocks. If you want to have more, please contribute pytickersymbols.
install
pip install pystockdb
database schema
quick start
In all samples we use sqlite but you are free to use other providers. For more information's please read Connecting to the Database.
Install sqlite stock db:
import logging from pystockdb.tools.create import CreateAndFillDataBase logger = logging.getLogger('test') config = { 'max_history': 1, 'indices': ['DAX'], 'currencies': ['EUR'], 'create': True 'db_args': { 'provider': 'sqlite', 'filename': 'demo.sqlite', 'create_db': True }, } create = CreateAndFillDataBase(config, logger) create.build()
Install mysql stock db:
For mysql you need an additional package:
pip install pymysql
import logging from pystockdb.tools.create import CreateAndFillDataBase logger = logging.getLogger('test') config = { 'max_history': 1, 'indices': ['DAX'], 'currencies': ['EUR'], 'create': True 'db_args': { 'provider': 'mysql', 'host': '127.0.0.1', 'user': 'root', 'passwd': 'test', 'db': 'test', }, } create = CreateAndFillDataBase(config, logger) create.build()
Update sqlite stock db:
import logging from pystockdb.tools import ALL_SYMBOLS from pystockdb.tools.update import UpdateDataBaseStocks logger = logging.getLogger('test') config = { 'symbols': [ALL_SYMBOLS], 'prices': True, # update prices 'fundamentals': True, # update fundamental stock data 'db_args': { 'provider': 'sqlite', 'filename': 'demo.sqlite', 'create_db': False }, } update = UpdateDataBaseStocks(config, logger) update.build()
Sync sqlite stock db:
import logging from pystockdb.tools.sync import SyncDataBaseStocks logger = logging.getLogger('test') config = { 'max_history': 1, 'indices': ['CAC 40'], # add new index to existing database 'currencies': ['EUR'], 'db_args': { 'provider': 'sqlite', 'filename': 'demo.sqlite', }, } sync = SyncDataBaseStocks(config, logger) sync.build()
Getting database objects:
import datetime from pony.orm import db_session from pystockdb.db.schema.stocks import Price, Stock from pystockdb.tools.base import DBBase # connect to database arguments = { 'db_args': { 'provider': 'sqlite', 'filename': 'test.sqlite', 'create_db': False } } # Read https://docs.ponyorm.org/api_reference.html for other provider settings DBBase(arguments, None) now = datetime.datetime.now() last_week = now - datetime.timedelta(days=7) with db_session: # get ifx stock object stock = Stock.select( (lambda s: 'IFX.F' in s.price_item.symbols.name) ).first() # select ifx.f prices of the last week prices = Price.select( lambda p: p.symbol.name == 'IFX.F' and p.date >= last_week and p.date <= now )
issue tracker
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pystockdb-1.1.1.tar.gz
(12.3 kB
view hashes)
Built Distribution
pystockdb-1.1.1-py3-none-any.whl
(14.5 kB
view hashes)
Close
Hashes for pystockdb-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74183ec64c04c7299fa2ebaa8d0f37d0eb932cacc93a12974360d4bdeb4db67f |
|
MD5 | feecca03d9440ca5d5dc2a1f83ea156f |
|
BLAKE2-256 | 2ca8439085c30ab6bdf24abd4953a7b8dc6f70f817de4b2cb1a058fc4cff5e29 |