Skip to content
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

Detailed export #98

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cb83e91
added option to export all events - WIP
Griffsano Dec 26, 2021
f1d68ce
export: added platform, minor format changes
Griffsano Dec 26, 2021
8aad810
address flake8 and mypy errors
Griffsano Dec 26, 2021
6d83bb6
address mypy errors
Griffsano Dec 26, 2021
d2f51f9
address flake8 error
Griffsano Dec 26, 2021
82d2705
renamed sell_price to sell_value to avoid confusion
Griffsano Dec 26, 2021
d8bfeca
remark for German tax calculation
Griffsano Dec 26, 2021
ec6b8ef
added option to include virtual sells in the export
Griffsano Dec 26, 2021
4912360
Merge branch 'main' into detailed-export
Griffsano Jan 16, 2022
f7adc22
moved config to ini
Griffsano Jan 16, 2022
821122f
address review comments
Griffsano Jan 16, 2022
7b6beb2
FIX linting errors
provinzio Feb 5, 2022
55ef433
CHANGE evaluate_sell to return list of TaxEvents
Griffsano Feb 20, 2022
6415130
FIX linting errors
Griffsano Feb 26, 2022
0bef72a
ADD newline in config.ini
provinzio Mar 19, 2022
cb0f5c6
FIX typo
provinzio Mar 19, 2022
5f5a276
REFACTOR code
provinzio Mar 19, 2022
9511d16
FIX Price relation in tax event remark
provinzio Mar 19, 2022
8bb18ed
Merge remote-tracking branch 'origin/main' into detailed-export
provinzio Mar 19, 2022
96b4c07
FIX linting error
provinzio Mar 19, 2022
d347127
FIX is_taxable value for multiple sold coins
provinzio Mar 19, 2022
c383bdc
ADD real_gain of airdrop
provinzio Mar 19, 2022
9d19ecb
ADD configparser country errors
Griffsano Mar 24, 2022
90f2179
ADD is_config_fiat function
Griffsano Mar 24, 2022
189367e
ADD class for config.FIAT
Griffsano Mar 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ CALCULATE_VIRTUAL_SELL = True
# taxable gains. Make sure, that this method is accepted by your tax
# authority.
MULTI_DEPOT = True
# Include virtual sells in the export
EXPORT_VIRTUAL_SELL = False
# Export all events (True) or only taxable events (False)
EXPORT_ALL_EVENTS = True
8 changes: 4 additions & 4 deletions src/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ def _read_bitpanda(self, file_path: Path) -> None:
elif operation in ["Buy", "Sell"]:
if asset_price_currency != config.FIAT:
log.error(
f"Only {config.FIAT.upper()} is supported as "
f"Only {config.FIAT} is supported as "
"'Asset market price currency', since price fetching for "
"fiat currencies is not fully implemented yet."
)
Expand All @@ -863,7 +863,7 @@ def _read_bitpanda(self, file_path: Path) -> None:
change_fiat = misc.force_decimal(amount_fiat)
# Save price in our local database for later.
price = misc.force_decimal(asset_price)
set_price_db(platform, asset, config.FIAT.upper(), utc_time, price)
set_price_db(platform, asset, config.FIAT, utc_time, price)

if change < 0:
log.error(
Expand All @@ -883,7 +883,7 @@ def _read_bitpanda(self, file_path: Path) -> None:
utc_time,
platform,
change_fiat,
config.FIAT.upper(),
config.FIAT,
row,
file_path,
)
Expand All @@ -893,7 +893,7 @@ def _read_bitpanda(self, file_path: Path) -> None:
utc_time,
platform,
change_fiat,
config.FIAT.upper(),
config.FIAT,
row,
file_path,
)
Expand Down
32 changes: 28 additions & 4 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,20 @@

config = configparser.ConfigParser()
config.read("config.ini")
COUNTRY = core.Country[config["BASE"].get("COUNTRY", "GERMANY")]

try:
COUNTRY = core.Country[config["BASE"].get("COUNTRY", "GERMANY")]
except KeyError as e:
raise NotImplementedError(
f"Your country {e} is currently not supported. " "Please create an Issue or PR."
)

TAX_YEAR = int(config["BASE"].get("TAX_YEAR", "2021"))
MEAN_MISSING_PRICES = config["BASE"].getboolean("MEAN_MISSING_PRICES")
CALCULATE_VIRTUAL_SELL = config["BASE"].getboolean("CALCULATE_VIRTUAL_SELL")
MULTI_DEPOT = config["BASE"].getboolean("MULTI_DEPOT")
EXPORT_VIRTUAL_SELL = config["BASE"].getboolean("EXPORT_VIRTUAL_SELL")
EXPORT_ALL_EVENTS = config["BASE"].getboolean("EXPORT_ALL_EVENTS")

# Read in environmental variables.
if _env_country := environ.get("COUNTRY"):
Expand All @@ -50,14 +59,29 @@
def IS_LONG_TERM(buy: datetime, sell: datetime) -> bool:
return buy + relativedelta(years=1) < sell


else:
raise NotImplementedError(f"Your country {COUNTRY} is not supported.")
raise NotImplementedError(
f"Your country {COUNTRY} is currently not supported. "
"Please create an Issue or PR."
)

# Program specific constants.
BASE_PATH = Path(__file__).parent.parent.absolute()
ACCOUNT_STATMENTS_PATH = Path(BASE_PATH, "account_statements")
DATA_PATH = Path(BASE_PATH, "data")
EXPORT_PATH = Path(BASE_PATH, "export")
TMP_LOG_FILEPATH = Path(EXPORT_PATH, "tmp.log")
FIAT = FIAT_CLASS.name # Convert to string.

# Class for simplified casefold string comparison with configured fiat currency
class Fiat(str):
def __init__(self, name):
self.name = name

def __eq__(self, fiat):
if isinstance(fiat, str):
return self.name.casefold() == fiat.casefold()
else:
raise TypeError(f"Unsupported operand for ==: {type(fiat)}")


FIAT = Fiat(FIAT_CLASS.name)
3 changes: 1 addition & 2 deletions src/log_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import logging
from logging import getLogger, shutdown
from pathlib import Path
from logging import getLogger, shutdown # noqa: F401

from config import TMP_LOG_FILEPATH

Expand Down
4 changes: 2 additions & 2 deletions src/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ def wrapper(*args, **kwargs):


def is_fiat(symbol: Union[str, core.Fiat]) -> bool:
"""Check if `symbol` is a fiat.
"""Check if `symbol` is a fiat currency.

Args:
fiat (str): Currency Symbol.

Returns:
bool: True if `symbol` is fiat. False otherwise.
bool: True if `symbol` is a fiat currency. False otherwise.
"""
return isinstance(symbol, core.Fiat) or symbol in core.Fiat.__members__

Expand Down
Loading