FiveTwenty
FiveTwenty is a typed Python client for OANDA's v20 REST API. It provides an
AsyncClient for asyncio applications and a synchronous Client for blocking
request code.
What the SDK handles
- Seven endpoint groups: accounts, instruments, orders, trades, positions, pricing and transactions.
- Pydantic models with Python field names,
Decimalfinancial values and nativedatetimeattributes. - Response dictionaries that retain OANDA's envelope keys, such as
accountandlastTransactionID. - Connection reuse, structured API errors and retries for eligible read requests.
- Pricing and transaction streams, plus a pricing helper with configurable reconnection.
The SDK does not automatically retry writes. If an order request times out, its outcome may be unknown; check account or transaction state before submitting again. The API reference describes method signatures, return types and account-specific restrictions.
Quick start
Install Python 3.10 or later, then install the SDK. python-dotenv is optional; this
example uses it to load a local .env file.
pip install fivetwenty python-dotenv
With uv, use uv add fivetwenty python-dotenv instead.
Create .env with credentials for your OANDA v20 practice account, and keep it out
of version control:
FIVETWENTY_OANDA_TOKEN=your-practice-token
FIVETWENTY_OANDA_ACCOUNT=your-account-id
FIVETWENTY_OANDA_ENVIRONMENT=practice
This example reads the configured account and current pricing. It does not place an order. Printed prices are a snapshot, not a promised execution price.
import asyncio
from dotenv import load_dotenv
from fivetwenty import AsyncClient, Environment
load_dotenv()
async def main() -> None:
async with AsyncClient() as client:
if client.config.environment != Environment.PRACTICE:
message = "Use a practice account for this example"
raise ValueError(message)
response = await client.accounts.get_account_summary(client.account_id)
account = response["account"]
print(f"Balance: {account.balance} {account.currency}")
response_prices = await client.pricing.get_pricing(
client.account_id, instruments=["EUR_USD"]
)
for price in response_prices["prices"]:
print(f"{price.instrument}: {price.closeout_bid} / {price.closeout_ask}")
if __name__ == "__main__":
asyncio.run(main())
The SDK reads process environment variables; it does not load .env files itself.
For an order lifecycle, continue with
Your first trade.
Beta compatibility
The public API may change as this beta library is aligned with OANDA v20. Review changes before upgrading.
- Collection methods generally return an envelope. For example, read
response["orders"]afterget_orders()and retainresponse["lastTransactionID"]when tracking account state.get_accounts()returns its account list directly. - Omit a dependent-order update argument to leave that order unchanged; pass
Noneto cancel it. Partial dictionaries use OANDA's camelCase field names. max_retries=3allows the initial request plus three retries for eligible reads.max_retries=0still sends the initial request. Writes are sent once.datetime_formatcontrols the wire format. Parsed model attributes remain Python datetimes; Python represents microseconds, not OANDA's full nanosecond precision.
Requirements and development
The direct runtime dependencies are HTTPX >= 0.26.0 and Pydantic >= 2.7.0. See the testing guide for supported Python versions, coverage checks and opt-in practice-account tests.
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
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.5.0.tar.gz.
File metadata
- Download URL: fivetwenty-0.5.0.tar.gz
- Upload date:
- Size: 70.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40a2be964481100ca942ec70dc2c2dd0d8de9bbe95b7e978c03217db23dda170
|
|
| MD5 |
c761102fd425c683b05ee27dfe6edf8b
|
|
| BLAKE2b-256 |
7599b1fe47c1b1044ccb3acdacaddd9151cd0e0af2e5ece2cf106b014c3b87d6
|
File details
Details for the file fivetwenty-0.5.0-py3-none-any.whl.
File metadata
- Download URL: fivetwenty-0.5.0-py3-none-any.whl
- Upload date:
- Size: 76.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0045b0a323536f02d5769ff408d2163617ae9953bfb9a67de3b517547be50440
|
|
| MD5 |
a4e89063b6e7fe12f329b9d5bb4943d0
|
|
| BLAKE2b-256 |
495dae48f5674c2820fdcdb00ed63d968bc83781df4346dcceca8c96af72f005
|