Cryptocurrency has always been in a strange territory because of the hostility aimed towards them, mostly due to fear of its capability and technology. Hence no technical or fundamental indicators are actually driving their prices rather than the pure sentiments of the community.

Although the majority of sentiment surrounding the crypto market is driven by Bitcoin, some alt coins have unique factors which affects their variance in the market.

There are multiple ways of performing sentiment analysis especially on tweets, since we’re going to use them as our primary metric in this article. We highlight 2 methods of performing them, the first being through Python and using Twitter’s API called Tweepy:

  1. For running sentiment analysis on tweets, we require twitter’s API called tweepy (python client). We need to first register an app through your twitter account for fetching tweets through the Twitter API.

Authentication and registration of the app is required in order to obtain consumer key, consumer secret key, Access token and Access Token Secret key for accessing tweets through your Twitter account.

We make use of textblob which is the python library for processing textual data. 

  • Tokenize the tweet ,i.e split words from body of text.
  • Remove stopwords from the tokens.(stopwords are the commonly used words which are irrelevant in text analysis like I, am, you, are, etc.)
  • Do POS( part of speech) tagging of the tokens and select only significant features/tokens like adjectives, adverbs, etc.
  • Pass the tokens to a sentiment classifier which classifies the tweet sentiment as positive, negative or neutral by assigning it a polarity between -1.0 to 1.0.
  • Next we need a Natural Language Toolkit (NLTK), which contains libraries for natural language processing (NLP). Here we use NLTK corpus, which is a massive dump of all kinds of natural language data sets. It is essentially a large and structured set of texts.
  • The sentiment classifier on textblob is created in the following way:
  • TextBlob uses a Movies Reviews dataset in which reviews have already been labelled as positive or negative.
  • Positive and negative features are extracted from each positive and negative review respectively.
  • Training data now consists of labelled positive and negative features. This data is trained on a Naive Bayes Classifier.


Here we run an example by using the query word “Bitcoin”

By requesting this query, the algorithm analyzes the trending tweets and performs sentiment analysis through the methods mentioned above. 

Here we see the sentiments surrounding Bitcoins price according to the sentiment analysis run by this algorithm. However, this is a simple algorithm which can be easily implemented by anyone who has access to Python and a Twitter developer account. It checks the sentiments surrounding the trending tweets.

Here we take a look at the entire python code for further reference:

credit – Geek for Geeks 

import re 

import tweepy 

from tweepy import OAuthHandler 

from textblob import TextBlob 

class TwitterClient(object): 


    Generic Twitter Class for sentiment analysis. 


    def __init__(self): 


        Class constructor or initialization method. 


        # keys and tokens from the Twitter Dev Console 

        consumer_key = ‘xxxxxxxxxx’

        consumer_secret = ‘xxxxxxxxxxx’

        access_token = ‘xxxxxxxxxxxxxxxxx’

        access_token_secret = ‘xxxxxxxxxxxxxxxxxx’

        # attempt authentication 


            # create OAuthHandler object 

            self.auth = OAuthHandler(consumer_key, consumer_secret) 

            # set access token and secret 

            self.auth.set_access_token(access_token, access_token_secret) 

            # create tweepy API object to fetch tweets 

            self.api = tweepy.API(self.auth) 


            print(“Error: Authentication Failed”) 

    def clean_tweet(self, tweet): 


        Utility function to clean tweet text by removing links, special characters 

        using simple regex statements. 


        return ‘ ‘.join(re.sub(“(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)”, ” “, tweet).split()) 

    def get_tweet_sentiment(self, tweet): 


        Utility function to classify sentiment of passed tweet 

        using textblob’s sentiment method 


        # create TextBlob object of passed tweet text 

        analysis = TextBlob(self.clean_tweet(tweet)) 

        # set sentiment 

        if analysis.sentiment.polarity > 0: 

            return ‘positive’

        elif analysis.sentiment.polarity == 0: 

            return ‘neutral’


            return ‘negative’

    def get_tweets(self, query, count = 10): 


        Main function to fetch tweets and parse them. 


        # empty list to store parsed tweets 

        tweets = [] 


            # call twitter api to fetch tweets 

            fetched_tweets = = query, count = count) 

            # parsing tweets one by one 

            for tweet in fetched_tweets: 

                # empty dictionary to store required params of a tweet 

                parsed_tweet = {} 

                # saving text of tweet 

                parsed_tweet[‘text’] = tweet.text 

                # saving sentiment of tweet 

                parsed_tweet[‘sentiment’] = self.get_tweet_sentiment(tweet.text) 

                # appending parsed tweet to tweets list 

                if tweet.retweet_count > 0: 

                    # if tweet has retweets, ensure that it is appended only once 

                    if parsed_tweet not in tweets: 




            # return parsed tweets 

            return tweets 

        except tweepy.TweepError as e: 

            # print error (if any) 

            print(“Error : ” + str(e)) 

