SWOP REST API

Quickstart

Getting the latest exchange rates using curl

  
    
  curl -i -H "Authorization: ApiKey <your-api-key-here>" "https://swop.cx/rest/rates"

  
Response
  
    
  [
    {
      "base_currency": "EUR",
      "quote_currency": "CHF",
      "quote": 1.054871,
      "date": "2020-04-04"
    },
    {
      "base_currency": "EUR",
      "quote_currency": "GBP",
      "quote": 0.878173,
      "date": "2020-04-04"
    },
    {
      "base_currency": "EUR",
      "quote_currency": "USD",
      "quote": 1.079301,
      "date": "2020-04-04"
    }
  ]

  

Authentication

The SWOP API uses API Keys to authenticate requests. To authenticate a request, you can either pass your API Key as a query parameter or as a request header.

Authentication by Query Parameter

Pass the API Key using the query parameter api-key

  
    
    curl -i "https://swop.cx/rest/rates?api-key=<your-api-key-here>"
  
  
Authentication by Request Header

Pass the API Key using the Authorization request header with type ApiKey to access the rates resource for example:

  
    
    curl -i -H "Authorization: ApiKey <your-api-key-here>" "https://swop.cx/rest/rates"
  
  

Endpoint

You can access the REST API using this base URL:

  
    
    https://swop.cx/rest
  
  

The endpoint accepts GET requests, some requests have optional query params

Resources

The following REST resources are available.

Single rate

The /rates/<base_currency>/<quote_currency> resource returns a single rate for the given currency pair.

Get the latest EUR/USD rate:

  
    
      https://swop.cx/rest/rates/EUR/USD
    
  

Get the historical EUR/USD rate for 4th of April 2020:

  
    
      https://swop.cx/rest/rates/EUR/USD?date=2020-04-04
    
  

Query Parameters
/rates/<base_currency>/<quote_currency>
name required description
date no ISO 8601 date (YYYY-MM-DD, between 1999-01-04 and today). Default is today.

Response: Single rate

  
    
      {
        "base_currency": "EUR",
        "quote_currency": "USD",
        "quote": 1.079301,
        "date": "2020-04-04"
      }
    
  

List of rates

The /rates resource returns a list of either latest or historical rates.

Get the latest rates:

  
    
      https://swop.cx/rest/rates
    
  

Get historical rates:

  
    
      https://swop.cx/rest/rates?date=2020-04-04
    
  

Get rates for specific base/quote currencies:

  
    
      https://swop.cx/rest/rates?date=2020-04-04&base_currency=CHF&quote_currencies=GBP,EUR,USD
    
  

Query Parameters
/rates
name required description
date no ISO 8601 date (YYYY-MM-DD, between 1999-01-04 and today). Default is today.
base_currency no ISO 4217 Currency code. Default is EUR.
quote_currencies no Comma separated list of ISO 4217 currency codes. By default, all quote currencies are returned.

Response: List of rates

  
    
      [
        {
          "base_currency": "CHF",
          "quote_currency": "EUR",
          "quote": 0.947983,
          "date": "2020-04-04"
        },
        {
          "base_currency": "CHF",
          "quote_currency": "GBP",
          "quote": 0.832494,
          "date": "2020-04-04"
        },
        {
          "base_currency": "CHF",
          "quote_currency": "USD",
          "quote": 1.023159,
          "date": "2020-04-04"
        }
      ]
    
  

Timeseries

The /timeseries resource returns a series of rates for a given time range.

Get the timeseries:

  
    
      https://swop.cx/rest/timeseries?date_from=2020-01-01&date_to=2020-04-04
    
  

Query Parameters
/timeseries
name required description
date_from yes ISO 8601 date (YYYY-MM-DD). Must be between 1999-01-04 and today.
date_to yes ISO 8601 date (YYYY-MM-DD). Must be between 1999-01-04 and today.
base_currency no ISO 4217 Currency code. Default is EUR.
quote_currencies no Comma separated list of ISO 4217 currency codes. By default, all quote currencies are returned.

Get the Limit: The timeseries query is limited to 4000 rates per request. This allows to query a time range of:

  • Single quote_currency: 10 years
  • Multiple quoteCurrencies: Single range divided by number of quote currencies, eg. 2 years for 5 quote currencies
  • All quoteCurrencies: 1 month

