Simple, elegant Python client for OANDA's REST API v20
Project description
FiveTwenty
A comprehensive, production-ready Python client for the OANDA v20 REST API.
Features
- Async-first with sync wrapper
- Type-safe with mypy strict compliance and comprehensive TypedDict responses
- Minimal dependencies (only httpx + pydantic)
- Robust client with retries, rate limiting, and comprehensive error handling
- Complete API coverage with 100% endpoint implementation (all 7 endpoint groups)
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
OANDA v20 API Implementation
- Account Management: Complete account operations, configuration updates, and change polling
- Order Operations: Full order lifecycle - create, list, get, cancel, replace, and client extensions
- Trade Management: Complete trade operations - list, get, close, modify, and dependent orders
- Position Management: Full position operations - list, get, close by instrument
- Pricing & Streaming: Real-time pricing, reliable streaming, and historical candles
- Transaction History: Complete audit trail, streaming, and incremental updates
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. The examples and code provided in this library are for demonstration purposes only and should not be used for actual trading without thorough testing and understanding of the risks involved.
- Past performance is not indicative of future results
- You are solely responsible for any trading decisions and their consequences
- The authors and contributors accept no liability for any financial losses incurred through use of this software
- Always test thoroughly with paper trading accounts before risking real capital
- Consult with qualified financial advisors before making investment decisions
USE AT YOUR OWN RISK.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fivetwenty-0.3.0.tar.gz.
File metadata
- Download URL: fivetwenty-0.3.0.tar.gz
- Upload date:
- Size: 93.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f48b01a174dadedda26eecb73f67fd29bcd87a636373af2a8778c8c78647b14d
|
|
| MD5 |
bc30cc5b04d9b35938b95be937b8fb30
|
|
| BLAKE2b-256 |
5bf7e4b41e2aa1f03645beb817de6fe8e79c962c0f7334f3a6b740e4b9864f9d
|
File details
Details for the file fivetwenty-0.3.0-py3-none-any.whl.
File metadata
- Download URL: fivetwenty-0.3.0-py3-none-any.whl
- Upload date:
- Size: 113.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38640f8915d1db04130507cc29d41a071402b1fd788e7640d639357cc04f0ce2
|
|
| MD5 |
6afca45616d10b58d35b04596761e996
|
|
| BLAKE2b-256 |
ecb6996ffa0939f2dff06a5cfb4388e3d99f01427294227c51f8cff0dd055b3f
|