LogoLogo
vBase.comvBase App
  • Welcome
    • Welcome to vBase
    • Unique Advantages
    • Core Concepts
      • How vBase Works
      • What is a Stamp?
      • Technical Overview
      • Why Blockchains?
    • Example Use Cases
  • Getting Started
    • Start your Journey
    • Stamping Best Practices
    • Python Quickstart
      • Cloud Notebooks
      • Local Installation
  • Web Tools
    • Stamp an Object
    • Verify an Object
  • Use Case How-Tos
    • Verified Investment Track Records
  • Python SDK
    • Samples
      • Creating a Dataset
      • Adding a Dataset Record
      • Adding a Dataset Record Asynchronously
      • Restoring Dataset Provenance
      • Stamp Interactive Brokers Portfolio
      • Stamp Alpaca Portfolio
    • Windows Setup Guide
    • Package vbase-py
    • Package vbase-py-tools
      • Setup
      • commit_s3_objects
      • verify_s3_objects
  • Other SDKs
    • COM Library Overview
    • Working in Excel
      • Via vBase Workbook
      • Via Excel VBA
    • COM API Reference
    • C#
    • TypeScript
  • Technical Reference
    • Command Line Interface
    • Windows Subsystem for Linux (WSL) Guide
    • GCE S3 Compatible Bucket Setup
    • Smart Contract Addresses
Powered by GitBook
On this page
  • 1. Prerequisites
  • 2. Download and Install Client Portal Gateway
  • 3. Set Environment Variables
  • 4. Run the Sample
  1. Python SDK
  2. Samples

Stamp Interactive Brokers Portfolio

PreviousRestoring Dataset ProvenanceNextStamp Alpaca Portfolio

Last updated 1 month ago

This sample illustrates how to retrieve, save, and stamp an Interactive Brokers (IB) portfolio.

The sample can be run from the command line interactively or as a script if your environment is set appropriately.

The sample will run the Interactive Brokers (IB) Client Portal Gateway on your Windows computer and make a request to it using the Web API from Python.

You can find the implementation in .

1. Prerequisites

  1. Interactive Brokers Account: You must have an IB account (live or paper trading).

  2. Python: Ensure Python is installed on your Windows machine.

  3. vBase: Follow the to set up Windows environment to run vBase samples.

2. Download and Install Client Portal Gateway

Interactive Brokers provides the Client Portal Gateway as a lightweight API gateway for accessing account data via a Web API. Follow these steps to download and run the gateway:

  1. Download the Client Portal Gateway:

    • Visit the official and download the latest Client Portal Gateway for Windows.

    • Alternatively, you can access the latest Client Portal Gateway directly from the .

  2. Extract the ZIP File:

    • After downloading the Client Portal Gateway ZIP file, extract it to a folder on your machine (e.g., C:\IBClientPortalGateway).

  3. Run the Gateway:

    • At the Command Line, run:

    cd \\path\\to\\clientportal\\clientportal.gw
    bin\\run.bat root\\conf.yaml
  4. Authenticate to the Gateway:

    • Open the client portal in a browser:

    https://localhost:5000/

    You may need to ignore security warnings and accept the self-signed certificate in your browser.

    • Login to the client portal with your IB credentials.

    • You should see the “Client login succeeds” message.

    • Once the gateway is running, it provides a Web API that requires authentication via the session token returned during the login process. The gateway will keep running in the background.

3. Set Environment Variables

Set the following environment variables for your IB and vBase configuration:

  • IB Configuration:

    • IB_ACCOUNT_ID - The IB account id.

  • AWS S3 Configuration (Optional if you save the portfolio data elsewhere):

    • AWS_ACCESS_KEY_ID - The Access Key used to connect to the S3 service.

    • AWS_SECRET_ACCESS_KEY - The Secret Key used to connect to the S3 service.

    • AWS_S3_BUCKET_NAME - The AWS S3 bucket name used to store the portfolio data.

  • vBase Configuration:

    • VBASE_FORWARDER_URL - vBase Forwarder Service URL:

      • https://dev.api.vbase.com/forwarder/ for development/testnet.

      • https://api.vbase.com/forwarder/ for production.

    • VBASE_API_KEY - The vBase API Key used to access the Forwarder service.

    • VBASE_COMMITMENT_SERVICE_PRIVATE_KEY - The private key used to sign portfolio stamps.

    • VBASE_DATASET_NAME - The name of the vBase dataset that will hold the portfolio history.

4. Run the Sample

Run the sample from the command line:

python3 stamp_interactive_brokers_portfolio.py

or walk through the sample in an interactive window.

stamp_interactive_brokers_portfolio.py
vBase Windows Guide
Client Portal Gateway page
IBKR GitHub Repository
1. Prerequisites
2. Download and Install Client Portal Gateway
3. Set Environment Variables
4. Run the Sample