Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

46 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Build Status Coverage Status Last Commit License: MIT Python Version

Broadcast Datafeed

A Python client for interacting with the AEBroadcast API service.
This package provides authentication and methods to retrieve financial data, such as stock quotes, from the AEBroadcast platform.

πŸ“‹ Features

  • πŸ” Simple authentication with the AEBroadcast API
  • πŸ“Š Stock quotes and financial data retrieval
  • πŸ”„ Automatic authentication token management
  • ⚑ Synchronous HTTP client with httpx
  • πŸ”’ SSL verification via ssl.SSLContext (default CA bundle from certifi)
  • 🧾 Optional custom CA bundle support via ssl_pem_path
  • πŸ›‘οΈ Robust exception handling
  • βœ… 100% test coverage

πŸš€ Installation

Via pip (PyPI)

pip install broadcast-datafeed

Via Git

pip install git+https://github.com/sylvioCampos/broadcast-datafeed.git

For Development

git clone https://github.com/sylvioCampos/broadcast-datafeed.git
cd broadcast-datafeed
uv sync --locked --all-extras --dev

πŸ“– Usage

Basic Example

from broadcast_datafeed import Broadcast

# Initialize the client
client = Broadcast("your_username", "your_password")

# Get quotes for a list of symbols
quotes = client.get_quote(["PETR4", "VALE3"])
print(quotes)

# Logout when done
client.logout()

Advanced Examples

Keeping Session Alive

# Initialize with keep_alive to keep the session active
client = Broadcast("your_username", "your_password", keep_alive=True)

# Session will be kept alive automatically
quotes = client.get_quote(["BBAS3", "ITUB4"])

Specifying Specific Fields

client = Broadcast("your_username", "your_password")

# Request only specific fields
quotes = client.get_quote(
    symbols=["PETR4", "VALE3"],
    fields=["ULT", "VAR", "VOLUME"]
)

Manual Token Management

client = Broadcast("your_username", "your_password")

# Check current token
print(f"Token: {client.token}")
print(f"Refresh Token: {client.refresh_token}")

# Refresh token manually
result = client.token_refresh()
if result["success"]:
    print("Token refreshed successfully")

Error Handling

import httpx
from broadcast_datafeed import Broadcast

try:
    client = Broadcast("username", "password")
    quotes = client.get_quote(["PETR4"])
except httpx.RequestError as e:
    print(f"Connection error: {e}")
except httpx.HTTPStatusError as e:
    print(f"HTTP error {e.response.status_code}")

πŸ”§ API Reference

Broadcast

Initialization

Broadcast(
    usr: str,
    pwd: str,
    keep_alive: bool = False,
    verify_ssl: bool = True,
    ssl_pem_path: str | None = None,
)

Parameters:

  • usr (str): Username for authentication
  • pwd (str): Password for authentication
  • keep_alive (bool, optional): If True, keeps the session alive. Default: False
  • verify_ssl (bool, optional): If True, verifies SSL certificates. Default: True
  • ssl_pem_path (str, optional): Path to a PEM-encoded CA bundle file to load into the SSL context (in addition to certifi). Default: None

Raises:

  • httpx.RequestError: Connection or SSL error
  • httpx.HTTPStatusError: HTTP error returned by the API

Methods

login(usr: str, pwd: str) -> dict[str, str]

Perform login against the API and return authentication tokens.

Returns: Dictionary containing token and refreshToken

logout() -> dict[str, Any]

Log out from the API, invalidating the current token.

Returns: Response from the API after logout

keep_alive() -> dict[str, Any]

Keep the current API session alive.

Returns: Response from the API for the keep-alive request

token_refresh() -> dict[str, Any] | bool

Refresh the authentication token using the refresh token.

Returns: Result of the refresh operation or False on error

get_quote(symbols: list[str], fields: list[str] = None) -> dict[str, Any]

Retrieve quotes for the requested financial instruments.

Parameters:

  • symbols (list[str]): List of instrument symbols
  • fields (list[str], optional): List of desired fields. Default: all fields

Returns: Quote payload or error message

πŸ› οΈ Development

Requirements

  • Python 3.14+
  • uv - Modern Python package manager
  • httpx - HTTP client

Environment Setup

# Install uv
pip install uv

# Sync dependencies
uv sync --locked --all-extras --dev

Running Tests

# Run all tests with coverage
uv run pytest --cov=broadcast_datafeed --cov-report=term-missing

# Run specific test file
uv run pytest tests/test_datafeed.py -v

Linting

# Check code with ruff
uv run ruff check .

# Auto-fix issues when possible
uv run ruff check . --fix

Project Structure

broadcast/
β”œβ”€β”€ src/
β”‚   └── broadcast_datafeed/
β”‚       β”œβ”€β”€ __init__.py      # Package exports
β”‚       β”œβ”€β”€ datafeed.py      # Main Broadcast class
β”‚       └── py.typed         # PEP 561 marker
β”œβ”€β”€ tests/
β”‚   └── test_datafeed.py     # Unit tests
β”œβ”€β”€ .github/
β”‚   └── workflows/           # CI/CD with GitHub Actions
β”œβ”€β”€ pyproject.toml           # Project configuration
β”œβ”€β”€ pytest.ini               # Pytest configuration
β”œβ”€β”€ LICENSE                  # MIT License
└── README.md                # This file

🀝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for more details on how to contribute.

Contribution Process

  1. Fork the project
  2. Create a branch for your feature (git checkout -b feature/MyFeature)
  3. Commit your changes (git commit -m 'Add MyFeature')
  4. Push to the branch (git push origin feature/MyFeature)
  5. Open a Pull Request

⚠️ Security Notes

Important: The current version allows disabling SSL verification via verify_ssl=False, which should only be used in development environments. For production use, always keep SSL verification enabled (default behavior).

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘€ Author

Sylvio Campos Neto

πŸ™ Acknowledgments

  • AEBroadcast for the financial data API
  • Python community and httpx maintainers

Note: This is an unofficial client for the AEBroadcast API.

About

Python client library for Broadcast datafeed API - Real-time financial data feeds with authentication, session management, and stock quotes retrieval

Topics

Resources

Contributing

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages