Elon Musk tweeting about DOGE

Sanidhya Singh
3 min readMar 7, 2021

Dogecoin is an open-source cryptocurrency which was started in 2013 as a joke, inspired by the doge meme. Over the last one year, the price of dogeocin has increased by 2,000%! This meteoric rise of Dogecoin stemmed from the WallStreetBets movement and it has got Elon Musk interested.

Tesla recently invested $1.5 billion in Bitcoin and Musk has shared his intention to do the same with Dogecoin, hoping to make it the “people’s crypto”.

In this article, we will try to pull in the historical pricing information for Dogecoin and tweets from Elon Musk that talk about it in an effort to establish if they affect the price of Doge.

We will leverage CoinAPI.io for historical dogecoin prices, head on over to their website and sign up for their free API.

import requestsparams = {'X-CoinAPI-Key': '<your_API_key>'}# query Dogecoin prices in USD from Jan 1, 2021 onwards
url = 'https://rest.coinapi.io/v1/ohlcv/DOGE/USD/history?period_id=1DAY&time_start=2021-01-01T00:00:00&time_end=2021-03-08T00:00:00'
r = requests.get(url, headers = params)# parse the results in a nice DataFrame
rows = []
for x in r.json():
rows.append([x['time_period_start'][0:10], x['price_close']])
df = pd.DataFrame(rows)
df.columns = ['date', 'DOGE (USD)']
display(df)

Using the historical data API from CoinAPI, we get:

Dogecoin prices in USD

Now, we need to extract Tweets from Elon Musk, specifically the ones talking about Doge. For this, we will be using tweepy, a nice python library that provides easy access to the Twitter API via Python. As usual, you will also require Twitter API tokens, refer to the Twitter Developer page and sign up for a free API.

twitter_key = '<your_Twitter_API_key>'
twitter_api_secret = '<your_Twitter_API_secret>'
import tweepy# authenticate
auth = tweepy.OAuthHandler(twitter_key, twitter_api_secret)
api = tweepy.API(auth)
# parse tweets from Musk containing 'doge' into a nice DataFrame
DataFrame
doge_tweets = []
for tweet in tweepy.Cursor(api.user_timeline, screen_name='@elonmusk', exclude_replies=False, include_rts=True, count=1000).items():
if "doge" in tweet.text.lower():
doge_tweets.append([str(tweet.created_at)[0:10],
df[df['date'] == str(tweet.created_at)[0:10]].iloc[0]['DOGE (USD)'],
tweet.text])
doge_tweets = pd.DataFrame(doge_tweets)
doge_tweets.columns = ['date', 'doge_price', 'tweet_text']
display(doge_tweets)

Using the user_timeline method from tweepy, we get:

Now, to tie it all together we will use Plotly to visualize the price of Dogecoin and use markers to denote when Elon tweeted about it.

import plotly.express as px
import plotly.graph_objects as go
fig = px.area(df, x='date', y="DOGE (USD)", template='plotly_dark')
fig.add_trace(go.Scatter(mode="markers", x=doge_tweets["date"],
y=doge_tweets["doge_price"], name="Elon tweets about DOGE",
text=doge_tweets['tweet_text'],
textposition='top right',
textfont=dict(color='#E58606'),))
fig.show()

From the plot, it is evident that Elon tweeting about Doge directly affects the price as we can see significant deviation from the preceding day at every Tweet, both positively and negatively. As a further step, we can perform sentiment analysis on the Tweet to investigate if Elon talking positively about Doge, increases its price.

--

--