mirror of
https://github.com/hydrosquall/tiingo-python.git
synced 2025-12-17 11:54:19 +01:00
[errors] Validate arguments to get_dataframe
This commit is contained in:
@@ -1,15 +1,16 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
from collections import namedtuple
|
||||||
import sys
|
|
||||||
import pkg_resources
|
|
||||||
import csv
|
import csv
|
||||||
import json
|
import json
|
||||||
from collections import namedtuple
|
import os
|
||||||
from zipfile import ZipFile
|
|
||||||
from tiingo.restclient import RestClient
|
|
||||||
import requests
|
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
|
import pkg_resources
|
||||||
|
from zipfile import ZipFile
|
||||||
|
|
||||||
|
from tiingo.restclient import RestClient
|
||||||
|
from tiingo.exceptions import InstallPandasException, APIColumnNameError, InvalidFrequencyError, MissingRequiredArgumentError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
@@ -49,17 +50,6 @@ def dict_to_object(item, object_name):
|
|||||||
object_hook=lambda d:
|
object_hook=lambda d:
|
||||||
namedtuple(object_name, fields)(*values))
|
namedtuple(object_name, fields)(*values))
|
||||||
|
|
||||||
class InstallPandasException(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class APIColumnNameError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class InvalidFrequencyError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TiingoClient(RestClient):
|
class TiingoClient(RestClient):
|
||||||
"""Class for managing interactions with the Tiingo REST API
|
"""Class for managing interactions with the Tiingo REST API
|
||||||
@@ -227,12 +217,16 @@ class TiingoClient(RestClient):
|
|||||||
frequency (string): Resample frequency (defaults to daily).
|
frequency (string): Resample frequency (defaults to daily).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
valid_columns = ['open', 'high', 'low', 'close', 'volume', 'adjOpen', 'adjHigh', 'adjLow',
|
valid_columns = {'open', 'high', 'low', 'close', 'volume', 'adjOpen', 'adjHigh', 'adjLow',
|
||||||
'adjClose', 'adjVolume', 'divCash', 'splitFactor']
|
'adjClose', 'adjVolume', 'divCash', 'splitFactor'}
|
||||||
|
|
||||||
if metric_name is not None and metric_name not in valid_columns:
|
if metric_name is not None and metric_name not in valid_columns:
|
||||||
raise APIColumnNameError('Valid data items are: ' + str(valid_columns))
|
raise APIColumnNameError('Valid data items are: ' + str(valid_columns))
|
||||||
|
|
||||||
|
if metric_name is None and type(tickers) is not str:
|
||||||
|
raise MissingRequiredArgumentError("""When tickers is provided as a list, metric_name is a required argument.
|
||||||
|
Please provide a metric_name, or call this method with one ticker at a time.""")
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
'resampleFreq': frequency
|
'resampleFreq': frequency
|
||||||
|
|||||||
15
tiingo/exceptions.py
Normal file
15
tiingo/exceptions.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# Exception Clasess
|
||||||
|
class InstallPandasException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class APIColumnNameError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidFrequencyError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class MissingRequiredArgumentError(Exception):
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user