Skip to content

Foreign Exchange Asynchronous Endpoints

This Foreign Exchange endpoint provides asynchronous methods to interact with the foreign exchange of the authenticated user.

Example usage of the Foreign Exchange endpoint object:

import asyncio
from pyrevolut.client import AsyncClient

CREDS_JSON_LOC = "path/to/creds.json"

client = AsyncClient(
    creds_loc=CREDS_JSON_LOC,
    sandbox=True,
)

async def run():
    async with client:
        rate = await client.ForeignExchange.get_exchange_rate(
            from_currency="USD",
            to_currency="EUR",
            amount=1.0,
        )
        print(rate)

asyncio.run(run())

EndpointForeignExchangeAsync

Bases: BaseEndpointAsync

The async Foreign Exchange API

Retrieve information on exchange rates between currencies, buy and sell currencies.

Source code in pyrevolut/api/foreign_exchange/endpoint/asynchronous.py
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
class EndpointForeignExchangeAsync(BaseEndpointAsync):
    """The async Foreign Exchange API

    Retrieve information on exchange rates between currencies, buy and sell currencies.
    """

    async def get_exchange_rate(
        self,
        from_currency: str,
        to_currency: str,
        amount: float | None = None,
        **kwargs,
    ) -> dict | GetExchangeRate.Response:
        """
        Get the sell exchange rate between two currencies.

        Parameters
        ----------
        from_currency : str
            The currency that you exchange from in ISO 4217 format.
        to_currency : str
            The currency that you exchange to in ISO 4217 format.
        amount : float | None
            The amount of the currency to exchange from.
            The default value is 1.00 if not provided.

        Returns
        -------
        dict | GetExchangeRate.Response
            A dict with the information about the exchange rate.
        """
        endpoint = GetExchangeRate
        path = endpoint.ROUTE
        params = endpoint.Params(
            from_=from_currency,
            to=to_currency,
            amount=amount,
        )

        return await self.client.get(
            path=path,
            response_model=endpoint.Response,
            params=params,
            **kwargs,
        )

    async def exchange_money(
        self,
        request_id: str,
        from_account_id: UUID,
        from_currency: str,
        to_account_id: UUID,
        to_currency: str,
        from_amount: float | None = None,
        to_amount: float | None = None,
        reference: str | None = None,
        **kwargs,
    ) -> dict | ExchangeMoney.Response:
        """
        Exchange money using one of these methods:

        Sell currency:
            You know the amount of currency to sell.
            For example, you want to exchange 135.5 USD to some EUR.
            Specify the amount in the from object.

        Buy currency:
            You know the amount of currency to buy.
            For example, you want to exchange some USD to 200 EUR.
            Specify the amount in the to object.

        Parameters
        ----------
        request_id : str
            The ID of the request, provided by you.
            It helps you identify the transaction in your system.

            To ensure that an exchange transaction is not processed multiple
            times if there are network or system errors, the same request_id
            should be used for requests related to the same transaction.
        from_account_id : UUID
            The ID of the account to sell currency from.
        from_currency : str
            The currency to sell in ISO 4217 format.
        to_account_id : UUID
            The ID of the account to receive exchanged currency into.
        to_currency : str
            The currency to buy in ISO 4217 format.
        from_amount : float | None
            The amount of currency. Specify ONLY if you want to sell currency.
        to_amount : float | None
            The amount of currency. Specify ONLY if you want to buy currency.
        reference : str | None
            The reference for the exchange transaction, provided by you.
            It helps you to identify the transaction if you want to look it up later.

        Returns
        -------
        dict | ExchangeMoney.Response
            A dict with the information about the exchange transaction.
        """
        endpoint = ExchangeMoney
        path = endpoint.ROUTE
        body = endpoint.Body(
            from_=endpoint.Body.ModelFrom(
                account_id=from_account_id,
                currency=from_currency,
                amount=from_amount,
            ),
            to=endpoint.Body.ModelTo(
                account_id=to_account_id,
                currency=to_currency,
                amount=to_amount,
            ),
            reference=reference,
            request_id=request_id,
        )

        return await self.client.post(
            path=path,
            response_model=endpoint.Response,
            body=body,
            **kwargs,
        )

exchange_money(request_id, from_account_id, from_currency, to_account_id, to_currency, from_amount=None, to_amount=None, reference=None, **kwargs) async

Exchange money using one of these methods:

Sell currency: You know the amount of currency to sell. For example, you want to exchange 135.5 USD to some EUR. Specify the amount in the from object.

Buy currency: You know the amount of currency to buy. For example, you want to exchange some USD to 200 EUR. Specify the amount in the to object.

