Skip to main content

Database for stocks this package provides an create, sync and update tool.

Project description

pystockdb

Release Build PyPI - Downloads Coverage Status Codacy Badge

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. Database for stocks this package provides an create, sync and update tool.

install

pip install pystockdb

database schema

StockDB 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

https://github.com/portfolioplus/pystockdb/issuese

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

pystockdb-1.2.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

pystockdb-1.2.1-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file pystockdb-1.2.1.tar.gz.

File metadata

  • Download URL: pystockdb-1.2.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for pystockdb-1.2.1.tar.gz
Algorithm Hash digest
SHA256 3b071db88600fd8ec1dfbd6df0a234337dfa23f4ef9aa409cee3b65e9e879579
MD5 c5e5500c4e5385a7484c49fdc21528fd
BLAKE2b-256 9037bfa873c780f8f5e1b50c2aad90d8215408ddfb4476860bbd3314dd36c809

See more details on using hashes here.

File details

Details for the file pystockdb-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: pystockdb-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for pystockdb-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 88766a25f18854154094708b359176390554a3fed1d183a97231885a6a22894e
MD5 5390b23a65f6cf8212d973900c36837d
BLAKE2b-256 ebbc8ee69220d840ead2a5fe06949a8707c73bb8cdefe8ddcfd6c961a70ee2eb

See more details on using hashes here.

Supported by

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