---
title: "US Congress Trading"
description: "US Congress Trading dataset from Quiver Quantitative."
canonical: https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quiver-quantitative/us-congress-trading
markdown: https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quiver-quantitative/us-congress-trading.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/03%20Writing%20Algorithms/14%20Datasets/23%20Quiver%20Quantitative/04%20US%20Congress%20Trading
modified: 2026-11-01
index: https://www.quantconnect.com/llms.txt
---

# US Congress Trading

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Writing Algorithms](https://www.quantconnect.com/docs/v2/writing-algorithms.md) > Datasets > [Quiver Quantitative](https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quiver-quantitative.md) > US Congress Trading

> Code examples are shown in Python. Append `?lang=csharp` to this URL for the C# version of this page.

## Introduction

The US Congress Trading dataset by Quiver Quantitative tracks US Equity trades made by members of Congress in the Senate and the House of Representatives. The data covers 1,800 US Equities, starts in January 2016, and is delivered on a daily frequency. This dataset is created by scraping SEC reports.

This dataset depends on the [US Equity Security Master](https://www.quantconnect.com/datasets/quantconnect-us-equity-security-master) dataset because the US Equity Security Master dataset contains information on splits, dividends, and symbol changes.

For more information about the US Congress Trading dataset, including CLI commands and pricing, see the [dataset listing](https://www.quantconnect.com/datasets/quiver-quantitative-congress-trading).

## About the Provider

[Quiver Quantitative](https://www.quiverquant.com/) was founded by two college students in February 2020 with the goal of bridging the information gap between Wall Street and non-professional investors. Quiver allows retail investors to tap into the power of big data and have access to actionable, easy to interpret data that hasn’t already been dissected by Wall Street.

## Getting Started

The following snippet demonstrates how to request data from the US Congress Trading dataset:

```python
self.aapl = self.add_equity("AAPL", Resolution.DAILY).symbol
self.dataset_symbol = self.add_data(QuiverCongress, self.aapl).symbol

self._universe = self.add_universe(QuiverQuantCongressUniverse, self.universe_selection)
```

## Data Summary

The following table describes the dataset properties:

| Property | Value |
| --- | --- |
| Start Date | January 2016 |
| Asset Coverage | 1,800 US Equities |
| Data Density | Sparse |
| Resolution | Daily |
| Timezone | UTC |

## Requesting Data

To add US Congress Trading data to your algorithm, call the `add_data` method. Save a reference to the dataset `Symbol` so you can access the data later in your algorithm.

```python
class QuiverCongressDataAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self.set_start_date(2019, 1, 1)
        self.set_end_date(2020, 6, 1)
        self.set_cash(100000)

        symbol = self.add_equity("AAPL", Resolution.DAILY).symbol
        self.dataset_symbol = self.add_data(QuiverCongress, symbol).symbol
```

## Accessing Data

To get the current US Congress Trading data, index the current [`Slice`](https://www.quantconnect.com/docs/v2/writing-algorithms/key-concepts/time-modeling/timeslices.md) with the dataset `Symbol`. Slice objects deliver unique events to your algorithm as they happen, but the `Slice` may not contain data for your dataset at every time step. To avoid issues, check if the `Slice` contains the data you want before you index it.

```python
def on_data(self, slice: Slice) -> None:
    if slice.contains_key(self.dataset_symbol):
        data_points = slice[self.dataset_symbol]
        for data_point in data_points:
            self.log(f"{self.dataset_symbol} transaction amount at {slice.time}: {data_point.amount}")
```

To iterate through all of the dataset objects in the current `Slice`, call the `get` method.

```python
def on_data(self, slice: Slice) -> None:
    for dataset_symbol, data_point in slice.get(QuiverCongress).items():
        self.log(f"{dataset_symbol} transaction amount at {slice.time}: {data_point.amount}")
```

## Historical Data

To get historical US Congress Trading data, call the `history` method with the dataset `Symbol`. If there is no data in the period you request, the history result is empty.

```python
# DataFrame
history_df = self.history(self.dataset_symbol, 100, Resolution.DAILY)

# Dataset objects
history_bars = self.history[QuiverCongress](self.dataset_symbol, 100, Resolution.DAILY)
```

For more information about historical data, see [History Requests](https://www.quantconnect.com/docs/v2/writing-algorithms/historical-data/history-requests.md).

## Universe Selection

To select a dynamic universe of US Equities based on US Congress Trading data, call the `add_universe` method with the `QuiverQuantCongressUniverse` class and a selection function.

```python
def initialize(self) -> None:
    self._universe = self.add_universe(QuiverQuantCongressUniverse, self.universe_selection)

def universe_selection(self, alt_coarse: List[QuiverQuantCongresssUniverse]) -> List[Symbol]:
    return [d.symbol for d in alt_coarse \
        if d.amount > 200000 and d.transaction == OrderDirection.BUY]
```

For more information about dynamic universes, see [Universes](https://www.quantconnect.com/docs/v2/writing-algorithms/universes/key-concepts.md).

## Universe History

You can get historical universe data in an algorithm and in the Research Environment.

### Historical Universe Data in Algorithms

To get historical universe data in an algorithm, call the `history` method with the `Universe` object and the lookback period. If there is no data in the period you request, the history result is empty.

```python
# DataFrame example where the columns are the QuiverQuantCongressUniverse attributes:
history_df = self.history(self._universe, 30, Resolution.DAILY, flatten=True)

# Series example where the values are lists of QuiverQuantCongressUniverse objects:
history = self.history(self._universe, 30, Resolution.DAILY)
for (univere_symbol, time), trades in universe_history.items():
    for trade in trades:
        self.log(f"{trade.symbol} amount at {trade.end_time}: {trade.amount} {trade.representative}") {trade.representative}")
```

### Historical Universe Data in Research

To get historical universe data in research, call the `universe_history` method with the `Universe` object, a start date, and an end date. This method returns the filtered universe. If there is no data in the period you request, the history result is empty.

```python
# DataFrame example where the columns are the QuiverQuantCongressUniverse attributes:
history_df = qb.universe_history(universe, qb.time-timedelta(30), qb.time, flatten=True)

# Series example where the values are lists of QuiverQuantCongressUniverse objects:
universe_history = qb.universe_history(universe, qb.time-timedelta(30), qb.time)
for (univere_symbol, time), trades in universe_history.items():
    for trade in trades:
        print(f"{trade.symbol} amount at {trade.end_time}: {trade.amount} {trade.representative}")
```

You can call the `history` method in Research.

## Remove Subscriptions

To remove a subscription, call the `remove_security` method.

```python
self.remove_security(self.dataset_symbol)
```

If you subscribe to US Congress Trading data for assets in a dynamic universe, remove the dataset subscription when the asset leaves your universe. To view a common design pattern, see [Track Security Changes](https://www.quantconnect.com/docs/v2/writing-algorithms/algorithm-framework/alpha/key-concepts.md#05-Track-Security-Changes).

## Example Applications

The US Congress Trading dataset enables you to take immediate action on trades made by informed Members of Congress. Examples include the following strategies:

- Following the trades of specific representatives on the premise that the representatives are more informed
- Assigning a long/short-bias to securities on a daily frequency based on how Members of Congress are trading them

### Classic Algorithm Example

The following example algorithm follows the net bias of the trades made by Members of Congress each day. When Members of Congress are net buyers, the algorithm buys. When they are net sellers, the algorithm short sells.

```python
from AlgorithmImports import *

class QuiverCongressDataAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        self.set_cash(100000)
        # Subscribe to Congress trading updates for the underlying equity.
        equity = self.add_equity("AAPL", Resolution.DAILY)
        quiver_congress_symbol = self.add_data(QuiverCongress, equity).symbol
        # Warm up the custom dataset with recent Congress trading history.
        history = self.history(QuiverCongress, quiver_congress_symbol, 60, Resolution.DAILY)
        self.debug(f"We got {len(history)} items from our history request")

    def on_data(self, data: Slice) -> None:
        congress_by_symbol = data.get(QuiverCongress)
        # Estimate sentiment for each security from the net direction of Congress trades.
        net_quantity_by_symbol = {}
        for symbol, points in congress_by_symbol.items():
            symbol = symbol.underlying
            if symbol not in net_quantity_by_symbol:
                net_quantity_by_symbol[symbol] = 0
            # Weight each vote by order size.
            for point in points:
                net_quantity_by_symbol[symbol] += (1 if point.transaction == OrderDirection.BUY else -1) * point.amount
        for symbol, net_quantity in net_quantity_by_symbol.items():
            if net_quantity == 0:
                self.liquidate(symbol)
                continue
            # Follow net Congress buying direction and short net selling direction.
            self.set_holdings(symbol, 1 if net_quantity > 0 else -1)
```

### Framework Algorithm Example

The following example algorithm follows the net bias of the trades made by Members of Congress each day. When Members of Congress are net buyers, the algorithm buys. When they are net sellers, the algorithm short sells.

```python
from AlgorithmImports import *

class QuiverCongressDataAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        self.set_cash(100000)
        self.settings.seed_initial_prices = True
        self.universe_settings.minimum_time_in_universe = timedelta(days=7)
        # Add the Quiver Congress universe.
        self.add_universe(QuiverQuantCongressUniverse, "QuiverQuantCongresssUniverse", Resolution.DAILY, self.universe_selection)
        self.add_alpha(CongressAlphaModel())
        self.set_portfolio_construction(InsightWeightingPortfolioConstructionModel(lambda time: None))
        self.add_risk_management(NullRiskManagementModel())
        self.set_execution(ImmediateExecutionModel())

    def universe_selection(self, alt_coarse: List[QuiverQuantCongressUniverse]) -> List[Symbol]:
        # Return all symbols from the Quiver Congress universe.
        return [d.symbol for d in alt_coarse]

class CongressAlphaModel(AlphaModel):
    _securities = []
    _insight_by_asset = {}

    def update(self, algorithm: QCAlgorithm, slice: Slice) -> List[Insight]:
        congress_data_by_asset = slice.get(QuiverCongress)
        if congress_data_by_asset:
            self._insight_by_asset.clear()
            net_quantity_by_asset = {}
            for congress_data_symbol, congress_data in congress_data_by_asset.items():
                security = algorithm.securities[congress_data_symbol.underlying]
                if security not in net_quantity_by_asset:
                    net_quantity_by_asset[security] = 0
                for point in congress_data:
                    net_quantity_by_asset[security] += (1 if point.transaction == OrderDirection.BUY else -1) * point.amount
            for security, net_quantity in net_quantity_by_asset.items():
                # Emit an up insight when Congress members are net buyers.
                if net_quantity > 0 and not security.holdings.is_long:
                    direction = InsightDirection.UP
                # Emit a down insight when Congress members are net sellers.
                elif net_quantity < 0 and not security.holdings.is_short:
                    direction = InsightDirection.DOWN
                else:
                    continue
                self._insight_by_asset[security] = Insight.price(security, timedelta(7), direction, weight=0.5)
        # To avoid error messages, emit the insights when the algorithm has a price for the asset.
        return [
                self._insight_by_asset.pop(security)
                for security in list(self._insight_by_asset.keys())
                if security.price
        ]

    def on_securities_changed(self, algorithm: QCAlgorithm, changes: SecurityChanges) -> None:
        for security in changes.added_securities:
            self._securities.append(security)
            # Add the Quiver Congress subscription for the security.
            security.congress_data = algorithm.add_data(QuiverCongress, security, Resolution.DAILY)
            history = algorithm.history(QuiverCongress, security.congress_data, 14, Resolution.DAILY)
            algorithm.debug(f"We got {len(history)} items from our history request for {security}")
        for security in changes.removed_securities:
            if security in self._securities:
                if security in self._insight_by_asset:
                    self._insight_by_asset.pop(security)
                # Remove the Quiver Congress subscription for the security.
                algorithm.remove_security(security.congress_data)
                self._securities.remove(security)
```

### Research Example

The following example lists trades made by Members of Congress daily as buyers.

```python
qb = QuantBook()

# Add QuiverCongress
aapl = qb.add_equity("AAPL", Resolution.DAILY).symbol
quiver_congress_symbol = qb.add_data(QuiverCongress, aapl).symbol

# Historical data
history = qb.history(QuiverCongress, quiver_congress_symbol, 60, Resolution.DAILY)
for (symbol, time), trades in history.items():
    for trade in trades:
        print(f'{time} {trade.symbol.value} {trade.representative} {trade.amount}')

# Add Universe Selection
def universe_selection(alt_coarse: List[QuiverQuantCongressUniverse]) -> List[Symbol]:
    return [d.symbol for d in alt_coarse if d.transaction == OrderDirection.BUY]

universe = qb.add_universe(QuiverQuantCongressUniverse, universe_selection)

# Historical Universe data
history = qb.universe_history(universe, qb.time-timedelta(60), qb.time)
for (univere_symbol, time), trades in history.items():
    for trade in trades:
        print(f'{time} {trade.symbol.value} {trade.representative} {trade.amount}')
```

## Data Point Attributes

The US Congress Trading dataset provides `QuiverCongressDataPoint`, `QuiverCongress`, and `QuiverQuantCongressUniverse` objects.

### QuiverCongressDataPoint Attributes

`QuiverCongressDataPoint` objects has the following attributes:

*Members of `QuantConnect.DataSource.QuiverCongressDataPoint` (JSON): https://www.quantconnect.com/services/inspector?type=T:QuantConnect.DataSource.QuiverCongressDataPoint&language=python*

### QuiverCongress Attributes

`QuiverCongress` objects has the following attributes:

*Members of `QuantConnect.DataSource.QuiverCongress` (JSON): https://www.quantconnect.com/services/inspector?type=T:QuantConnect.DataSource.QuiverCongress&language=python*

### QuiverQuantCongressUniverse Attributes

`QuiverQuantCongressUniverse` objects has the following attributes:

*Members of `QuantConnect.DataSource.QuiverQuantCongressUniverse` (JSON): https://www.quantconnect.com/services/inspector?type=T:QuantConnect.DataSource.QuiverQuantCongressUniverse&language=python*
