Skip to main content

Official Wealthica Python SDK for the Investment Data API

Project description

Wealthica Investment API Python SDK

Official Python SDK for the Wealthica Investment API.

What is Wealthica?

Wealthica is an API for connecting with Canadian financial institutions and brokerages platforms. Instead of manually integrating with multiple institution APIs - you can simply use Wealthica for them all.

For our updated list of integrations, check out our list of Wealthica Integrations.

Features

  • Secure JWT-based token authentication with automatic refresh
  • Investment positions with security details
  • Transaction history across all connected institutions
  • Balance history tracking over time
  • Support for 150+ Canadian financial institutions
  • Context manager support for automatic cleanup
  • Typed exception classes for granular error handling

Installation

pip install wealthica

Configuration

Set your credentials as environment variables:

export WEALTHICA_CLIENT_ID="your_client_id"
export WEALTHICA_CLIENT_SECRET="your_secret"

To obtain API keys, reach out to the team at sales@wealthica.com.

Quick Start

from wealthica import Wealthica

# Initialize the client with your API credentials
wealthica = Wealthica(
    client_id="your_client_id",
    secret="your_secret"
)

# Get list of supported providers (no user login required)
providers = wealthica.providers.get_list()
print(f"Wealthica supports {len(providers)} providers")

# Get team information
team = wealthica.get_team()
print(f"Team: {team['name']}")

User Authentication

To access user-specific data like institutions, positions, and transactions, you need to login as a user:

from wealthica import Wealthica

wealthica = Wealthica(
    client_id="your_client_id",
    secret="your_secret"
)

# Login as a specific user (use your internal user ID)
user = wealthica.login("user_123")

# Now you can access user-specific resources
institutions = user.institutions.get_list()
for inst in institutions:
    print(f"Institution: {inst['provider']['display_name']}")
    for balance in inst.get('balances', []):
        print(f"  {balance['ticker']}: {balance['amount']}")

API Reference

Provider APIs

These APIs don't require user authentication:

Get All Providers

providers = wealthica.providers.get_list()

# Each provider includes:
# - name: unique identifier
# - display_name: human-friendly name
# - auth_type: authentication type
# - credentials: required credential types

Get a Specific Provider

provider = wealthica.providers.get_one("questrade")
print(f"Auth type: {provider['auth_type']}")

Institution APIs

These APIs require user authentication:

List All Institutions

user = wealthica.login("user_123")
institutions = user.institutions.get_list()

for inst in institutions:
    print(f"ID: {inst['id']}")
    print(f"Provider: {inst['provider']['display_name']}")

Get a Specific Institution

institution = user.institutions.get_one("603522490d2b02001233a5d6")

Sync an Institution

Trigger a refresh to fetch the latest data from the provider:

institution = user.institutions.sync("603522490d2b02001233a5d6")

Remove an Institution

user.institutions.remove("603522490d2b02001233a5d6")

Position APIs

Get Positions

user = wealthica.login("user_123")

# Get all positions
positions = user.positions.get_list()

# Get positions for specific institutions
positions = user.positions.get_list(
    institutions=["603522490d2b02001233a5d6"]
)

for pos in positions:
    security = pos.get('security', {})
    print(f"{security['name']} ({security['symbol']})")
    print(f"  Quantity: {pos['quantity']}")
    print(f"  Market Value: {pos['market_value']}")
    print(f"  Gain: {pos['gain_percent']}%")

Transaction APIs

List Transactions

user = wealthica.login("user_123")

# Get all transactions
transactions = user.transactions.get_list(
    institutions=["603522490d2b02001233a5d6"]
)

# With filters
transactions = user.transactions.get_list(
    institutions=["603522490d2b02001233a5d6"],
    from_date="2024-01-01",
    to_date="2024-06-30",
    limit=100
)

Get a Specific Transaction

tx = user.transactions.get_one(tx_id="603522490d2b02001233a5d7")

Balance History APIs

Get Balance History

user = wealthica.login("user_123")

history = user.history.get_list(
    institutions=["603522490d2b02001233a5d6"],
    from_date="2024-01-01",
    to_date="2024-06-30"
)

for entry in history:
    print(f"Date: {entry['date']}, Investment: {entry['investment']}")

