Skip to content

Instantly share code, notes, and snippets.

@nsa-yoda
Created May 6, 2021 22:21
Show Gist options
  • Save nsa-yoda/6296ab7dedb13454c212d47edbd301de to your computer and use it in GitHub Desktop.
Save nsa-yoda/6296ab7dedb13454c212d47edbd301de to your computer and use it in GitHub Desktop.
import locale
from dataclasses import dataclass
@dataclass
class ProfitCalculator():
label: str
buy: float
sell: float
usd_amount: float
profit: float = 0.00
def calculate_profit(self, just_gross: bool=False) -> float:
gross_profit: float = self.sell * (self.usd_amount / self.buy)
net_profit: float = gross_profit - self.usd_amount
self.profit = gross_profit if just_gross else net_profit
return self.profit
def print(self) -> None:
locale.setlocale(locale.LC_ALL, '')
formatted = locale.currency(self.profit, grouping=True)
print(f"{self.label} <> {formatted}")
# Bonfire
bonfire = ProfitCalculator("Bonfire", 0.000000125458, 0.01, 250)
bonfire.calculate_profit()
bonfire.print()
# Happy
happy = ProfitCalculator("Happy", 0.0000000254551, 0.01, 250)
happy.calculate_profit()
happy.print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment