Esempio n. 1
0
def get_intraday(ticker,
                 start=(date.today() - timedelta(days=1)),
                 end='+1',
                 interval='5m'):
    start, end = _prepare_datetimes(start, end)
    log.info("request: %s - > %s - %s", ticker,
             dth.get_datetime_timestamp(start),
             dth.get_datetime_timestamp(end))
    url = common.baseurl_intraday + ticker + '?' + 'api_token=' + common.apitoken + '&fmt=json&from=' + \
        str(start) + '&to=' + str(end) + '&interval=' + interval
    log.info(url)
    response = requests.get(url)
    common.check_response_status(response)
    return response.json()
Esempio n. 2
0
def get_eod(ticker,
            start=(date.today() - timedelta(days=1)),
            end="+1",
            period="d"):
    start, end = _prepare_datetimes(start, end, False)
    log.info("request: %s - > %s - %s", ticker, start, end)
    url = common.baseurl_eod + ticker + '?' + 'api_token=' + common.apitoken + '&fmt=json&from=' + \
        str(start) + '&to=' + str(end) + '&period=' + period
    log.info(url)
    response = requests.get(url)
    common.check_response_status(response)
    internal_data = response.json()
    start, end = _get_start_end_date(internal_data)
    internal_data = {
        "ticker": ticker,
        "startdate": start,
        "enddate": end,
        "inserted": dth.now_as_string(),
        "data": internal_data
    }
    return internal_data
Esempio n. 3
0
def get_exchange_tickers(exchange):
    log.info("request all tickers of exchange %s", exchange)
    url = common.baseurl_exchange_tickers + exchange + '?' + \
        "api_token=" + common.apitoken + "&fmt=json"
    log.info(url)
    result = requests.get(url).json()
    log.info("found %s tickers for exchange %s", len(result), exchange)
    return result
Esempio n. 4
0
def get_exchange_details(exchange):
    log.info("request details of exchange %s", exchange)
    url = common.baseurl_exchange_details + exchange + '?' + \
        "api_token=" + common.apitoken + "&fmt=json"
    log.info(url)
    result = requests.get(url).json()
    log.info("found details for exchange %s", exchange)
    return result
Esempio n. 5
0
def get_exchange_list():
    log.info("request list of exchanges")
    url = common.baseurl_exchange_list + '?' + \
        "api_token=" + common.apitoken + "&fmt=json"
    log.info(url)
    result = requests.get(url).json()
    log.info("found %s exchanges", len(result))
    return result
Esempio n. 6
0
def get_stock_fundamentals(ticker):
    log.info("request fundamentals for %s", ticker)
    url = common.baseurl_fundamental + ticker + '?' + \
        "api_token=" + common.apitoken + "&fmt=json"
    log.info(url)
    for i in range(10):
        try:
            log.info("%s try to receive date for %s", i + 1, ticker)
            result = requests.get(url).json()
            break
        except json.decoder.JSONDecodeError:
            log.warn("Could not receive data for %s. Waiting and try again",
                     ticker)
            time.sleep(30)
    return result
Esempio n. 7
0
def download_logo(ticker, sub_url, force=False):
    url = common.baseurl_logo + sub_url
    logodir = _logo_file_path + (str(sub_url).rsplit('/', 1)[0])[1:]
    if os.path.isfile(_logo_file_path + sub_url) and not force:
        log.info("logo for %s allready exists on path: %s", ticker,
                 _logo_file_path + sub_url)
    else:
        log.info("request logo for %s, URL: %s and Path: %s", ticker, url,
                 logodir)
        if not os.path.exists(logodir):
            os.makedirs(logodir)

        for i in range(10):
            try:
                urllib.request.urlretrieve(url, _logo_file_path + sub_url)
            except urllib.error.HTTPError as httpError:
                log.error("Could not download Logo for %s %s", ticker,
                          str(httpError))
                break
            except urllib.error.URLError as urlError:
                log.error("Could not download Logo for %s %s. Retry: %s of 10",
                          ticker, str(urlError), i)
                time.sleep(30)
                continue

        filesize = os.path.getsize(_logo_file_path + sub_url)
        if filesize < 62:
            log.error("Filesize of %s is just %s", sub_url, filesize)
            os.remove(_logo_file_path + sub_url)
            raise RuntimeError(sub_url + " is corrupted")
        if force:
            log.info("logo for %s replaced on path %s", ticker,
                     _logo_file_path + sub_url)
        else:
            log.info("logo for %s downloaded to %s", ticker,
                     _logo_file_path + sub_url)
Esempio n. 8
0
def get_index_constituents(index, incl_delist=False, only_ticker=True):
    log.info("request constituents of %s", index)
    url = common.baseurl_fundamental + index + '?' + \
        "api_token=" + common.apitoken + "&fmt=json"
    log.info(url)
    result = requests.get(url).json()
    if not incl_delist:
        result = result["Components"]
    else:
        result = result["HistoricalTickerComponents"]
    if only_ticker:
        tickers = []
        for i in result:
            entry = result[i]
            tickers.append(entry["Code"] + "." + entry["Exchange"])
        result = tickers
    log.info("found %s constituents for index %s", len(result), index)
    return result
Esempio n. 9
0
def getUserData():
    url = common.baseurl_user + '?' + 'api_token=' + common.apitoken
    log.info(url)
    response = requests.get(url)
    return response.json()