Skip to main content

Agent-side trading SDK for Alpaca execution and Bridgewood reporting.

Project description

oneworldtrade

oneworldtrade is the agent-side trading SDK that executes orders through a broker and reliably reports resulting fills to Bridgewood.

What It Does

oneworldtrade sits between your strategy code and the external systems:

agent -> oneworldtrade -> Alpaca + Bridgewood

The agent decides what to trade.

oneworldtrade handles:

  • speaking Alpaca correctly
  • waiting for a final fill outcome
  • normalizing the resulting execution
  • reporting the completed fill to Bridgewood
  • retrying Bridgewood reporting safely
  • returning a structured result object instead of a vague success boolean

What It Does Not Do

This package is intentionally narrow.

It is not:

  • a strategy framework
  • a scheduler
  • a bot runner
  • a portfolio analytics suite
  • a replacement for Bridgewood
  • a replacement for Alpaca

In v1 it only supports:

  • Alpaca equities
  • Bridgewood agent-side reporting
  • fully filled orders only
  • synchronous workflows

Bridgewood is treated as an external dependency. oneworldtrade does not provision Bridgewood accounts or agents and only uses an existing BRIDGEWOOD_AGENT_API_KEY.

If you want broker-only usage, oneworldtrade supports that too. A Trader can be constructed without Bridgewood credentials and used with report_to_bridgewood=False.

Install

pip install oneworldtrade

For local development:

python -m venv .venv
./.venv/bin/pip install -e ".[dev]"

Environment

Trader.from_env() reads from the ambient process environment provided by the agent runtime, shell, container, or deployment platform. oneworldtrade does not auto-load a local .env file.

Minimum environment:

ALPACA_API_KEY=...
ALPACA_SECRET_KEY=...
BRIDGEWOOD_AGENT_API_KEY=bgw_...

Optional:

ONEWORLDTRADE_ALPACA_PAPER=true
BRIDGEWOOD_API_BASE=https://bridgewood.onrender.com/v1
ONEWORLDTRADE_BRIDGEWOOD_REPORTING_MODE=aggregated_order
ONEWORLDTRADE_POLL_INTERVAL_SECONDS=2
ONEWORLDTRADE_FILL_TIMEOUT_SECONDS=120
ONEWORLDTRADE_HTTP_TIMEOUT_SECONDS=15
ONEWORLDTRADE_REPORT_MAX_ATTEMPTS=3
ONEWORLDTRADE_REPORT_BACKOFF_SECONDS=1
ONEWORLDTRADE_LOG_LEVEL=INFO

If you want .env loading in your own agent repo, do that at the application layer before constructing Trader.

Broker-only Usage

from oneworldtrade import Trader

trader = Trader.from_env_broker_only()
result = trader.buy("AAPL", qty=1, report_to_bridgewood=False)

If Bridgewood reporting is requested without a configured reporter, oneworldtrade raises a configuration error before the order is submitted.

Quick Start

from oneworldtrade import Trader

trader = Trader.from_env()

result = trader.buy("AAPL", qty=1)

if result.report_succeeded:
    print("Filled and reported to Bridgewood")
elif result.filled:
    print("Filled at broker, but Bridgewood reporting needs attention")
else:
    print(f"Order status: {result.broker_status}")

Advanced Usage

from decimal import Decimal

from oneworldtrade import OrderType, TimeInForce, Trader

trader = Trader.from_env()

result = trader.place_order(
    symbol="AAPL",
    side="buy",
    qty=Decimal("2"),
    order_type=OrderType.LIMIT,
    limit_price=Decimal("180"),
    time_in_force=TimeInForce.DAY,
)

Reconciliation

oneworldtrade is designed to recover cleanly from the important partial-failure case:

  1. Alpaca fills the order.
  2. Bridgewood reporting fails temporarily.
  3. The agent replays the filled order later.

Because Bridgewood deduplicates on external_order_id, oneworldtrade defaults to using the stable Alpaca order ID when reporting a fully filled order. Replays are safe.

The default reporting mode is aggregated_order, which reports one Bridgewood execution per filled Alpaca order. For future flexibility, the package also supports a per_fill reporting mode that emits one Bridgewood execution per broker fill after the order reaches a final filled state.

When Bridgewood exposes GET /v1/executions, oneworldtrade uses it during reconciliation to discover which external IDs are already recorded and only replays missing executions. If the endpoint is unavailable on an older Bridgewood deployment, reconciliation falls back to replaying filled orders and relying on duplicate-safe reporting.

reconciliation = trader.reconcile(limit=20)
print(reconciliation.successful_reports)

CLI

The package includes a small CLI:

oneworldtrade config show
oneworldtrade broker verify
oneworldtrade bridgewood verify
oneworldtrade broker-only-verify
oneworldtrade buy AAPL --qty 1
oneworldtrade sell TSLA --qty 1
oneworldtrade sync-order <broker-order-id>
oneworldtrade reconcile --limit 20

Design Notes

  • Only fully filled orders are reported to Bridgewood.
  • Bridgewood setup is human-owned and outside the package scope.
  • Alpaca is wrapped behind a broker client interface so future brokers can be added without rewriting strategy code.
  • The default public API is Trader.
  • Naive execution timestamps are rejected rather than silently assumed to be UTC.
  • Lower-level broker and Bridgewood clients are still available when needed.

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

oneworldtrade-0.1.2.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oneworldtrade-0.1.2-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

File details

Details for the file oneworldtrade-0.1.2.tar.gz.

File metadata

  • Download URL: oneworldtrade-0.1.2.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for oneworldtrade-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a17cda014b011cdacda0d5ae8d89107b2090fead2cad1ca65fd9894ba9077c93
MD5 03b642926ff62351636df1e98df10811
BLAKE2b-256 cb2bfbd0419cae81d058229775c80fccc5e7c9e54e4e18d80aef90a5b5555f32

See more details on using hashes here.

Provenance

The following attestation bundles were made for oneworldtrade-0.1.2.tar.gz:

Publisher: publish.yml on BridgewoodSecurities/oneworldtrade

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file oneworldtrade-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: oneworldtrade-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 28.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for oneworldtrade-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1a3363659596ed392a9dfe0c7e6e38e9294d0647c23c32a0e289053037f645f7
MD5 1818189c97d2189c5b2bd9d9fe4fd49e
BLAKE2b-256 10f2fc39c20e2d9d6796d95e1bb4726c11051dd8d28827993ae93d05a63c71f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for oneworldtrade-0.1.2-py3-none-any.whl:

Publisher: publish.yml on BridgewoodSecurities/oneworldtrade

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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