This commit is contained in:
parent
59b196348a
commit
5cc88e1d02
|
@ -41,16 +41,22 @@ class KrakenDepoFetcher(DepoFetcher):
|
||||||
result = self.client.query_private('Balance')
|
result = self.client.query_private('Balance')
|
||||||
|
|
||||||
assets: dict[fin_defs.Asset, Decimal] = {}
|
assets: dict[fin_defs.Asset, Decimal] = {}
|
||||||
for account_raw, balance_str in result['result'].items():
|
for ticker, balance_str in result['result'].items():
|
||||||
account = account_raw.removesuffix('.HOLD')
|
asset = parse_asset_from_ticker(ticker)
|
||||||
asset = fin_defs.WELL_KNOWN_SYMBOLS[account]
|
|
||||||
balance = Decimal(balance_str)
|
balance = Decimal(balance_str)
|
||||||
if balance != 0:
|
if balance != 0:
|
||||||
assets[asset] = assets.get(asset, Decimal(0)) + balance
|
assets[asset] = assets.get(asset, Decimal(0)) + balance
|
||||||
del account, account_raw, balance_str, asset, balance
|
del ticker, balance_str, asset, balance
|
||||||
|
|
||||||
return DepoSingle(
|
return DepoSingle(
|
||||||
name='Kraken',
|
name='Kraken',
|
||||||
_assets=assets,
|
_assets=assets,
|
||||||
updated_time=now,
|
updated_time=now,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def parse_asset_from_ticker(ticker: str) -> fin_defs.Asset:
|
||||||
|
account = ticker.removesuffix('.HOLD')
|
||||||
|
if account == 'ZEUR':
|
||||||
|
return fin_defs.EUR
|
||||||
|
asset = fin_defs.WELL_KNOWN_SYMBOLS[account]
|
||||||
|
|
|
@ -12,6 +12,11 @@ from .data import DepoFetcher, DepoGroup, DepoSingle, TradeOrderDetails
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
def parse_asset_from_ticker(ticker: str) -> fin_defs.Asset:
|
||||||
|
if ticker == 'KCS':
|
||||||
|
return fin_defs.CryptoCurrency('KCS', coingecko_id='kucoin-shares')
|
||||||
|
return fin_defs.WELL_KNOWN_SYMBOLS[ticker]
|
||||||
|
|
||||||
|
|
||||||
class KucoinDepoFetcher(DepoFetcher):
|
class KucoinDepoFetcher(DepoFetcher):
|
||||||
"""`Depo` fetcher for [Kucoin](https://www.kucoin.com), the online crypto currency exchange.
|
"""`Depo` fetcher for [Kucoin](https://www.kucoin.com), the online crypto currency exchange.
|
||||||
|
@ -56,7 +61,7 @@ class KucoinDepoFetcher(DepoFetcher):
|
||||||
assets_by_account_type: dict[str, dict[fin_defs.Asset, Decimal]] = {}
|
assets_by_account_type: dict[str, dict[fin_defs.Asset, Decimal]] = {}
|
||||||
|
|
||||||
for account_data in self.kucoin_client.get_accounts():
|
for account_data in self.kucoin_client.get_accounts():
|
||||||
asset = fin_defs.WELL_KNOWN_SYMBOLS[account_data['currency']]
|
asset = parse_asset_from_ticker(account_data['currency'])
|
||||||
balance = Decimal(account_data['balance'])
|
balance = Decimal(account_data['balance'])
|
||||||
assets_for_account_type = assets_by_account_type.setdefault(
|
assets_for_account_type = assets_by_account_type.setdefault(
|
||||||
account_data['type'],
|
account_data['type'],
|
||||||
|
@ -164,7 +169,7 @@ class KucoinDepoFetcher(DepoFetcher):
|
||||||
input_amount=input_amount_final,
|
input_amount=input_amount_final,
|
||||||
output_asset=output_asset,
|
output_asset=output_asset,
|
||||||
output_amount=output_amount_final,
|
output_amount=output_amount_final,
|
||||||
fee_asset=fin_defs.WELL_KNOWN_SYMBOLS[order_details['feeCurrency']],
|
fee_asset=parse_asset_from_ticker(order_details['feeCurrency']),
|
||||||
fee_amount=Decimal(order_details['fee']),
|
fee_amount=Decimal(order_details['fee']),
|
||||||
executed_time=datetime.datetime.fromtimestamp(
|
executed_time=datetime.datetime.fromtimestamp(
|
||||||
order_details['createdAt'] / 1000,
|
order_details['createdAt'] / 1000,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user