示例#1
0
def get_crypto_historical(symbol, interval, span, bound, info=None):
    """Gets historical information about a crypto including open price, close price, high price, and low price.

    :param symbol: The crypto ticker.
    :type symbol: str
    :param interval: The time between data points. Can be '15second', '5minute', '10minute', 'hour', 'day', or 'week'.
    :type interval: str
    :param span: The entire time frame to collect data points. Can be 'hour', 'day', 'week', 'month', '3month', 'year', or '5year'.
    :type span: str
    :param bound: The times of day to collect data points. 'Regular' is 6 hours a day, 'trading' is 9 hours a day, \
    'extended' is 16 hours a day, '24_7' is 24 hours a day
    :type bound: str
    :param info: Will filter the results to have a list of the values that correspond to key that matches info.
    :type info: Optional[str]
    :returns: [list] If info parameter is left as None then the list will contain a dictionary of key/value pairs for each ticker. \
    Otherwise, it will be a list of strings where the strings are the values of the key that corresponds to info.
    :Dictionary Keys: * data_points
                      * bounds
                      * interval
                      * span
                      * symbol
                      * id
                      * open_price
                      * open_time
                      * previous_close_price
                      * previous_close_time

    """
    interval_check = ['15second', '5minute', '10minute', 'hour', 'day', 'week']
    span_check = ['hour', 'day', 'week', 'month', '3month', 'year', '5year']
    bounds_check = ['24_7', 'extended', 'regular', 'trading']

    if interval not in interval_check:
        print(
            'ERROR: Interval must be "15second","5minute","10minute","hour","day",or "week"'
        )
        return ([None])
    if span not in span_check:
        print(
            'ERROR: Span must be "hour","day","week","month","3month","year",or "5year"'
        )
        return ([None])
    if bound not in bounds_check:
        print('ERROR: Bounds must be "24_7","extended","regular",or "trading"')
        return ([None])
    if (bound == 'extended' or bound == 'trading') and span != 'day':
        print(
            'ERROR: extended and trading bounds can only be used with a span of "day"'
        )
        return ([None])

    id = get_crypto_info(symbol, info='id')
    url = urls.crypto_historical(id, interval, span, bound)
    data = helper.request_get(url)
    return (helper.filter(data, info))
示例#2
0
def get_crypto_historical_from_id(id, interval, span, bound, info=None):
    """Gets historical information about a crypto including open price, close price, high price, and low price using id

    :param id: The id of a crypto.
    :type id: str
    :param interval: The time between data points.
    :type interval: str
    :param span: The entire time frame to collect data points.
    :type span: str
    :param bound: The times of dat to collect data points.
    :type bound: str
    :param info: Will filter the results to have a list of the values that correspond to key that matches info.
    :type info: Optional[str]
    :returns: If info parameter is left as None then the list will contain a dictionary of key/value pairs for each ticker. \
    Otherwise, it will be a list of strings where the strings are the values of the key that corresponds to info.

    """
    interval_check = ['15second', '5minute', '10minute', 'hour', 'day', 'week']
    span_check = ['hour', 'day', 'week', 'month', '3month', 'year', '5year']
    bounds_check = ['24_7', 'extended', 'regular', 'trading']

    if interval not in interval_check:
        print(
            'ERROR: Interval must be "15second","5minute","10minute","hour","day",or "week"'
        )
        return ([None])
    if span not in span_check:
        print(
            'ERROR: Span must be "hour","day","week","month","3month","year",or "5year"'
        )
        return ([None])
    if bound not in bounds_check:
        print('ERROR: Bounds must be "24_7","extended","regular",or "trading"')
        return ([None])
    if (bound == 'extended' or bound == 'trading') and span != 'day':
        print(
            'ERROR: extended and trading bounds can only be used with a span of "day"'
        )
        return ([None])

    url = urls.crypto_historical(id, interval, span, bound)
    data = helper.request_get(url)
    return (helper.filter(data, info))
示例#3
0
def get_crypto_historicals(symbol,
                           interval='hour',
                           span='week',
                           bounds='24_7',
                           info=None):
    """Gets historical information about a crypto including open price, close price, high price, and low price.

    :param symbol: The crypto ticker.
    :type symbol: str
    :param interval: The time between data points. Can be '15second', '5minute', '10minute', 'hour', 'day', or 'week'. Default is 'hour'.
    :type interval: str
    :param span: The entire time frame to collect data points. Can be 'hour', 'day', 'week', 'month', '3month', 'year', or '5year'. Default is 'week'
    :type span: str
    :param bound: The times of day to collect data points. 'Regular' is 6 hours a day, 'trading' is 9 hours a day, \
    'extended' is 16 hours a day, '24_7' is 24 hours a day. Default is '24_7'
    :type bound: str
    :param info: Will filter the results to have a list of the values that correspond to key that matches info.
    :type info: Optional[str]
    :returns: [list] If info parameter is left as None then the list will contain a dictionary of key/value pairs for each ticker. \
    Otherwise, it will be a list of strings where the strings are the values of the key that corresponds to info.
    :Dictionary Keys: * begins_at
                      * open_price
                      * close_price
                      * high_price
                      * low_price
                      * volume
                      * session
                      * interpolated
                      * symbol

    """
    interval_check = ['15second', '5minute', '10minute', 'hour', 'day', 'week']
    span_check = ['hour', 'day', 'week', 'month', '3month', 'year', '5year']
    bounds_check = ['24_7', 'extended', 'regular', 'trading']

    if interval not in interval_check:
        print(
            'ERROR: Interval must be "15second","5minute","10minute","hour","day",or "week"',
            file=helper.get_output())
        return ([None])
    if span not in span_check:
        print(
            'ERROR: Span must be "hour","day","week","month","3month","year",or "5year"',
            file=helper.get_output())
        return ([None])
    if bounds not in bounds_check:
        print('ERROR: Bounds must be "24_7","extended","regular",or "trading"',
              file=helper.get_output())
        return ([None])
    if (bounds == 'extended' or bounds == 'trading') and span != 'day':
        print(
            'ERROR: extended and trading bounds can only be used with a span of "day"',
            file=helper.get_output())
        return ([None])

    symbol = helper.inputs_to_set(symbol)
    id = get_crypto_info(symbol[0], info='id')
    url = urls.crypto_historical(id)
    payload = {'interval': interval, 'span': span, 'bounds': bounds}
    data = helper.request_get(url, 'regular', payload)

    histData = []
    cryptoSymbol = data['symbol']
    for subitem in data['data_points']:
        subitem['symbol'] = cryptoSymbol
        histData.append(subitem)

    return (helper.filter_data(histData, info))