1
0
mirror of https://gitlab.com/simple-stock-bots/simple-stock-bot.git synced 2025-06-16 15:17:28 +00:00

cleanup and formatting

This commit is contained in:
Anson Biggs 2021-02-02 08:51:06 -07:00
parent 19655f02de
commit 72e912319f
2 changed files with 37 additions and 42 deletions

20
bot.py
View File

@ -4,20 +4,16 @@ import io
import logging import logging
import os import os
import random import random
import mplfinance as mpf
import mplfinance as mpf
import telegram import telegram
from telegram import ( from telegram import InlineQueryResultArticle, InputTextMessageContent, LabeledPrice
InlineQueryResultArticle,
InputTextMessageContent,
LabeledPrice,
)
from telegram.ext import ( from telegram.ext import (
CommandHandler, CommandHandler,
Filters, Filters,
InlineQueryHandler, InlineQueryHandler,
PreCheckoutQueryHandler,
MessageHandler, MessageHandler,
PreCheckoutQueryHandler,
Updater, Updater,
) )
@ -80,7 +76,7 @@ def donate(update, context):
return return
print(price) print(price)
prices = [LabeledPrice(f"Donation:", price)] prices = [LabeledPrice("Donation:", price)]
context.bot.send_invoice( context.bot.send_invoice(
chat_id, chat_id,
@ -110,7 +106,8 @@ def successful_payment_callback(update, context):
def symbol_detect(update, context): def symbol_detect(update, context):
""" """
Runs on any message that doesn't have a command and searches for symbols, then returns the prices of any symbols found. Runs on any message that doesn't have a command and searches for symbols,
then returns the prices of any symbols found.
""" """
message = update.message.text message = update.message.text
chat_id = update.message.chat_id chat_id = update.message.chat_id
@ -181,11 +178,6 @@ def info(update, context):
def search(update, context): def search(update, context):
message = update.message.text message = update.message.text
chat_id = update.message.chat_id
usage = """
To use this command
"""
queries = s.search_symbols(message)[:6] queries = s.search_symbols(message)[:6]
if queries: if queries:

View File

@ -1,7 +1,5 @@
import json
import os
import re import re
from datetime import datetime, timedelta from datetime import datetime
import pandas as pd import pandas as pd
import requests as r import requests as r
@ -45,22 +43,23 @@ Full documentation on using and running your own stock bot can be found [here.](
- /help Get some help using the bot. 🆘 - /help Get some help using the bot. 🆘
**Inline Features** **Inline Features**
You can type @SimpleStockBot `[search]` in any chat or direct message to search for the stock bots full list of stock symbols and return the price of the ticker. Then once you select the ticker you want the bot will send a message as you in that chat with the latest stock price. You can type @SimpleStockBot `[search]` in any chat or direct message to search for the stock bots
full list of stock symbols and return the price of the ticker. Then once you select the ticker
The bot also looks at every message in any chat it is in for stock symbols. Symbols start with a `$` followed by the stock symbol. For example: $tsla would return price information for Tesla Motors. want the bot will send a message as you in that chat with the latest stock price.
The bot also looks at every message in any chat it is in for stock symbols.Symbols start with a
`$` followed by the stock symbol. For example:$tsla would return price information for Tesla Motors.
Market data is provided by [IEX Cloud](https://iexcloud.io) Market data is provided by [IEX Cloud](https://iexcloud.io)
""" """
donate_text = """ donate_text = """
Simple Stock Bot is run entirely on donations[.](https://www.buymeacoffee.com/Anson) All donations go directly towards paying for servers, and market data is provided by [IEX Cloud](https://iexcloud.io/). Simple Stock Bot is run entirely on donations[.](https://www.buymeacoffee.com/Anson)
All donations go directly towards paying for servers, and market data is provided by
[IEX Cloud](https://iexcloud.io/).
The easiest way to donate is to run the `/donate [amount in USD]` command with USdollars you would like to donate. The easiest way to donate is to run the `/donate [amount in USD]` command with USdollars you would like to donate.
Example: `/donate 2` would donate 2 USD. Example: `/donate 2` would donate 2 USD.
An alternative way to donate is through https://www.buymeacoffee.com/Anson,which accepts Paypal or Credit card. An alternative way to donate is through https://www.buymeacoffee.com/Anson,which accepts Paypal or Credit card.
If you have any questions get in touch: @MisterBiggs or[anson@ansonbiggs.com](http://mailto:anson@ansonbiggs.com/) If you have any questions get in touch: @MisterBiggs or[anson@ansonbiggs.com](http://mailto:anson@ansonbiggs.com/)
_Donations can only be made in a chat directly with @simplestockbot_ _Donations can only be made in a chat directly with @simplestockbot_
@ -83,7 +82,9 @@ _Donations can only be made in a chat directly with @simplestockbot_
Returns: Returns:
pd.DataFrame -- [DataFrame with columns: Symbol | Issue_Name | Primary_Listing_Mkt pd.DataFrame -- [DataFrame with columns: Symbol | Issue_Name | Primary_Listing_Mkt
datetime -- The time when the list of symbols was fetched. The Symbol list is updated every open and close of every trading day. datetime -- The time when the list of symbols was fetched.
The Symbol list is updated every open and close of every trading day.
""" """
raw_symbols = r.get( raw_symbols = r.get(
f"https://cloud.iexapis.com/stable/ref-data/symbols?token={self.IEX_TOKEN}" f"https://cloud.iexapis.com/stable/ref-data/symbols?token={self.IEX_TOKEN}"
@ -100,10 +101,12 @@ _Donations can only be made in a chat directly with @simplestockbot_
Performs a fuzzy search to find stock symbols closest to a search term. Performs a fuzzy search to find stock symbols closest to a search term.
Arguments: Arguments:
search {str} -- String used to search, could be a company name or something close to the companies stock ticker. search {str} -- String used to search, could be a company name or something close
to the companies stock ticker.
Returns: Returns:
List of Tuples -- A list tuples of every stock sorted in order of how well they match. Each tuple contains: (Symbol, Issue Name). List of Tuples -- A list tuples of every stock sorted in order of how well they match.
Each tuple contains: (Symbol, Issue Name).
""" """
schedule.run_pending() schedule.run_pending()
search = search.lower() search = search.lower()
@ -133,7 +136,8 @@ _Donations can only be made in a chat directly with @simplestockbot_
def find_symbols(self, text: str): def find_symbols(self, text: str):
""" """
Finds stock tickers starting with a dollar sign in a blob of text and returns them in a list. Only returns each match once. Example: Whats the price of $tsla? -> ['tsla'] Finds stock tickers starting with a dollar sign in a blob of text and returns them in a list.
Only returns each match once. Example: Whats the price of $tsla? -> ['tsla']
Arguments: Arguments:
text {str} -- Blob of text that might contain tickers with the format: $TICKER text {str} -- Blob of text that might contain tickers with the format: $TICKER
@ -146,13 +150,16 @@ _Donations can only be made in a chat directly with @simplestockbot_
def price_reply(self, symbols: list): def price_reply(self, symbols: list):
""" """
Takes a list of symbols and replies with Markdown formatted text about the symbols price change for the day. Takes a list of symbols and replies with Markdown formatted text about the symbols
price change for the day.
Arguments: Arguments:
symbols {list} -- List of stock market symbols. symbols {list} -- List of stock market symbols.
Returns: Returns:
dict -- Dictionary with keys of symbols and values of markdown formatted text example: {'tsla': 'The current stock price of Tesla Motors is $**420$$, the stock price is currently **up 42%**} dict -- Dictionary with keys of symbols and values of markdown formatted
text example: {'tsla': 'The current stock price of Tesla Motors is
$**420$$, the stock price is currently **up 42%**}
""" """
dataMessages = {} dataMessages = {}
for symbol in symbols: for symbol in symbols:
@ -356,7 +363,3 @@ _Donations can only be made in a chat directly with @simplestockbot_
else: else:
return False return False
# s = Symbol("")
# print(s.donate_text)