An unofficial async Python client for currency exchange rates.
Install from pip:
pip install afxapicomInstall from source:
pip install git+https://github.com/MrBaconHat/afxapi-python.gitAll requests are made using the Client class, initialized with your API key.
import afxapicom
import asyncio
async def main():
client = afxapicom.Client('YOUR_API_KEY')
# make calls here
asyncio.run(main())result = await client.status()
print(result)result = await client.currencies(currencies=['EUR', 'USD'])
print(result)result = await client.latest(base_currency='USD', currencies=['EUR', 'GBP'])
print(result)result = await client.historical('2024-01-01', base_currency='USD')
print(result)result = await client.range('2024-01-01', '2024-01-07', base_currency='USD')
print(result)result = await client.convert(1000, base_currency='USD', currencies=['EUR', 'GBP'])
print(result)from afxapicom import Client
from afxapicom.errors import AuthenticationFailed, RateLimited, QuotaExceeded
async def main():
client = Client('YOUR_API_KEY')
try:
result = await client.latest()
print(result)
except AuthenticationFailed:
print("Invalid API key")
except RateLimited:
print("Rate limit hit, slow down")
except QuotaExceeded:
print("Monthly quota exceeded")
asyncio.run(main())