-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] [Stock Market] Add New Cog #554
base: V3/testing
Are you sure you want to change the base?
Conversation
Integrates the Real life stock market into Ren! Thought adding new ways to gain/lose credits might be fun. Also, has the added benefit of teaching people how to invest and gaining experience losing money. Unlike Squid.py, effort was put in. Oh, and comments... yea kinda forgot about those midway so, you got this! Its fairly simple code so should be alright without it. Couple of issues are still present in no particular order: - Its slow, that needs to be worked on, especially for the buy and sell functions - The output could be prettier. - Buy & Sell functions are kinda messy. Needs to be cleaned up. - For the charts, the time stamps are weird if you view a stock when its currently being traded on the market WIP/To-Do: - Dividends (think of it as adult allowance for the financial illiterate) - buy/sell with the full company name instead of tickers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move casino changes into a new PR. It is a separate cog change and should be reviewed separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did one quick scan. Please consider breaking your command coroutine definitions into smaller pieces, since they are hard to follow.
Added Type hints
Revert "Added Type hints"
[AfterHours] Added Type Hints
New File(s): - Created utils.py that contains abstracted functions for market.py Changes to constants.py - Constants class removed and all single quotes changed to double quotes - Added a constant for the maximum message length and the price multiplier - Removed some quips and adjusted punctuation Changes to market.py: - Cognitive complexity is lower - most functions are now abstracted away and moved into utils.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a second pass, please see below.
cogs/stockmarket/constants.py
Outdated
DATA_FILE = "cogs\\stockmarket\\portfolios.json" | ||
EMBED_LOCATION = "cogs\\stockmarket\\chart.jpg" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please make these paths platform-agnostic? This would work on Windows but not Linux.
cogs/stockmarket/constants.py
Outdated
INVALID_TICKER_STR = "Invalid ticker symbol!" | ||
INVALID_AMOUNT_STR = "Invalid amount!" | ||
POOR_STR = "You do not have enough money to buy this stock!" | ||
ACCOUNT_NOT_FOUND_STR = """No account found! Please create an account using `renmarket createacc`.""" # .format(get prefix somehow) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: No need for """
.
import time | ||
import datetime | ||
import matplotlib.pyplot as plt | ||
import yfinance as yf # pip install yfinance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include a info.json
and put this as a requirements. You can see other cogs (i.e. YOURLS) for examples.
cogs/stockmarket/market.py
Outdated
@market.command(name="debug") | ||
async def market_debug(self, ctx: commands.Context): | ||
"""Debugging command""" | ||
# print out all the data | ||
all_member_data = await self.config.all_members(guild=None) | ||
print(all_member_data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be protected by some mod/admin equivalent check.
cogs/stockmarket/market.py
Outdated
embed_file = discord.File(EMBED_LOCATION, filename=ticker + ".jpg") | ||
embed.set_image(url="attachment:https://image.jpg") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work if the filename doesn't match the one you're setting with set_image
?
cogs/stockmarket/market.py
Outdated
from .constants import * | ||
from .utils import * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably some other places are using import *
, but can we please explicitly import all attributes that you need? Makes tracing where names are coming from easier.
cogs/stockmarket/market.py
Outdated
self, | ||
ctx: commands.Context, | ||
ticker: str, | ||
amount_to_sell: int = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to include default of 0 and let the infra print out the help string if the amount to sell isn't provided?
cogs/stockmarket/market.py
Outdated
user_id: discord.Member = None, | ||
): | ||
"""Sell a user-specified amount of a stock""" | ||
ticker = ticker.upper() | ||
|
||
if user_id is None: | ||
user_id = ctx.author |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re:user_id
, can we rename this to something that doesn't include ID, since this is not a user ID but rather the Member object itself.
cogs/stockmarket/market.py
Outdated
if user_id is None: | ||
user_id = ctx.author |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as previous sentiment.
cogs/stockmarket/utils.py
Outdated
# so messy... | ||
async def build_embed(self, ctx: commands.Context, price: int, ticker: str, ticker_info: dict): | ||
"""Builds the embed""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: does this need to be inside the class? I don't see self
being used anywhere in this helper.
Messed up my local git repo so it doesn't contain the 30 or so changes. Still kinda figuring this stuff out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please remove the files at the root of the repo in your PR?
…s-at-root Removing accidentally placed files at root
Description of the changes
Also balanced all the casino games so that the expected value is roughly all the same.