def main(): 

    # creating object of TwitterClient Class 

    api = TwitterClient() 

    # calling function to get tweets 

    tweets = api.get_tweets(query = ‘Bitcoin’, count = 200) 

    # picking positive tweets from tweets 

    ptweets = [tweet for tweet in tweets if tweet[‘sentiment’] == ‘positive’] 

    # percentage of positive tweets 

    print(“Positive tweets percentage: {} %”.format(100*len(ptweets)/len(tweets))) 

    # picking negative tweets from tweets 

    ntweets = [tweet for tweet in tweets if tweet[‘sentiment’] == ‘negative’] 

    # percentage of negative tweets 

    print(“Negative tweets percentage: {} %”.format(100*len(ntweets)/len(tweets))) 

    #picking neutral tweets from tweets 

    neutraltweets = [tweet for tweet in tweets if tweet[‘sentiment’] == ‘neutral’]

    # percentage of neutral tweets 

    print(“Neutral tweets percentage: {} %”.format(100*len(neutraltweets)/len(tweets)))

    # printing first 5 positive tweets 

    print(“\n\nPositive tweets:”) 

    for tweet in ptweets[:10]: 


    # printing first 5 negative tweets 

    print(“\n\nNegative tweets:”) 

    for tweet in ntweets[:10]: 


    if __name__ == “__main__”: 

    # calling main function 


The second method is through analyzing Twitter hashtags using a tool known as Keyhole:

This tool analyzes tweets based on hashtags of a specific keyword rather than looking for the keyword within the tweet itself.

Here we can see the result of running the keyhole hashtag analysis tool for a day. There’s additional information we can gather from Keyhole for market analysis, like social media account analytics and influencer management. 

These are how the tweets get segregated into different sentiment categories and how more engagements with a tweet (retweeting, commenting etc) drives that particular sentiment (good or bad). 

Now let’s take a look at how sentiments have affected the price of Bitcoin in the past and how it persuades people to identify it as a trigger for investing in the market. 

A prime example of how sentiments drive the cryptocurrency community is the April fools prank that took place on April 1st of this year.

Bitcoin was on its knees recovering from a bear market, unable to break any significant resistance levels. There was suddenly an unexpected 23% rally that drove its price up to $5,023, bringing its price to its 4 month high.

This was apparently due to a spoof article that was being circulated as an April Fool’s joke, stating that the U.S. Securities and Exchange Commission (SEC) had approved two Bitcoin Exchange-Traded Funds (ETF). 

Even Bloomberg covered this in their article titled, “April Fools: Traders Chase Another Unexplainable Bitcoin Rally”, which covered the unexplainable pump related to the farce information being circulated. 

There is a direct correlation between sentiments in the crypto community and their prices that drive it. As we can see in the above sentiment analysis that we performed on both Python as well as Keyhole, there is very high positivity surrounding Bitcoin’s current bullrun which is further driving its price up. Most other cryptocurrencies prices are directly related to how well Bitcoin is doing (with exceptions to a few) in the current market. 

Leave a comment

Podcast suggestions of the week

TechMerge © 2019 . All rights reserved.