Demo entry 5160206

essai

   

Submitted by essai on Jun 07, 2016 at 10:17
Language: Python 3. Code size: 994 Bytes.

def returnQueryUrl(exchange, symbol, startDate, endDate, indicatorName,
                   **kwargs):
    '''
    Return the url to query the data from Stockvider API.
    
    exchange (str): name of the stock exchange.
    symbol (str): name of the symbol.
    startDate (date): start date of the data.
    endDate (date): end date of the data.
    indicatorName (str): name of the indicatior.
    
    '''
    
    # Build the basic part of the url.
    # Made of: the exchange, the symbol, the indicator name and the start and
    # end dates.
    url = 'https://api.stockvider.com/data/' + exchange.upper() + '/' + symbol.upper() + '/' + indicatorName
    url += '?start_date=' + startDate.strftime('%Y-%m-%d') + '&end_date=' + endDate.strftime('%Y-%m-%d')
    
    # Add any query parameters (contained in kwargs) to the url (api_key, time_period, ...)
    for (key, value) in kwargs.items():
        url += '&' + str(key) + '=' + str(value)
        
    return url

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).