GithubHelp home page GithubHelp logo

ycharts / pycharts Goto Github PK

View Code? Open in Web Editor NEW
22.0 18.0 12.0 34 KB

Python client for the YCharts API

Home Page: https://pypi.python.org/pypi/pycharts

License: MIT License

Python 100.00%
mutual-funds ycharts api client pycharts python-client

pycharts's Introduction

pycharts

Python client for the YCharts Market Data API.

Requirements

  • Python ( 3.x )
  • Valid API key from YCharts.

Installation

Install from github using pip.

pip install git+https://github.com/ycharts/pycharts.git
# or
pip install pycharts

Documentation and Support

Full API documentation can be found at https://www.ycharts.com/api/docs/.

For questions and information about API access, visit YCharts or email us ([email protected]) for more info.

Examples

Below are some examples to get started with using the Python Client.

Setup

from pycharts import CompanyClient, IndicatorClient, MutualFundClient

ycharts_api_key = 'sample-api-key'

company_client = CompanyClient(ycharts_api_key)
mutual_fund_client = MutualFundClient(ycharts_api_key)
indicator_client = IndicatorClient(ycharts_api_key)

Discovery Queries

Gets a paginated list of companies, mutual funds or indicators.

companies = company_client.get_securities(exchange='NYSE')
mutual_funds = mutual_fund_client.get_securities(category='Technology')
indicators = indicator_client.get_securities(region='USA')

Data Point Queries

Get a single date-value pair of data from one or more securities for one or more calculations. It takes an optional date parameter and will return the latest value before the requested date.

# Queries the latest price values for AAPL and MSFT
point_rsp = company_client.get_points(['AAPL', 'MSFT'], ['price'])
# Queries the latest net asset value for M:FCNTX
point_rsp = mutual_fund_client.get_points('M:FCNTX', ['net_asset_value'])
# Queries the latest value for I:USICUI
point_rsp = indicator_client.get_points('I:USICUI')

# Queries the price values for AAPL 21 days ago
previous_point_rsp = company_client.get_points('AAPL', 'price', query_date=-21)
# Queries the net asset value for M:FCNTXPL 21 days ago
twenty_one_days_ago = datetime.datetime.now() - datetime.timedelta(days=21)
previous_point_rsp = mutual_fund_client.get_points('M:FCNTX', ['net_asset_value'], 
    query_date=twenty_one_days_ago)
# Queries the value for I:USICUI 21 days ago
previous_point_rsp = indicator_client.get_points('I:USICUI', query_date=-31)

Data Series Queries

Get a series of date-value pairs of data from one or more securities for one or more calculations. It takes optional start_date and end_date parameters and will return all values between the requested dates.

now = datetime.datetime.now()
past = now - datetime.timedelta(days=100)

series_rsp = company_client.get_series(['AAPL', 'MSFT'], ['price'],
    query_start_date=past , query_end_date=now)
    
series_rsp = mutual_fund_client.get_series('M:FCNTX', ['net_asset_value'], 
    query_start_date=past , query_end_date=now)
    
series_rsp = indicator_client.get_series('I:USICUI',
    query_start_date=past , query_end_date=now)

# example resampling request
series_rsp = company_client.get_series(['AAPL', 'MSFT'], ['price'], query_start_date=past, 
    query_end_date=now, resampling_frequency='daily', resampling_function='mean')

Info Queries

Get information about one or more securities.

info_rsp = company_client.get_info(['AAPL', 'MSFT'], ['description'])
info_rsp = mutual_fund_client.get_info('M:FCNTX', ['inception_date', 'broad_asset_class'])
info_rsp = indicator_client.get_info('I:USICUI', ['next_release'])

Dividend Queries

Get dividends from one or more companies or mutual funds.

start_date = datetime.datetime(2015, 1, 1)

dividend_rsp = company_client.get_dividends(['AAPL', 'MSFT'], ex_start_date=start_date, 
    dividend_type='special')
dividend_rsp = mutual_fund_client.get_dividends('M:FCNTX', ex_start_date=start_date)

Stock Split and Spinoff Queries

Get a list of stock split/spinoff objects that within the date range specified by the optional start and end date parameters.

split_spinoff_end_date = datetime.datetime(2014, 1, 1)
split_rsp = company_client.get_stock_splits(['AAPL'], split_end_date=split_spinoff_end_date)
spinoff_rsp = company_client.get_stock_spinoffs(['AAPL'], spinoff_end_date=split_spinoff_end_date)

Exceptions

# More exception classes in pycharts/exceptions.py
from pycharts import exceptions


try:
    bad_point_rsp = company_client.get_points(['AAPL'], ['price'], query_date=45)
except exceptions.PyChartsRequestException as pycharts_error:
    print(pycharts_error.error_message)

pycharts's People

Contributors

ara818 avatar jpo424 avatar kfoxder avatar michaeljmath avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pycharts's Issues

Initial Update

Hi ๐Ÿ‘Š

This is my first visit to this fine repo, but it seems you have been working hard to keep all dependencies updated so far.

Once you have closed this issue, I'll create separate pull requests for every update as soon as I find one.

That's it for now!

Happy merging! ๐Ÿค–

base_url update

I got an email from YCharts saying that the request URL will be changing effective September 9, 2021. I can edit the base url in my project but are there plans to update the package with the proper URL?

Old request URL:ย https://ycharts.com
New request URL:ย https://api.ycharts.com

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.