Error Handling

The SDK provides specific exception classes for different error types:

from wealthica import (
    Wealthica,
    WealthicaError,
    WealthicaAuthenticationError,
    WealthicaAPIError,
    WealthicaValidationError,
    WealthicaNotFoundError,
    WealthicaRateLimitError,
)

try:
    user = wealthica.login("user_123")
    institution = user.institutions.get_one("invalid_id")
except WealthicaNotFoundError as e:
    print(f"Institution not found: {e.message}")
except WealthicaAuthenticationError as e:
    print(f"Authentication failed: {e.message}")
except WealthicaRateLimitError as e:
    print(f"Rate limit exceeded: {e.message}")
except WealthicaAPIError as e:
    print(f"API error [{e.status_code}]: {e.message}")
except WealthicaError as e:
    print(f"Wealthica error: {e.message}")

Context Manager Support

The SDK supports context managers for automatic cleanup:

with Wealthica(client_id="...", secret="...") as wealthica:
    providers = wealthica.providers.get_list()
    # Connection is automatically closed when exiting the block

Configuration Options

wealthica = Wealthica(
    client_id="your_client_id",              # Required
    secret="your_secret",                    # Required
    base_url="https://api.wealthica.com/v1", # Optional, default API URL
    connect_url="https://connect.wealthica.com",  # Optional, Connect widget URL
    timeout=30.0,                            # Optional, request timeout in seconds
)

Connecting Users (Frontend Integration)

To connect user institutions, you'll need to use Wealthica Connect in your frontend. Here's how the flow works:

  1. Backend: Generate a user token
user = wealthica.login("user_123")
token = user.get_token()
# Send this token to your frontend
  1. Frontend: Use the token with Wealthica Connect (JavaScript)
import Wealthica from 'wealthica-sdk-js';

const wealthica = Wealthica.init({
    clientId: 'YOUR_CLIENT_ID',
    authEndpoint: '/wealthica/auth',
});

const user = wealthica.login();
user.connect()
    .onConnection((institution) => {
        console.log('Connected:', institution);
    })
    .onError((error) => {
        console.error('Error:', error);
    });
  1. Backend: Handle the callback to receive the connected institution

For full frontend integration, see the JavaScript SDK.

Publishing to PyPI

To release a new version of the SDK:

1. Update Version

Update the version number in pyproject.toml:

version = "X.Y.Z"

And in src/wealthica/__init__.py:

__version__ = "X.Y.Z"

2. Update Changelog

Add release notes to CHANGELOG.md.

3. Commit and Tag

git add -A
git commit -m "vX.Y.Z: Description of changes"
git tag -a vX.Y.Z -m "Release vX.Y.Z"
git push origin main --tags

4. Build the Package

# Install build tools
pip install build twine

# Clean previous builds
rm -rf dist/ build/ src/*.egg-info

# Build
python3 -m build

5. Upload to PyPI

# Upload using twine (requires PyPI API token)
python3 -m twine upload dist/* -u __token__ -p YOUR_PYPI_TOKEN

To get a PyPI API token:

  1. Go to https://pypi.org/manage/account/
  2. Create an API token with "Upload packages" scope
  3. Use __token__ as username and the token as password

Documentation

Support

License

MIT License - see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wealthica-1.0.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wealthica-1.0.0-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file wealthica-1.0.0.tar.gz.

File metadata

  • Download URL: wealthica-1.0.0.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for wealthica-1.0.0.tar.gz
Algorithm Hash digest
SHA256 df51325556ef9955cf833e24646dfb583048bd35bcd454b9e41eacacacf9c5aa
MD5 797c119c5f77db8dab93f6a584ddc452
BLAKE2b-256 447a01124205c0a22b7ffe0e35c6eabda5b57f65769312baeff84d173b20933c

See more details on using hashes here.

File details

Details for the file wealthica-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: wealthica-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for wealthica-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 42e68316b96bf49a32a5b572da4ed900d5767ea87e320c008d151e936c0e069a
MD5 de9b290cabf98fefaee9ab1b97662e2b
BLAKE2b-256 7670e3b4ba13779efc5dcb6e890ecdcdd41ea9f0f77efd5d1cb60b40a1c1e639

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page