Skip to content

Currencies converter πŸ’±ΒΆ

A dict-like class to handle converting steam currencies.

Instance is an API consumer of SERT and use service endpoints.

InstallationΒΆ

You can install converter with aiosteampy[converter] install target. For instance:

poetry add aiosteampy[converter]

Creating instance and loading ratesΒΆ

Before start converting rates need to be loaded.

from aiosteampy.ext.converter import CurrencyConverter

converter = CurrencyConverter()
await converter.load()

ConvertingΒΆ

Assuming that rates loaded we can convert prices of the items on steam market.

Target currency

Default target converted currency is USD but You can pass target currency as third argument

from aiosteampy import Currency

amount_in_usd = converter.convert(14564, Currency.UAH)

# if You need different target currency
amount_in_eur = converter.convert(14564, Currency.UAH, Currency.EUR)

Updating ratesΒΆ

Service update rates frequently and to synchronize rates with it You can use synchronize method of the instance. This will create and run a coroutine wrapped in asyncio.Task in the background.

croniter

This functionality requires croniter library to work, which will be already installed with aiosteampy[converter]

converter.synchronize()

Graceful shutdownΒΆ

In that case You need to close instance and handle canceling _sync_task before shutdown Your application:

converter.close()

Available currenciesΒΆ

You can see available currencies in converter web app. Just in case You need more or different currencies you can host the service by yourself and pass api_url argument to instance.

from yarl import URL

my_api_url = URL("https://mydomain.com")

converter = CurrencyConverter(api_url=my_api_url)