Parameters:

Name Type Description Default
request_id str

The ID of the request, provided by you. It helps you identify the transaction in your system.

To ensure that an exchange transaction is not processed multiple times if there are network or system errors, the same request_id should be used for requests related to the same transaction.

required
from_account_id UUID

The ID of the account to sell currency from.

required
from_currency str

The currency to sell in ISO 4217 format.

required
to_account_id UUID

The ID of the account to receive exchanged currency into.

required
to_currency str

The currency to buy in ISO 4217 format.

required
from_amount float | None

The amount of currency. Specify ONLY if you want to sell currency.

None
to_amount float | None

The amount of currency. Specify ONLY if you want to buy currency.

None
reference str | None

The reference for the exchange transaction, provided by you. It helps you to identify the transaction if you want to look it up later.

None

Returns:

Type Description
dict | Response

A dict with the information about the exchange transaction.

Source code in pyrevolut/api/foreign_exchange/endpoint/asynchronous.py
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
async def exchange_money(
    self,
    request_id: str,
    from_account_id: UUID,
    from_currency: str,
    to_account_id: UUID,
    to_currency: str,
    from_amount: float | None = None,
    to_amount: float | None = None,
    reference: str | None = None,
    **kwargs,
) -> dict | ExchangeMoney.Response:
    """
    Exchange money using one of these methods:

    Sell currency:
        You know the amount of currency to sell.
        For example, you want to exchange 135.5 USD to some EUR.
        Specify the amount in the from object.

    Buy currency:
        You know the amount of currency to buy.
        For example, you want to exchange some USD to 200 EUR.
        Specify the amount in the to object.

    Parameters
    ----------
    request_id : str
        The ID of the request, provided by you.
        It helps you identify the transaction in your system.

        To ensure that an exchange transaction is not processed multiple
        times if there are network or system errors, the same request_id
        should be used for requests related to the same transaction.
    from_account_id : UUID
        The ID of the account to sell currency from.
    from_currency : str
        The currency to sell in ISO 4217 format.
    to_account_id : UUID
        The ID of the account to receive exchanged currency into.
    to_currency : str
        The currency to buy in ISO 4217 format.
    from_amount : float | None
        The amount of currency. Specify ONLY if you want to sell currency.
    to_amount : float | None
        The amount of currency. Specify ONLY if you want to buy currency.
    reference : str | None
        The reference for the exchange transaction, provided by you.
        It helps you to identify the transaction if you want to look it up later.

    Returns
    -------
    dict | ExchangeMoney.Response
        A dict with the information about the exchange transaction.
    """
    endpoint = ExchangeMoney
    path = endpoint.ROUTE
    body = endpoint.Body(
        from_=endpoint.Body.ModelFrom(
            account_id=from_account_id,
            currency=from_currency,
            amount=from_amount,
        ),
        to=endpoint.Body.ModelTo(
            account_id=to_account_id,
            currency=to_currency,
            amount=to_amount,
        ),
        reference=reference,
        request_id=request_id,
    )

    return await self.client.post(
        path=path,
        response_model=endpoint.Response,
        body=body,
        **kwargs,
    )

get_exchange_rate(from_currency, to_currency, amount=None, **kwargs) async

Get the sell exchange rate between two currencies.

Parameters:

Name Type Description Default
from_currency str

The currency that you exchange from in ISO 4217 format.

required
to_currency str

The currency that you exchange to in ISO 4217 format.

required
amount float | None

The amount of the currency to exchange from. The default value is 1.00 if not provided.

None

Returns:

Type Description
dict | Response

A dict with the information about the exchange rate.

Source code in pyrevolut/api/foreign_exchange/endpoint/asynchronous.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
async def get_exchange_rate(
    self,
    from_currency: str,
    to_currency: str,
    amount: float | None = None,
    **kwargs,
) -> dict | GetExchangeRate.Response:
    """
    Get the sell exchange rate between two currencies.

    Parameters
    ----------
    from_currency : str
        The currency that you exchange from in ISO 4217 format.
    to_currency : str
        The currency that you exchange to in ISO 4217 format.
    amount : float | None
        The amount of the currency to exchange from.
        The default value is 1.00 if not provided.

    Returns
    -------
    dict | GetExchangeRate.Response
        A dict with the information about the exchange rate.
    """
    endpoint = GetExchangeRate
    path = endpoint.ROUTE
    params = endpoint.Params(
        from_=from_currency,
        to=to_currency,
        amount=amount,
    )

    return await self.client.get(
        path=path,
        response_model=endpoint.Response,
        params=params,
        **kwargs,
    )