|
17 | 17 | ) |
18 | 18 | from ws_api.session import WSAPISession |
19 | 19 |
|
| 20 | +# Mapping of account types to human-readable descriptions |
| 21 | +_ACCOUNT_TYPE_DESCRIPTIONS = { |
| 22 | + "SELF_DIRECTED_RRSP": "RRSP: self-directed", |
| 23 | + "MANAGED_RRSP": "RRSP: managed", |
| 24 | + "SELF_DIRECTED_SPOUSAL_RRSP": "RRSP: self-directed spousal", |
| 25 | + "SELF_DIRECTED_TFSA": "TFSA: self-directed", |
| 26 | + "MANAGED_TFSA": "TFSA: managed", |
| 27 | + "SELF_DIRECTED_FHSA": "FHSA: self-directed", |
| 28 | + "MANAGED_FHSA": "FHSA: managed", |
| 29 | + "SELF_DIRECTED_NON_REGISTERED": "Non-registered: self-directed", |
| 30 | + "SELF_DIRECTED_JOINT_NON_REGISTERED": "Non-registered: self-directed - joint", |
| 31 | + "SELF_DIRECTED_NON_REGISTERED_MARGIN": "Non-registered: self-directed margin", |
| 32 | + "MANAGED_JOINT": "Non-registered: managed - joint", |
| 33 | + "SELF_DIRECTED_CRYPTO": "Crypto", |
| 34 | + "SELF_DIRECTED_RRIF": "RRIF: self-directed", |
| 35 | + "SELF_DIRECTED_SPOUSAL_RRIF": "RRIF: self-directed spousal", |
| 36 | + "CREDIT_CARD": "Credit card", |
| 37 | + "SELF_DIRECTED_LIRA": "LIRA: self-directed", |
| 38 | +} |
| 39 | + |
20 | 40 |
|
21 | 41 | class WealthsimpleAPIBase: |
22 | 42 | OAUTH_BASE_URL = "https://api.production.wealthsimple.com/v1/oauth/v2" |
@@ -442,64 +462,36 @@ def _account_add_description(account): |
442 | 462 | account["number"] = account["id"] |
443 | 463 | # This is the account number visible in the WS app: |
444 | 464 | for ca in account["custodianAccounts"]: |
445 | | - if (ca["branch"] in ["WS", "TR"]) and ca["status"] == "open": |
| 465 | + if ca["branch"] in ("WS", "TR") and ca["status"] == "open": |
446 | 466 | account["number"] = ca["id"] |
447 | 467 |
|
448 | | - # Default |
449 | | - account["description"] = account["unifiedAccountType"] |
450 | | - |
451 | 468 | if account.get("nickname"): |
452 | 469 | account["description"] = account["nickname"] |
453 | | - elif account["unifiedAccountType"] == "CASH": |
| 470 | + return |
| 471 | + |
| 472 | + account_type = account["unifiedAccountType"] |
| 473 | + |
| 474 | + # Special case: CASH depends on owner configuration |
| 475 | + if account_type == "CASH": |
454 | 476 | account["description"] = ( |
455 | 477 | "Cash: joint" |
456 | 478 | if account["accountOwnerConfiguration"] == "MULTI_OWNER" |
457 | 479 | else "Cash" |
458 | 480 | ) |
459 | | - elif account["unifiedAccountType"] == "SELF_DIRECTED_RRSP": |
460 | | - account["description"] = "RRSP: self-directed" |
461 | | - elif account["unifiedAccountType"] == "MANAGED_RRSP": |
462 | | - account["description"] = "RRSP: managed" |
463 | | - elif account["unifiedAccountType"] == "SELF_DIRECTED_SPOUSAL_RRSP": |
464 | | - account["description"] = "RRSP: self-directed spousal" |
465 | | - elif account["unifiedAccountType"] == "SELF_DIRECTED_TFSA": |
466 | | - account["description"] = "TFSA: self-directed" |
467 | | - elif account["unifiedAccountType"] == "MANAGED_TFSA": |
468 | | - account["description"] = "TFSA: managed" |
469 | | - elif account["unifiedAccountType"] == "SELF_DIRECTED_FHSA": |
470 | | - account["description"] = f"FHSA: self-directed" |
471 | | - elif account["unifiedAccountType"] == "MANAGED_FHSA": |
472 | | - account["description"] = f"FHSA: managed" |
473 | | - elif account["unifiedAccountType"] == "SELF_DIRECTED_NON_REGISTERED": |
474 | | - account["description"] = "Non-registered: self-directed" |
475 | | - elif account["unifiedAccountType"] == "SELF_DIRECTED_JOINT_NON_REGISTERED": |
476 | | - account["description"] = "Non-registered: self-directed - joint" |
477 | | - elif account["unifiedAccountType"] == "SELF_DIRECTED_NON_REGISTERED_MARGIN": |
478 | | - account["description"] = "Non-registered: self-directed margin" |
479 | | - elif account["unifiedAccountType"] == "MANAGED_JOINT": |
480 | | - account["description"] = "Non-registered: managed - joint" |
481 | | - elif account["unifiedAccountType"] == "SELF_DIRECTED_CRYPTO": |
482 | | - account["description"] = "Crypto" |
483 | | - elif account["unifiedAccountType"] == "SELF_DIRECTED_RRIF": |
484 | | - account["description"] = "RRIF: self-directed" |
485 | | - elif account["unifiedAccountType"] == "SELF_DIRECTED_SPOUSAL_RRIF": |
486 | | - account["description"] = "RRIF: self-directed spousal" |
487 | | - elif account["unifiedAccountType"] == "CREDIT_CARD": |
488 | | - account["description"] = "Credit card" |
489 | | - elif account["unifiedAccountType"] == "MANAGED_NON_REGISTERED": |
490 | | - if any( |
491 | | - feature["name"] == "PRIVATE_CREDIT" |
492 | | - for feature in account["accountFeatures"] |
493 | | - ): |
| 481 | + # Special case: MANAGED_NON_REGISTERED depends on features |
| 482 | + elif account_type == "MANAGED_NON_REGISTERED": |
| 483 | + features = {f["name"] for f in account["accountFeatures"]} |
| 484 | + if "PRIVATE_CREDIT" in features: |
494 | 485 | account["description"] = "Non-registered: managed - private credit" |
495 | | - if any( |
496 | | - feature["name"] == "PRIVATE_EQUITY" |
497 | | - for feature in account["accountFeatures"] |
498 | | - ): |
| 486 | + elif "PRIVATE_EQUITY" in features: |
499 | 487 | account["description"] = "Non-registered: managed - private equity" |
500 | | - elif account["unifiedAccountType"] == "SELF_DIRECTED_LIRA": |
501 | | - account["description"] = "LIRA: self-directed" |
502 | | - # TODO: Add other types as needed |
| 488 | + else: |
| 489 | + account["description"] = account_type |
| 490 | + # Simple lookup for all other types |
| 491 | + else: |
| 492 | + account["description"] = _ACCOUNT_TYPE_DESCRIPTIONS.get( |
| 493 | + account_type, account_type |
| 494 | + ) |
503 | 495 |
|
504 | 496 | def get_account_balances(self, account_id): |
505 | 497 | accounts = self.do_graphql_query( |
|
0 commit comments