Compare commits
No commits in common. "5b188cf1aa560af71a4af5c76bb51db6182ddb6f" and "1870de8109b31087ea9ee14e1b9f87d4c57c1ed8" have entirely different histories.
5b188cf1aa
...
1870de8109
|
@ -148,9 +148,7 @@ class PartisiaBlockchainAccountDepoFetcher:
|
||||||
balances = self.client.get_account_balances(self.blockchain_address)
|
balances = self.client.get_account_balances(self.blockchain_address)
|
||||||
|
|
||||||
depo_mpc = DepoSingle(
|
depo_mpc = DepoSingle(
|
||||||
'Native',
|
'Native', balances.update_time, {fin_defs.MPC: balances.mpc}
|
||||||
balances.update_time,
|
|
||||||
{fin_defs.MPC: balances.mpc},
|
|
||||||
)
|
)
|
||||||
depo_byoc = DepoSingle(
|
depo_byoc = DepoSingle(
|
||||||
'BYOC',
|
'BYOC',
|
||||||
|
|
|
@ -15,7 +15,7 @@ from decimal import Decimal
|
||||||
|
|
||||||
import fin_defs
|
import fin_defs
|
||||||
|
|
||||||
from .data import Depo, DepoGroup, DepoSingle
|
from .data import Depo, DepoSingle, DepoGroup
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -38,7 +38,6 @@ def asset_from_instrument_json(json) -> fin_defs.Asset | None:
|
||||||
exchange_id = json['tradables'][0]['mic']
|
exchange_id = json['tradables'][0]['mic']
|
||||||
return fin_defs.Stock(symbol, fin_defs.EXCHANGES_BY_IDS[exchange_id])
|
return fin_defs.Stock(symbol, fin_defs.EXCHANGES_BY_IDS[exchange_id])
|
||||||
|
|
||||||
|
|
||||||
class NordnetDepoFetcher:
|
class NordnetDepoFetcher:
|
||||||
def __init__(self, session, username: str, password: str):
|
def __init__(self, session, username: str, password: str):
|
||||||
assert session is not None, 'missing session'
|
assert session is not None, 'missing session'
|
||||||
|
@ -85,9 +84,7 @@ class NordnetDepoFetcher:
|
||||||
|
|
||||||
def get_depo(self) -> Depo:
|
def get_depo(self) -> Depo:
|
||||||
self.login()
|
self.login()
|
||||||
now = datetime.datetime.now(
|
now = datetime.datetime.now(tz=datetime.UTC) # TODO: Use info from json requests
|
||||||
tz=datetime.UTC,
|
|
||||||
) # TODO: Use info from json requests
|
|
||||||
|
|
||||||
json_accounts = self.get_json(API_ACCOUNTS)
|
json_accounts = self.get_json(API_ACCOUNTS)
|
||||||
|
|
||||||
|
@ -95,39 +92,31 @@ class NordnetDepoFetcher:
|
||||||
for json_account in json_accounts:
|
for json_account in json_accounts:
|
||||||
account_id = json_account['accid']
|
account_id = json_account['accid']
|
||||||
|
|
||||||
assets: dict[fin_defs.Asset, Decimal] = {}
|
assets: dict[fin_defs.Asset, Decimal] = {
|
||||||
|
}
|
||||||
|
|
||||||
# Determine amount of usable currency stored on Nordnet
|
# Determine amount of usable currency stored on Nordnet
|
||||||
if True:
|
if True:
|
||||||
json_account_info = self.get_json(
|
json_account_info = self.get_json(API_ACCOUNT_INFO.format(accid = account_id))
|
||||||
API_ACCOUNT_INFO.format(accid=account_id),
|
asset = fin_defs.FiatCurrency(json_account_info[0]['account_sum']['currency'])
|
||||||
)
|
|
||||||
asset = fin_defs.FiatCurrency(
|
|
||||||
json_account_info[0]['account_sum']['currency'],
|
|
||||||
)
|
|
||||||
amount = Decimal(json_account_info[0]['account_sum']['value'])
|
amount = Decimal(json_account_info[0]['account_sum']['value'])
|
||||||
assets[asset] = amount
|
assets[asset] = amount
|
||||||
del asset, amount
|
del asset, amount
|
||||||
|
|
||||||
# Determine positions on Nordnet
|
# Determine positions on Nordnet
|
||||||
json_account_positions = self.get_json(
|
json_account_positions = self.get_json(API_ACCOUNT_POSITIONS.format(accid = account_id))
|
||||||
API_ACCOUNT_POSITIONS.format(accid=account_id),
|
|
||||||
)
|
|
||||||
for pos in json_account_positions:
|
for pos in json_account_positions:
|
||||||
asset = asset_from_instrument_json(pos['instrument'])
|
asset = asset_from_instrument_json(pos['instrument'])
|
||||||
if asset is None:
|
if asset is None: continue
|
||||||
continue
|
|
||||||
amount = Decimal(pos['qty'])
|
amount = Decimal(pos['qty'])
|
||||||
assets[asset] = amount
|
assets[asset] = amount
|
||||||
del asset, amount
|
del asset, amount
|
||||||
|
|
||||||
nested.append(
|
nested.append(DepoSingle(
|
||||||
DepoSingle(
|
name='{} {}'.format(json_account['type'], json_account['alias']),
|
||||||
name='{} {}'.format(json_account['type'], json_account['alias']),
|
_assets=assets,
|
||||||
_assets=assets,
|
updated_time=now,
|
||||||
updated_time=now,
|
))
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
return DepoGroup(
|
return DepoGroup(
|
||||||
name=f'Nordnet',
|
name=f'Nordnet',
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
import requests
|
|
||||||
|
|
||||||
from fin_depo import investbank_nordnet
|
|
||||||
|
|
||||||
SECRET_USERNAME = None
|
|
||||||
SECRET_PASSWORD = None
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_depo():
|
|
||||||
session = requests.Session()
|
|
||||||
nordnet = investbank_nordnet.NordnetDepoFetcher(
|
|
||||||
session,
|
|
||||||
SECRET_USERNAME,
|
|
||||||
SECRET_PASSWORD,
|
|
||||||
)
|
|
||||||
|
|
||||||
depo = nordnet.get_depo()
|
|
||||||
assert depo is not None
|
|
Loading…
Reference in New Issue
Block a user