コード例 #1
0
ファイル: views.py プロジェクト: soncojmk/sunnytradeBACKEND
def get_link(ticker_symbol, page=None):
    """
    Gets the article for the target ticker symbol
    :param ticker_symbol: The ticker symbol of the interested stock (e.g., "AAPL", "GOOG", "MSFT")
    :param page: html tree structure based on the html markup of the scraped website
    :return: a string of the percentage of bearish sentiment as listed on a stock's StockTwits page
    """
    if page is None:
        page = scrape_page(BLOOMBERG_URL + ticker_symbol)

    sentiment = page.xpath(LINK_XPATH)

    if not sentiment:
        return None
    else:
        return sentiment[0].replace("\n", "")
コード例 #2
0
ファイル: views.py プロジェクト: soncojmk/sunnytradeBACKEND
def get_bullish_sentiment(ticker_symbol, page=None):
    """
    Gets the bullish sentiment of the target ticker symbol
    :param ticker_symbol: The ticker symbol of the interested stock (e.g., "AAPL", "GOOG", "MSFT")
    :param page: html tree structure based on the html markup of the scraped website
    :return: a string of the pe rcentage of bullish sentiment as listed on a stock's StockTwit's page
    """
    if page is None:
        page = scrape_page(BASE_URL + ticker_symbol)

    sentiment = page.xpath(BULLISH_SENTIMENT_XPATH)

    if not sentiment:
        return None
    else:
        return sentiment[0].replace("\n", "") + " Bullish"
コード例 #3
0
ファイル: views.py プロジェクト: soncojmk/sunnytradeBACKEND
def get_sentiment(ticker_symbol, page=None):
    """
    Gets both the bullish and bearish sentiment of the target ticker symbol
    :param ticker_symbol: The ticker symbol of the interested stock (e.g., "AAPL", "GOOG", "MSFT")
    :param page: html tree structure based on the html markup of the scraped website
    :return: a tuple of strings containing both the bullish and bearish sentiment as listed on a stock's
    StockTwits page
    """
    if page is None:
        page = scrape_page(BASE_URL + ticker_symbol)

    #get strings
    bullish_sentiment = get_bullish_sentiment(ticker_symbol, page)
    bearish_sentiment = get_bearish_sentiment(ticker_symbol, page)
    price = get_price(ticker_symbol, page)
    name = get_name(ticker_symbol, page)

    title = get_title(ticker_symbol, page)
    article = get_article(ticker_symbol, page)
    link = get_link(ticker_symbol, page)

    my_trader = Robinhood()
    logged_in = my_trader.login(username=username, password=password)
    description = my_trader.get_fundamentals(ticker_symbol)
    news = my_trader.get_news(ticker_symbol)

    #see strings for verification
    #print(bullish_sentiment);
    #print(bearish_sentiment);

    #find digits in string
    bull = int(''.join(list(filter(str.isdigit, bullish_sentiment))))
    bear = int(''.join(list(filter(str.isdigit, bearish_sentiment))))
    #price=int(''.join(list(filter(str.isdigit, price))))
    #print(bull)
    #print(bear)

    return Response({
        "bullish": bull,
        "bearish": bear,
        "price": price,
        "name": name,
        "description": description,
        "news": news
    })
    '''