Skip to main content

Ingest portfolio and other data from multiple brokerages, and analyze it

Project description

bankroll PyPI version CircleCI

Command line interface and notebook utilities to ingest portfolio and other data from multiple brokerages, and analyze it.

This is the frontend to the bankroll project, which is comprised of several libraries that can also be used on their own.

Table of contents:

  1. Installation
  2. Connecting to brokers
    1. Interactive Brokers
    2. Charles Schwab
    3. Fidelity
    4. Vanguard
    5. (your broker here)
  3. Saving configuration
  4. Extending bankroll

Installation

To install the bankroll command line utility, select from the list of available brokerage plugins, and run pip install with those brokerages listed as extras.

For example, to install bankroll with support for Interactive Brokers and Charles Schwab:

pip3 install bankroll[ibkr,schwab]

Or from the repository root, if you have cloned the code:

pip3 install .[ibkr,schwab,fidelity]

Once installed (and presuming your Python path is set up correctly), the command line tool can be invoked directly:

bankroll --help

Connecting to brokers

After being set up, bankroll can be used from the command line to bring together data from multiple brokerages.

For example, to show all positions held in both Interactive Brokers and Charles Schwab:

bankroll \
  --ibkr-tws-port 7496 \
  --schwab-positions ~/Positions-2019-01-01.CSV \
  --schwab-transactions ~/Transactions_20190101.CSV \
  positions

Run with --help to see all options:

bankroll --help

Interactive Brokers

Interactive Brokers (sometimes abbreviated as IB or IBKR) offers a well-supported API, which—along with ib_insync—makes it possible to load up-to-date portfolio data and request real-time information about particular securities.

For bankroll, this functionality is implemented via the bankroll-broker-ibkr plugin:

pip3 install bankroll[ibkr]

To load data from Interactive Brokers, one of IB's trading applications—Trader Workstation or IB Gateway—must be running and logged-in to accept API connections. You may wish to use IBC to automate the startup and login of these applications.

Once Trader Workstation or IB Gateway is running, and API connections are enabled, provide the local port number to bankroll like so:

bankroll \
  --ibkr-tws-port 7496 \
  [command]

Querying trade history

IB's Trader Workstation API does not support retrieving information about an account's historical trades, so bankroll must use their Flex Web Service.

To set this up, log in to Account Management, then browse to Settings → Account Settings in the sidebar:

Account Settings

In the Reporting section of this page, click the gear to configure Flex Web Service:

Flex Web Service

Once configured, copy the Current Token for use on the command line.

Then, you must save a query for bankroll to use. Back in the sidebar, browse to Reports → Flex Queries:

Flex Queries

Click the gear to configure Custom Flex Queries:

Custom Flex Queries

Create a new Trade Confirmation Flex Query Template:

Trade Confirmation Flex Query Templates

Pick a name of your choosing, then make sure the Date Period reflects the historical period you care about (e.g., Last 365 Calendar Days):

Trade Confirmation Flex Query Details

Under Sections, click Trade Confirmations and enable everything in the dialog which appears:

Trade Confirmation button Trade Confirmation options

After saving your query, expand it in the list to view and copy the Query ID for use on the command line.

With the token and the query ID from your account, historical trades can be downloaded:

bankroll \
  --ibkr-flex-token [token] \
  --ibkr-trades [query ID] \
  activity

Querying dividend history

This workflow will be simplified in the future.

To incorporate the history of dividend payments in your portfolio, follow the same steps for the Trade Confirmation Flex Query, but create an Activity Flex Query instead.

The only section which needs to be enabled is Change in Dividend Accruals:

Activity query options

Pass your existing token, and the new query's ID, on the command line:

bankroll \
  --ibkr-flex-token [token] \
  --ibkr-activity [query ID] \
  activity

Charles Schwab

Charles Schwab does not offer an API, but it does provide CSV files for export, which bankroll can then import.

This functionality is implemented via the bankroll-broker-schwab plugin:

pip3 install bankroll[schwab]

Browse to the "Positions" and/or "Transactions" screen:

Positions and Transactions

Click the "Export" link in the top-right:

Export

Then provide the paths of either or both these downloaded files to bankroll:

bankroll \
  --schwab-positions ~/path/to/Positions.CSV \
  --schwab-transactions ~/path/to/Transactions.CSV \
  [command]

Fidelity

Fidelity is supported through a similar facility as Schwab.

This functionality is implemented via the bankroll-broker-fidelity plugin:

pip3 install bankroll[fidelity]

More detailed instructions have yet to be written—contributions welcome!

Vanguard

Vanguard is a work in progress, and may not be as fully-featured as the other brokerages listed here. Support is being developed in the bankroll-broker-vanguard plugin:

(your broker here)

bankroll intends to abstract away broker-specific details as much as possible, to minimize the work required to support each one, so if your broker isn't listed above, please consider building a new brokerage plugin! We want the list to grow over time, because it's extremely useful to be able to aggregate and analyze data across multiple brokers at once.

To add a new brokerage, create a new subclass of AccountData, then implement the methods as required by the interface. As long as the new subclass is loaded at runtime, it will be automatically included in functionality like data aggregation.

If the brokerage offers a facility to load market data, consider extending the bankroll-marketdata interfaces as well (though this is optional).

Saving configuration

To preserve settings across runs, all of the command-line arguments demonstrated above can also be saved into an INI file. The configuration file is especially useful to store default values, because when a setting is specified in a configuration file as well as on the command line, the command-line argument will take precedence.

To create a configuration, copy bankroll.default.ini to ~/.bankroll.ini, or leave it in your working directory as bankroll.ini, then edit the file to apply your desired settings.

If you would like to store the configuration somewhere else, you can also provide custom paths via the --config argument on the command line.

Extending bankroll

Although the command-line interface exposes a basic set of functionality, it will never be able to capture the full set of possible use cases. For much greater flexibility, you can write Python code to use bankroll directly, and build on top of its APIs for your own purposes.

For some examples, see the included notebooks.

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

bankroll-0.4.1.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

bankroll-0.4.1-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file bankroll-0.4.1.tar.gz.

File metadata

  • Download URL: bankroll-0.4.1.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4

File hashes

Hashes for bankroll-0.4.1.tar.gz
Algorithm Hash digest
SHA256 1a7f21ced4b198600f421cac78f6a46ee10bfb179b512d71744318a722c878bc
MD5 c1ec47206f74bc7aa124d6770692ab3c
BLAKE2b-256 e0396fb571ac9ab5270ddf50257534efdf03b6fb1840a3ad67fb8c5685cf1dd5

See more details on using hashes here.

File details

Details for the file bankroll-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: bankroll-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4

File hashes

Hashes for bankroll-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 53275c831000d8d725edbe353c7e0fdd3c70795edba649e8e0be110ccd56f120
MD5 e53229d99d92d2c5a8a7b7d2a3da72d5
BLAKE2b-256 4219effcfaab380798971e78884846ac93e73c0b7da929e41f02b1d89c13a75e

See more details on using hashes here.

Supported by

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