Skip to content

Commit

Permalink
Typing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveitaly committed Aug 16, 2022
1 parent 254bcdd commit b766b6b
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/dali/plugin/input/csv/binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import logging
from csv import reader
from decimal import Decimal
from typing import List, Optional
from typing import List, Optional, Dict

from rp2.logger import create_logger

Expand Down Expand Up @@ -117,15 +117,15 @@ def load(self) -> List[AbstractTransaction]:
# it is unclear what 'Distribution > Other' represents, but it looks like some type of income
if transaction_type in [_REFERRAL_COMMISSION, _STAKING_REWARDS] or (category == "Distribution" and transaction_type == _OTHERS):
granular_transaction_type = Keyword.INCOME if transaction_type == _REFERRAL_COMMISSION else Keyword.INTEREST
currency: str = line[self.__PRIMARY_ASSET_INDEX].strip()
currency = line[self.__PRIMARY_ASSET_INDEX].strip()

crypto_amount = line[self.__PRIMARY_ASSET_AMOUNT_INDEX].strip()
calculated_spot_price = Decimal(line[self.__PRIMARY_ASSET_SPOT_PRICE_INDEX].strip()) / Decimal(crypto_amount)

result.append(
InTransaction(
**(
common_params
common_params # type: ignore
| {
"asset": currency,
"exchange": self.__BINANCE,
Expand All @@ -139,14 +139,14 @@ def load(self) -> List[AbstractTransaction]:
)
)
elif transaction_type == _CRYPTO_DEPOSIT:
currency: str = line[self.__PRIMARY_ASSET_INDEX].strip()
currency = line[self.__PRIMARY_ASSET_INDEX].strip()
crypto_amount = line[self.__PRIMARY_ASSET_AMOUNT_INDEX].strip()
calculated_spot_price = Decimal(line[self.__PRIMARY_ASSET_SPOT_PRICE_INDEX].strip()) / Decimal(crypto_amount)

result.append(
IntraTransaction(
**(
common_params
common_params # type: ignore
| {
"asset": currency,
"crypto_sent": "0",
Expand All @@ -163,14 +163,14 @@ def load(self) -> List[AbstractTransaction]:
)
)
elif transaction_type == _CRYPTO_WITHDRAWAL:
currency: str = line[self.__PRIMARY_ASSET_INDEX].strip()
currency = line[self.__PRIMARY_ASSET_INDEX].strip()
crypto_amount = line[self.__PRIMARY_ASSET_AMOUNT_INDEX].strip()
calculated_spot_price = Decimal(line[self.__PRIMARY_ASSET_SPOT_PRICE_INDEX].strip()) / Decimal(crypto_amount)

result.append(
IntraTransaction(
**(
common_params
common_params # type: ignore
| {
"crypto_received": "0",
# withdrawals happen in the primary asset field
Expand All @@ -191,7 +191,7 @@ def load(self) -> List[AbstractTransaction]:
result.append(
OutTransaction(
**(
common_params
common_params # type: ignore
| {
"notes": f"Fee for {category} - {transaction_type}",
}
Expand All @@ -205,18 +205,18 @@ def load(self) -> List[AbstractTransaction]:
# 52358478,2021-08-04 16:15:55.614,Quick Buy,Buy,{32 char txn id},{9 char id},,,,USD,30.00000000,30.00000000,BUSD,29.84000000,29.84542100,USD,0.15000000,0.15000000,ACH,, # pylint: disable=line-too-long

if category == "Quick Buy":
purchased_asset: str = line[self.__QUOTE_ASSET_INDEX].strip()
purchased_asset = line[self.__QUOTE_ASSET_INDEX].strip()
crypto_amount = line[self.__QUOTE_ASSET_AMOUNT_INDEX].strip()
calculated_spot_price = Decimal(line[self.__QUOTE_ASSET_AMOUNT_SPOT_PRICE_INDEX].strip()) / Decimal(crypto_amount)
else:
purchased_asset: str = line[self.__BASE_ASSET_INDEX].strip()
purchased_asset = line[self.__BASE_ASSET_INDEX].strip()
crypto_amount = line[self.__BASE_ASSET_AMOUNT_INDEX].strip()
calculated_spot_price = Decimal(line[self.__BASE_ASSET_AMOUNT_SPOT_PRICE_INDEX].strip()) / Decimal(crypto_amount)

result.append(
InTransaction(
**(
common_params
common_params # type: ignore
| {
"exchange": self.__BINANCE,
"holder": self.account_holder,
Expand All @@ -241,7 +241,7 @@ def load(self) -> List[AbstractTransaction]:
result.append(
OutTransaction(
**(
common_params
common_params # type: ignore
| {
"exchange": self.__BINANCE,
"holder": self.account_holder,
Expand All @@ -260,7 +260,7 @@ def load(self) -> List[AbstractTransaction]:
result.append(
OutTransaction(
**(
common_params
common_params # type: ignore
| {
"notes": f"Fee for {category} - {transaction_type}",
}
Expand All @@ -275,7 +275,7 @@ def load(self) -> List[AbstractTransaction]:
result.append(
OutTransaction(
**(
common_params
common_params # type: ignore
| {
"exchange": self.__BINANCE,
"holder": self.account_holder,
Expand All @@ -295,7 +295,7 @@ def load(self) -> List[AbstractTransaction]:
result.append(
InTransaction(
**(
common_params
common_params # type: ignore
| {
"exchange": self.__BINANCE,
"holder": self.account_holder,
Expand All @@ -313,7 +313,7 @@ def load(self) -> List[AbstractTransaction]:
result.append(
OutTransaction(
**(
common_params
common_params # type: ignore
| {
"notes": f"Fee for {category} - {transaction_type}",
}
Expand All @@ -330,7 +330,7 @@ def load(self) -> List[AbstractTransaction]:

return result

def generate_fee_parameters(self, line):
def generate_fee_parameters(self, line: list[str]) -> Dict[str, str]:
fee_amount = Decimal(line[self.__FEE_ASSET_AMOUNT_INDEX].strip())

if fee_amount.is_zero():
Expand Down

0 comments on commit b766b6b

Please sign in to comment.