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.

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.1.tar.gz (24.5 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.1-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: oneworldtrade-0.1.1.tar.gz
  • Upload date:
  • Size: 24.5 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.1.tar.gz
Algorithm Hash digest
SHA256 17c82679a3a25878812cb11fbbca32e29f3230682c98f1f37846368d39fef926
MD5 2a464605157ffbfd33459df2fc8bb65c
BLAKE2b-256 ea6504008d5b83269efe8d905f9bb0c9eb7d84713790a2643bd32c60b5b3da64

See more details on using hashes here.

Provenance

The following attestation bundles were made for oneworldtrade-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: oneworldtrade-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 27.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c9615a3b320e85f9899ef2382d2629e256a29e910e4a6b4bf85325f06a8a1a8d
MD5 0d08d12fed963ca1ea48a0a6079e3fce
BLAKE2b-256 b53f905c9d441c866e6c523d33f22ab0518afdf356d5d9fa72b9f2b0574ec6c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for oneworldtrade-0.1.1-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