Response: List of currency pairs, each with rate time series

  
    
      [
        {
          "base_currency": "GBP",
          "quote_currency": "EUR",
          "time_series": [
            {
              "date": "2020-04-01",
              "quote": 1.129721
            },
            {
              "date": "2020-04-02",
              "quote": 1.138768
            },
            {
              "date": "2020-04-03",
              "quote": 1.138727
            },
            {
              "date": "2020-04-04",
              "quote": 1.138727
            }
          ]
        },
        {
          "base_currency": "GBP",
          "quote_currency": "USD",
          "time_series": [
            {
              "date": "2020-04-01",
              "quote": 1.236679
            },
            {
              "date": "2020-04-02",
              "quote": 1.242678
            },
            {
              "date": "2020-04-03",
              "quote": 1.229030
            },
          {
            "date": "2020-04-04",
            "quote": 1.229030
          }
        }
      ]
    
  

Fluctuation

The /fluctuations resource returns the fluctuation of rates between two dates.

Get the fluctuation:

  
    
      https://swop.cx/rest/fluctuations?date_from=2020-01-01&date_to=2020-04-04
    
  

Query Parameters
/fluctuations
name required description
date_from yes ISO 8601 date (YYYY-MM-DD). Must be between 1999-01-04 and today.
date_to yes ISO 8601 date (YYYY-MM-DD). Must be between 1999-01-04 and today.
base_currency no ISO 4217 Currency code. Default is EUR.
quote_currencies no Comma separated list of ISO 4217 currency codes. By default, all quote currencies are returned.

Response: List currency pairs with fluctuation between given dates

  
    
      [
        {
          "base_currency": "GBP",
          "quote_currency": "EUR",
          "date_from": "2019-01-01",
          "date_to": "2020-04-01",
          "fluctuation": 0.013850,
          "fluctuation_percent": 1.241193,
          "rate_from": {
            "base_currency": "GBP",
            "quote_currency": "EUR",
            "quote": 1.115871,
            "date": "2019-01-01"
          },
          "rate_to": {
            "base_currency": "GBP",
            "quote_currency": "EUR",
            "quote": 1.129721,
            "date": "2020-04-01"
          }
        },
        {
          "base_currency": "GBP",
          "quote_currency": "JPY",
          "date_from": "2019-01-01",
          "date_to": "2020-04-01",
          "fluctuation": -7.605382,
          "fluctuation_percent": -5.412233,
          "rate_from": {
            "base_currency": "GBP",
            "quote_currency": "JPY",
            "quote": 140.522084,
            "date": "2019-01-01"
          },
          "rate_to": {
            "base_currency": "GBP",
            "quote_currency": "JPY",
            "quote": 132.916702,
            "date": "2020-04-01"
          }
        },
        {
          "base_currency": "GBP",
          "quote_currency": "USD",
          "date_from": "2019-01-01",
          "date_to": "2020-04-01",
          "fluctuation": -0.040275,
          "fluctuation_percent": -3.153953,
          "rate_from": {
            "base_currency": "GBP",
            "quote_currency": "USD",
            "quote": 1.276953,
            "date": "2019-01-01"
          },
          "rate_to": {
            "base_currency": "GBP",
            "quote_currency": "USD",
            "quote": 1.236679,
            "date": "2020-04-01"
          }
        }
      ]
    
  

Amount Conversion

The /conversions/<base_currency>/<quote_currency> resource converts an amount from the base currency to the quote currency.

Get the conversion (Convert 200 EUR to USD):

  
    
      https://swop.cx/rest/conversions/EUR/USD?amount=200
    
  

Query Parameters
/conversions/<base_currency>/<quote_currency>
name required description
amount yes Decimal amount in base currency.
date no ISO 8601 date (YYYY-MM-DD, between 1999-01-04 and today). Default is today.

Response: Single conversion.

  
    
      {
        "base_currency": "EUR",
        "quote_currency": "USD",
        "base_amount": 200.00,
        "quote_amount": 215.86,
        "date": "2020-04-04"
      }
    
  

Multi Amount Conversion

The /conversions resource converts an amount to multiple quote currencies.

Get the conversion (Convert 125.25 CHF to multiple quote currencies):

  
    
      https://swop.cx/rest/conversions?base_currency=CHF&quote_currencies=GBP,EUR,USD&amount=125.25
    
  

Query Parameters
/conversions
name required description
amount yes Decimal amount in base currency.
base_currency no ISO 4217 Currency code. Default is EUR.
quote_currencies no Comma separated list of ISO 4217 currency codes. By default, all quote currencies are returned.
date no ISO 8601 date (YYYY-MM-DD, between 1999-01-04 and today). Default is today.

Response: List of conversions.

  
    
      [
        {
          "base_currency": "CHF",
          "quote_currency": "EUR",
          "base_amount": 125.25,
          "quote_amount": 118.73,
          "date": "2020-04-04"
        },
        {
          "base_currency": "CHF",
          "quote_currency": "GBP",
          "base_amount": 125.25,
          "quote_amount": 104.27,
          "date": "2020-04-04"
        },
        {
          "base_currency": "CHF",
          "quote_currency": "USD",
          "base_amount": 125.25,
          "quote_amount": 128.15,
          "date": "2020-04-04"
        }
      ]
    
  

Currencies

The /currencies resource returns information about the available currencies.

Get the:

  
    
      https://swop.cx/rest/currencies
    
  

Query Parameters
/currencies
name required description
currency_codes no Comma separated list of ISO 4217 currency codes. By default, all currencies are returned.
include_historical no Boolean, include historical currencies for which we don't have current rates. Default false.

Response:

  
    
      [
        {
          "code": "SGD",
          "numeric_code": "702",
          "decimal_digits": 2,
          "name": "Singapore dollar",
          "active": true
        },
        {
          "code": "USD",
          "numeric_code": "840",
          "decimal_digits": 2,
          "name": "United States dollar",
          "active": true
        },
        {
          "code": "ZMK",
          "numericCode": "894",
          "decimalDigits": 2,
          "name": "Zambian kwacha",
          "active": false
        }
      ]
    
  

arrow-up icon