Reply in Telegram with the current price and market figures for any ticker symbol someone asks about.
Uses
CoinMarketCap
Telegram
Look up a crypto price from Telegram
Whenever someone in a Telegram chat your bot is in writes your price keyword followed by a ticker symbol, such as BTC, the bot replies with what CoinMarketCap reports for that coin right now. Any other message is left alone, so it stays quiet in a busy group instead of answering everything.
The reply gives the coin's name, its price in US dollars, the one-hour and 24-hour change, market cap and market cap rank, then two pieces of wider context: the Fear and Greed Index and Bitcoin's share of total market cap. It reports figures and nothing else: no view on what a number means and no suggestion about what to do, and every reply says so. A figure the data does not carry is marked as not reported rather than shown as zero, and a symbol outside the top coins by market cap gets a reply saying it was not found.
You need a Telegram bot in the chat and a CoinMarketCap connection. Prices are always in US dollars.
message.When a new message is received. Save it as message.priceKeyword to blank.Set priceKeyword to blank.coinsSearched to 300.Set coinsSearched to 300.chatId to message.chat_id.Set chatId to message.chat_id.messageText to blank.Set messageText to blank.noTextErrorIf a step below fails, save the error as noTextErrormessage.text and save it as messageText.Trim message.text and save it as messageText.This message carried no text, so there was nothing to look up..Show in the output: This message carried no text, so there was nothing to look up..messageText is emptyIf messageText is emptymessageText by a space and save it as words.Split messageText by a space and save it as words.words[0] lowercase and save it as commandWord.Make words[0] lowercase and save it as commandWord.commandWord is not priceKeyword in lowercaseIf commandWord is not priceKeyword in lowercaserequestedSymbol to blank.Set requestedSymbol to blank.symbolErrorIf a step below fails, save the error as symbolError$ with in words[1] in uppercase and save it as requestedSymbol.Replace $ with in words[1] in uppercase and save it as requestedSymbol.No ticker symbol followed the keyword..Show in the output: No ticker symbol followed the keyword..requestedSymbol is empty or the length of requestedSymbol is greater than 12If requestedSymbol is empty or the length of requestedSymbol is greater than 12chatId.Send a message to chat chatId.Send a ticker symbol after '@priceKeyword', for example: priceKeyword BTClistings.Get top CoinMarketCap cryptocurrencies. Save it as listings.rows to listings.listings.data.Set rows to listings.listings.data.matched to false.Set matched to false.coinName to nothing.Set coinName to nothing.coinRank to nothing.Set coinRank to nothing.usdQuote to nothing.Set usdQuote to nothing.row in rows:For each row in rows:row.symbol is requestedSymbolIf row.symbol is requestedSymbolmatched to true.Change matched to true.coinName to row.name.Change coinName to row.name.coinRank to row.cmc_rank.Change coinRank to row.cmc_rank.usdQuote to row.quote.USD.Change usdQuote to row.quote.USD.matched is noIf matched is nochatId.Send a message to chat chatId.I could not find requestedSymbol in the top coinsSearched as text cryptocurrencies by market cap on CoinMarketCap. Check the ticker symbol and try again.requestedSymbol.Finish the run: No coin on CoinMarketCap matched requestedSymbol.replyLines to an empty list.Set replyLines to an empty list.heading to requestedSymbol.Set heading to requestedSymbol.coinName isn't emptyIf coinName isn't emptyheading to coinName (requestedSymbol).Change heading to coinName (requestedSymbol).heading to the end of replyLines and save it as replyLines.Add heading to the end of replyLines and save it as replyLines.priceLine to Price: not reported by CoinMarketCap.Set priceLine to Price: not reported by CoinMarketCap.priceRaw to usdQuote.price.Set priceRaw to usdQuote.price.priceRaw isn't emptyIf priceRaw isn't emptypriceErrorIf a step below fails, save the error as priceErrorpriceNumber to priceRaw multiplied by 1.Set priceNumber to priceRaw multiplied by 1.priceNumber is less than 1If priceNumber is less than 1priceLine to Price: priceNumber formatted as US dollars with 8 decimal places.Change priceLine to Price: priceNumber formatted as US dollars with 8 decimal places.priceLine to Price: priceNumber formatted as US dollars with 2 decimal places.Change priceLine to Price: priceNumber formatted as US dollars with 2 decimal places.The price came back in a form that is not a number, so it was left out..Show in the output: The price came back in a form that is not a number, so it was left out..priceLine to the end of replyLines and save it as replyLines.Add priceLine to the end of replyLines and save it as replyLines.hourChangeRaw to usdQuote.percent_change_1h.Set hourChangeRaw to usdQuote.percent_change_1h.hourChangeRaw isn't emptyIf hourChangeRaw isn't emptyhourChangeRawErrorIf a step below fails, save the error as hourChangeRawErrorhourChangeRaw multiplied by 1 formatted as a plain number with 2 decimal places% to the end of replyLines and save it as replyLines.Add 1h change: hourChangeRaw multiplied by 1 formatted as a plain number with 2 decimal places% to the end of replyLines and save it as replyLines.A percentage came back in a form that is not a number, so it was left out..Show in the output: A percentage came back in a form that is not a number, so it was left out..dayChangeRaw to usdQuote.percent_change_24h.Set dayChangeRaw to usdQuote.percent_change_24h.dayChangeRaw isn't emptyIf dayChangeRaw isn't emptydayChangeRawErrorIf a step below fails, save the error as dayChangeRawErrordayChangeRaw multiplied by 1 formatted as a plain number with 2 decimal places% to the end of replyLines and save it as replyLines.Add 24h change: dayChangeRaw multiplied by 1 formatted as a plain number with 2 decimal places% to the end of replyLines and save it as replyLines.A percentage came back in a form that is not a number, so it was left out..Show in the output: A percentage came back in a form that is not a number, so it was left out..marketCapRaw to usdQuote.market_cap.Set marketCapRaw to usdQuote.market_cap.marketCapRaw isn't emptyIf marketCapRaw isn't emptymarketCapRawErrorIf a step below fails, save the error as marketCapRawErrormarketCapRaw multiplied by 1 formatted as US dollars with 0 decimal places to the end of replyLines and save it as replyLines.Add Market cap: marketCapRaw multiplied by 1 formatted as US dollars with 0 decimal places to the end of replyLines and save it as replyLines.A market figure came back in a form that is not a number, so it was left out..Show in the output: A market figure came back in a form that is not a number, so it was left out..rankRaw to coinRank.Set rankRaw to coinRank.rankRaw isn't emptyIf rankRaw isn't emptyrankRawErrorIf a step below fails, save the error as rankRawErrorrankRaw multiplied by 1 formatted as a plain number with 0 decimal places to the end of replyLines and save it as replyLines.Add Market cap rank: #rankRaw multiplied by 1 formatted as a plain number with 0 decimal places to the end of replyLines and save it as replyLines.A market figure came back in a form that is not a number, so it was left out..Show in the output: A market figure came back in a form that is not a number, so it was left out..fearGreedErrorIf a step below fails, save the error as fearGreedErrorfearGreed.Get CoinMarketCap Fear and Greed Index. Save it as fearGreed.fearGreedData to fearGreed.fear_and_greed.data.Set fearGreedData to fearGreed.fear_and_greed.data.fearGreedValue to fearGreedData.value.Set fearGreedValue to fearGreedData.value.fearGreedLabel to fearGreedData.value_classification.Set fearGreedLabel to fearGreedData.value_classification.fearGreedValue isn't emptyIf fearGreedValue isn't emptyfearGreedLine to CoinMarketCap Fear and Greed Index: fearGreedValue multiplied by 1 formatted as a plain number with 0 decimal places.Set fearGreedLine to CoinMarketCap Fear and Greed Index: fearGreedValue multiplied by 1 formatted as a plain number with 0 decimal places.fearGreedLabel isn't emptyIf fearGreedLabel isn't emptyfearGreedLine to fearGreedLine (fearGreedLabel).Change fearGreedLine to fearGreedLine (fearGreedLabel).fearGreedLine to the end of replyLines and save it as replyLines.Add fearGreedLine to the end of replyLines and save it as replyLines.The Fear and Greed Index could not be read, so it was left out of the reply..Show in the output: The Fear and Greed Index could not be read, so it was left out of the reply..globalErrorIf a step below fails, save the error as globalErrorglobalMetrics.Get global market data. Save it as globalMetrics.globalData to globalMetrics.metrics.data.Set globalData to globalMetrics.metrics.data.dominanceRaw to globalData.btc_dominance.Set dominanceRaw to globalData.btc_dominance.dominanceRaw isn't emptyIf dominanceRaw isn't emptydominanceRawErrorIf a step below fails, save the error as dominanceRawErrordominanceRaw multiplied by 1 formatted as a plain number with 2 decimal places% to the end of replyLines and save it as replyLines.Add Bitcoin share of total market cap: dominanceRaw multiplied by 1 formatted as a plain number with 2 decimal places% to the end of replyLines and save it as replyLines.A market figure came back in a form that is not a number, so it was left out..Show in the output: A market figure came back in a form that is not a number, so it was left out..totalCapRaw to globalData.quote.USD.total_market_cap.Set totalCapRaw to globalData.quote.USD.total_market_cap.totalCapRaw isn't emptyIf totalCapRaw isn't emptytotalCapRawErrorIf a step below fails, save the error as totalCapRawErrortotalCapRaw multiplied by 1 formatted as US dollars with 0 decimal places to the end of replyLines and save it as replyLines.Add Total crypto market cap: totalCapRaw multiplied by 1 formatted as US dollars with 0 decimal places to the end of replyLines and save it as replyLines.A market figure came back in a form that is not a number, so it was left out..Show in the output: A market figure came back in a form that is not a number, so it was left out..Global market figures could not be read, so they were left out of the reply..Show in the output: Global market figures could not be read, so they were left out of the reply..Observed market data from CoinMarketCap. Not financial advice. to the end of replyLines and save it as replyLines.Add Observed market data from CoinMarketCap. Not financial advice. to the end of replyLines and save it as replyLines.chatId.Send a message to chat chatId.replyLines joined by a new line