Skip to main content

FiveTwenty

Documentation Python License: MIT Code style: ruff

A Python client for the OANDA v20 REST API. Async-first with a synchronous wrapper, every monetary value in Decimal, and all seven v20 endpoint groups implemented.

Features

  • Async-first AsyncClient, plus a thread-backed sync Client with the same surface
  • mypy strict throughout, with typed models and TypedDict responses
  • Two runtime dependencies: httpx and pydantic
  • Retries with backoff for safe requests only; writes are never re-sent, so a timed-out order can't be double-submitted
  • Price and transaction streaming with stall detection and configurable reconnection
  • 130+ Pydantic models and 41 enums, checked against OANDA's published spec by an automated parity pipeline

Quick Start

Installation

pip install fivetwenty python-dotenv

Or with uv:

uv add fivetwenty python-dotenv

Configuration

Create a .env file with your OANDA credentials:

FIVETWENTY_OANDA_TOKEN=your-api-token
FIVETWENTY_OANDA_ACCOUNT=your-account-id
FIVETWENTY_OANDA_ENVIRONMENT=practice

Usage

import asyncio
import time
from decimal import Decimal

from dotenv import load_dotenv

from fivetwenty import AsyncClient
from fivetwenty.models import ClientPrice, InstrumentName

# Load environment variables from .env file
load_dotenv()


async def main() -> None:
    # Zero-config client - automatically reads from environment variables
    async with AsyncClient() as client:
        # Get accounts
        accounts = await client.accounts.get_accounts()
        account_id = accounts[0].id

        # Create market order (use Decimal for financial values)
        order = await client.orders.post_market_order(
            account_id=account_id,
            instrument=InstrumentName.EUR_USD,
            units=1000,
            stop_loss=Decimal("1.0900"),
            take_profit=Decimal("1.1100"),
        )
        print(f"Order created: {order['lastTransactionID']}")

        # Stream real-time prices for 30 seconds
        end_time = time.time() + 30

        async for price in client.pricing.get_pricing_stream(
            account_id, [InstrumentName.EUR_USD]
        ):
            if isinstance(price, ClientPrice):  # Filter out heartbeats
                spread = price.closeout_ask - price.closeout_bid
                print(f"{price.instrument}: {price.closeout_bid}/{price.closeout_ask} (spread: {spread})")

            if time.time() > end_time:
                break


if __name__ == "__main__":
    asyncio.run(main())

Requirements

  • Python 3.10+
  • httpx >= 0.25.0
  • pydantic >= 2.5.0

API coverage

All seven OANDA v20 endpoint groups:

  • Accounts: account details, summary, instruments, configuration, change polling
  • Instruments: candles, order book and position book snapshots
  • Orders: create (market, limit, stop, market-if-touched), list, get, cancel, replace, client extensions
  • Trades: list, get, close, client extensions, dependent take-profit/stop-loss orders
  • Positions: list, get, close by instrument
  • Pricing: current prices, streaming, account-scoped candles, latest candles
  • Transactions: history by time or ID range, single lookup, streaming

License

MIT License - see LICENSE file for details.

Disclaimer

This library is provided for educational and demonstration purposes only.

Trading financial instruments involves substantial risk of loss. Test against a practice account before risking real capital; you are solely responsible for your trading decisions, and the authors accept no liability for losses incurred through use of this software. Past performance is not indicative of future results.

USE AT YOUR OWN RISK.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fivetwenty-0.4.0.tar.gz (145.5 kB view details)

Uploaded Source

Built Distribution

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

fivetwenty-0.4.0-py3-none-any.whl (176.3 kB view details)

Uploaded Python 3

File details

Details for the file fivetwenty-0.4.0.tar.gz.

File metadata

  • Download URL: fivetwenty-0.4.0.tar.gz
  • Upload date:
  • Size: 145.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.6

File hashes

Hashes for fivetwenty-0.4.0.tar.gz
Algorithm Hash digest
SHA256 fa7136bcf38d374075ee5d54b7b9849f81d7534a4389923e8e17c18ec2ebb3e6
MD5 ad8beca73d8e1cbab68f12847869c9e9
BLAKE2b-256 2315158fc382adac88cd4ef0673d46725178d8000f739fb568631c46e69d3c7a

See more details on using hashes here.

File details

Details for the file fivetwenty-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: fivetwenty-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 176.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.6

File hashes

Hashes for fivetwenty-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0049d3469ea2baa2c6d9f7ff015babbf4bece61fb25e460e1e0953c34f7ab41
MD5 b5527d9671afd3b5ef0b7ed455d0a51a
BLAKE2b-256 28f7dbaec49fef3f6acb23e9dd5dcd13110c222d86c885623176bb048caad7cd

See more details on using hashes here.

Release history Release notifications | RSS feed

0.5.0

2 files

0.4.1

2 files

This release

0.4.0 This release

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page