Package: bankroll
bankrollCommand line interface and notebook utilities toingest portfolio and other data from multiple brokerages, and analyze it.This is the frontend to thebankrollproject, which is comprised of several libraries that can also be used on their own.Table of contents:InstallationConnecting to brokersInteractive BrokersCharles SchwabFidelityVanguard(your broker here)Saving configurationExtendingbankrollInstallationTo install thebankrollcommand line utility, select fromthe list of available brokerage plugins, and runpip installwith those brokerages listed asextras.For example, to installbankrollwith support forInteractive BrokersandCharles 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 --helpConnecting to brokersAfter being set up,bankrollcan 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 \
  positionsRun with--helpto see all options:bankroll --helpInteractive BrokersInteractive Brokers(sometimes abbreviated as IB or IBKR) offers a well-supportedAPI, whichâ€”along withib_insyncâ€”makes it possible to load up-to-date portfolio data and request real-time information about particular securities.Forbankroll, this functionality is implemented via thebankroll-broker-ibkrplugin: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 useIBCto automate the startup and login of these applications.Once Trader Workstation or IB Gateway is running, andAPI connections are enabled, provide the local port number tobankrolllike so:bankroll \
  --ibkr-tws-port 7496 \
  [command]Querying trade historyIB'sTrader Workstation APIdoes not support retrieving information about an account's historical trades, sobankrollmust use theirFlex Web Service.To set this up, log in toAccount Management, then browse toSettingsâ†’Account Settingsin the sidebar:In theReportingsection of this page, click the gear to configureFlex Web Service:Once configured, copy theCurrent Tokenfor use on the command line.Then, you must save a query forbankrollto use. Back in the sidebar, browse toReportsâ†’Flex Queries:Click the gear to configureCustom Flex Queries:Create a new Trade Confirmation Flex Query Template:Pick a name of your choosing, then make sure theDate Periodreflects the historical period you care about (e.g.,Last 365 Calendar Days):UnderSections, clickTrade Confirmationsand enable everything in the dialog which appears:After saving your query, expand it in the list to view and copy theQuery IDfor 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] \
  activityQuerying dividend historyThis workflowwill be simplifiedin the future.To incorporate the history of dividend payments in your portfolio, follow the same steps for theTrade Confirmation Flex Query, but create an Activity Flex Query instead.The only section which needs to be enabled isChange in Dividend Accruals:Pass your existing token, and the new query's ID, on the command line:bankroll \
  --ibkr-flex-token [token] \
  --ibkr-activity [query ID] \
  activityCharles SchwabCharles Schwabdoes not offer an API, but it does provideCSVfiles for export, whichbankrollcan then import.This functionality is implemented via thebankroll-broker-schwabplugin:pip3 install bankroll[schwab]Browse to the "Positions" and/or "Transactions" screen:Click the "Export" link in the top-right:Then provide the paths of either or both these downloaded files tobankroll:bankroll \
  --schwab-positions ~/path/to/Positions.CSV \
  --schwab-transactions ~/path/to/Transactions.CSV \
  [command]FidelityFidelityis supported through a similar facility asSchwab.This functionality is implemented via thebankroll-broker-fidelityplugin:pip3 install bankroll[fidelity]To export position data,download from the Portfolio Positions page.To export transactions data,download from the History page.More detailed instructions have yet to be writtenâ€”contributions welcome!VanguardVanguardis awork in progress, and may not be as fully-featured as the other brokerages listed here. Support is being developed in thebankroll-broker-vanguardplugin:(your broker here)bankrollintends 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 considerbuilding 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 ofAccountData, 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 likedata aggregation.If the brokerage offers a facility to load market data, consider extending thebankroll-marketdatainterfaces as well (though this is optional).Saving configurationTo preserve settings across runs, all of the command-line arguments demonstrated above can also be saved into anINI file. The configuration file is especially useful to store default values, because when a setting is specified in a configuration fileas well ason the command line, the command-line argument will take precedence.To create a configuration, copybankroll.default.inito~/.bankroll.ini, or leave it in your working directory asbankroll.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--configargument on the command line.ExtendingbankrollAlthough 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 usebankrolldirectly, and build on top of its APIs for your own purposes.For some examples,see the included notebooks.