Imagine your own custom Twitter Bot posting real-time market updates for your favorite cryptocurrencies. It is possible with Python, , and . Below we will outline a step-by-step process utilizing Python. The bot pulls information from . The metrics for Bitcoin, Ethereum, Litecoin stored as formatted variables and tweeted out automatically every 30 minutes. Tweepy LunarCRUSH LunarCRUSH Setting up a Twitter Development Account and Tweepy Let’s start off by installing . It’s simple enough through terminal using the pip command: Tweepy pip install tweepy Next, you need to create a .Twitter for Developers provides access to the Twitter API in order to Publish and analyze Tweets, optimize ads, and create unique customer experiences. Check out the . You can perform multiple tasks through this API. See below some of them:Post and retrieve tweetsFollow and unfollow usersPost direct messagesBefore you are able to use the Twitter API endpoints, create a developer account and generate your API keys. . You must answer questions on how you plan to use the API and accept the Twitter Developer Agreement, and then you will be granted access to the Developer Dashboard.Once you are approved access to the Developers for Twitter, log in to the and create your App. This step will automatically generate your consumer API keys and access tokens, remember, you should keep them secret: Twitter developer account Twitter API documentation here You can apply for a developer account directly here developer site The developer account should be linked to the Twitter account where you want to have the bot active. From the Twitter Development platform, you are able to edit the app permissions. In my example, I have granted my app permission to read, write and send direct messages. Introduction to LunarCRUSH — Social Listening For Crypto In order to start pulling in cryptocurrency social insights, you must head over to and set up an account. LunarCRUSH.com In the left-hand navigation, head to Developers and select API Docs. Generate V2 API Key Once you are in the API Docs, generate your V2 API Key. Building a Twitter bot with Python, Tweepy, LunarCRUSH Let’s start building our Twitter bot. As mentioned previously, you will use the which works seamlessly with Twitter API and LunarCRUSH API / LunarSTREAM™.First, import . Tweepy makes it easier to authenticate to the API through our Twitter App secret keys.Below is an extract of code, do this by creating a instance to bypassing the consumer key and consumer secret as arguments.In order to be able to make requests to the API, send back an access token. Use the method to store the access request token for our session. . Note that I have included ‘ instead of my real secret keys. Replace ‘ with your secret keys that you can obtain in your . Tweepy library tweepy OAuthHandler handle our login auth.set_access_token Now, you are ready to control our Twitter Account with Python XXX’ XXX’ Twitter Developers Dashboard tweepy urllib.request ssl json time ssl._create_default_https_context = ssl._create_unverified_context consumer_key = consumer_secret = access_token = access_token_secret = auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) import import import import import # Oauth keys "XXX" "XXX" "XXX" "XXX" # Authentication with Twitter Our variable is where you store the auth settings. You will use it to make requests to the Twitter API.The idea of this twitter bot is to publish a different tweet, every x amount of minutes with specific cryptocurrency coin / token metrics. This can be easily done using & .Let’s add our LunarCRUSH API Keys to the code. Simply add: api LunarCRUSH API LUNARSTREAM™ api_key = "XXX" Now you are authenticated with LunarCRUSH API. It is time to decide which Cryptocurrencies you would like to integrate into your tweets. Use to store the different crypto symbols. For instance, ‘LTC’ is Litecoin, ‘ETH’ is Ethereum, and ‘BTC’ is Bitcoin. coin_list coin_list = [ , , ] coins = .join(coin_list) # Allows adding as many coins as desired "LTC" "ETH" "BTC" ',' A list of the fields desired from the API — key is the LunarCRUSH key, and the value is the field name outputted to Twitter. { : } "LUNAR_CRUSH_KEY" "RENDERED_NAME" For example, to add tweet_replies: { : }, "tweet_replies" "Tweet Replies: " you would add this to the list below. List comprehensions provide a concise way to create lists. Common applications are to make new lists where each element is the result of some operations applied to each member of another sequence or iterable, or to create a subsequence of those elements that satisfy a certain condition. — Python Data Structures Docs Now you can map which values you would like to pull from LunarCRUSH API. As the program becomes more complex, this should be written in a more robust manner. map = [ { : }, { : }, { : }, { : }, { : }, { : }, { : }, { : }, { : }, { : }, { : }, { : }, { : }, { : }, "name" "" "symbol" "" "price" " Price: " "percent_change_24h" " - 24 Hour Percent Change: " "market_cap" " Market Cap: " "volume_24h" " 24 Hour Volume: " "url_shares" " URL Shares: " "reddit_posts" " Reddit Posts: " "tweets" " Tweets: " "galaxy_score" " Galaxy Score: " "volatility" " Volatility: " "social_volume" " Social Volume: " "news" " News: " "close" " Close: " Now, iterate over each of the fields from LunarCRUSH which gets the value from LunarCRUSH and renders it with the field name. url = + api_key + + coins assets = json.loads(urllib.request.urlopen(url).read()) asset assets[ ]: asset_tweet = field map: key = list(field.keys())[ ] value = list(field.values())[ ] asset_tweet = final_render(asset_tweet, value, key, asset) print(asset_tweet) print(len(asset_tweet)) api.update_status(status=asset_tweet) : main() time.sleep( ) : def main () "https://api.lunarcrush.com/v2?data=assets&key=" "&symbol=" for in 'data' "" for in 0 0 # Posts tweets # Runs main() every 30 minutes while True 1800 Complete Python Code Full code Github Repository Example Crypto Twitter Bot Tweet Additional Functionalities to Include in a LunarCRUSH + Python Twitter BotNot only can you post tweets; our LunarCRUSH Python Tweepy Twitter Bot can perform additional functionalities.For example:Pull information about a particular Twitter user — Send direct messages — Follow and unfollow users — Block and unblock users — User methods Direct Message Methods Friendship Methods Block Methods Configuration Options It is possible to configure the bot to extract additional features. For example: ?key={API_KEY_HERE} - Required to render the widgets. ?symbol=BTC - Change the symbol that displayed the widgets. ?interval= Week - Change the time interval being displayed the charts (default Week). ?price_correlation=true|false - Show a price line addition to the selected metric (default = false) ?metric=galaxy_score - Change the timeseries metric being displayed (Metric widget only). ?animation=true|false - Show hide component animations (default = true) ?theme={See themes section instructions} ?scrolling=true|false (default = true) - Enable disable scrolling on the widget inner content. Use this you want to set scrolling=false on the iframe a fixed height but still want to allow scrolling within the widget. is in 1 in is 1 in or for or if with You have the ability to configure and add all available metrics from LunarCRUSH: market_cap (Market Cap) galaxy_score (Galaxy Score) price_score (Price Score) average_sentiment (Average Sentiment) social score (Social Impact Score) market_cap (Market Cap) galaxy_score (Galaxy Score) price_score (Price Score) average_sentiment (Average Sentiment) social score (Social Impact Score) correlation_rank (Correlation Rank) volatility (Volatility) social_score (Social Volume) social_volume (Social Volume) twitter_volume (Twitter Volume) reddit_volume (Reddit Volume) news_volume (News Volume) search_volume (Search Volume) spam_volume (Spam Volume) bullish_sentiment (Bullish Sentiment) bearish_sentiment (Bearish Sentiment) Metrics Widgets average_sentiment (Average Sentiment) correlation_rank (Correlation Rank) galaxy_score (Galaxy Score) market_cap (Market Cap) market rank (Market Cap Rank) news_articles (News Volume) popular_tweet (Popular Tweets) price_btc (Price BTC) price_score (Price Score) priceclose (Price Close) pricehigh (Price High) pricelow (Price Low) priceopen (Price Open) reddit_comment (Reddit Comments) reddit_post (Reddit Posts) reddit reddit_comment (Reddit Volume) search_average (Search Volume) social score (Social Impact Score) social_score (Social Volume) tweet (Twitter Volume) tweet_sentiment1 (Very Bearish Sentiment) tweet_sentiment2 (Bearish Sentiment) tweet tweet_sentiment (Negative Sentiment) tweet_sentiment3 (Neutral Sentiment) tweet_sentiment4 (Bullish Sentiment) tweet_sentiment5 (Very Bullish Sentiment) tweet sentiment5 (Positive Sentiment) tweet impact1 (Very Bearish Sentiment Impact) tweet impact2 (Bearish Sentiment Impact) tweet impact3 (Neutral Sentiment Impact) tweet impact4 (Bullish Sentiment Impact) tweet impact5 (Very Bullish Sentiment Impact) tweet_spam (Spam Volume) volatility (Volatility) volumefrom (Market Volume Open) volumeto (Market Volume Close) _impact_ _impact_ _cap_ _post_ _impact_ _sentiment2_ _sentiment4_ _sentiment_ _sentiment_ _sentiment_ _sentiment_ _sentiment_ Final Thoughts Within a few lines of code, your easily configurable Twitter bot now pulls data from LunarCRUSH and automatically engages your audience with real-time reliable social insights.There are a few things that can be done to improve the code, such as additional LunarCRUSH parameters to tweet robust cryptocurrency data or visually appealing tweets with images and hashtags.Please let me know in the comments if you have any questions or suggestions. Share your knowledge, open source your projects, participate in a community (any community!), and maybe just maybe publish a blog post about it. Knowledge is Power! Constructive criticism and feedback are welcomed. Nicholas Resendez can be reached on Instagram @nirholas , on LinkedIn , and Twitter @nickresendez for updates on new articles.