# NOTE: This file is auto generated by OpenAPI Generator 7.14.0 (https://openapi-generator.tech).
# Do not edit this file manually.

defmodule ExchangeRatesHistoricalRESTAPI.Api.ExchangeRates do
  @moduledoc """
  API calls for all endpoints tagged `ExchangeRates`.
  """

  alias ExchangeRatesHistoricalRESTAPI.Connection
  import ExchangeRatesHistoricalRESTAPI.RequestBuilder

  @doc """
  Get specific rate
  Retrieves the exchange rate for a specific base and quote asset at a given time or the current rate.              :::info If you are using an exchange rate for mission-critical operations, then for best reliability, you should measure the difference between current time and the time returned from the response to ensure that value of the difference between those meets your internal requirements. :::

  ### Parameters

  - `connection` (ExchangeRatesHistoricalRESTAPI.Connection): Connection to server
  - `asset_id_base` (String.t): Requested exchange rate base asset identifier (from the Metadata -> Assets)
  - `asset_id_quote` (String.t): Requested exchange rate quote asset identifier (from the Metadata -> Assets)
  - `opts` (keyword): Optional parameters
    - `:time` (String.t): Time at which exchange rate is calculated (optional, if not supplied then current rate is returned)

  ### Returns

  - `{:ok, ExchangeRatesHistoricalRESTAPI.Model.V1ExchangeRate.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec get_specific_rate(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, ExchangeRatesHistoricalRESTAPI.Model.V1ExchangeRate.t} | {:error, Tesla.Env.t}
  def get_specific_rate(connection, asset_id_base, asset_id_quote, opts \\ []) do
    optional_params = %{
      :time => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/v1/exchangerate/#{asset_id_base}/#{asset_id_quote}")
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, ExchangeRatesHistoricalRESTAPI.Model.V1ExchangeRate}
    ])
  end

  @doc """
  Timeseries data
  Get the historical exchange rates between two assets in the form of the timeseries.

  ### Parameters

  - `connection` (ExchangeRatesHistoricalRESTAPI.Connection): Connection to server
  - `asset_id_base` (String.t): Requested exchange rates base asset identifier (from the Metadata -> Assets)
  - `asset_id_quote` (String.t): Requested exchange rates base asset identifier (from the Metadata -> Assets)
  - `opts` (keyword): Optional parameters
    - `:period_id` (String.t): Identifier of requested timeseries period (required, e.g. `5SEC` or `1HRS`)
    - `:time_start` (String.t): Timeseries starting time in ISO 8601 (required)
    - `:time_end` (String.t): Timeseries ending time in ISO 8601 (required)
    - `:limit` (integer()): Amount of items to return (optional, mininum is 1, maximum is 100000, default value is 100, if the parameter is used then every 100 output items are counted as one request)

  ### Returns

  - `{:ok, [%V1ExchangeRatesTimeseriesItem{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_exchangerate_asset_id_base_asset_id_quote_history_get(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, [ExchangeRatesHistoricalRESTAPI.Model.V1ExchangeRatesTimeseriesItem.t]} | {:error, Tesla.Env.t}
  def v1_exchangerate_asset_id_base_asset_id_quote_history_get(connection, asset_id_base, asset_id_quote, opts \\ []) do
    optional_params = %{
      :period_id => :query,
      :time_start => :query,
      :time_end => :query,
      :limit => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/v1/exchangerate/#{asset_id_base}/#{asset_id_quote}/history")
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, ExchangeRatesHistoricalRESTAPI.Model.V1ExchangeRatesTimeseriesItem}
    ])
  end

  @doc """
  Get all current rates
  Get the current exchange rate between requested asset and all other assets.              :::info If you are using an exchange rate for mission-critical operations, then for best reliability, you should measure the difference between current time and the time returned from the response to ensure that value of the difference between those meets your internal requirements. :::              :::info You can invert the rates by using Y = 1 / X equation, for example BTC/USD = 1 / (USD/BTC); :::

  ### Parameters

  - `connection` (ExchangeRatesHistoricalRESTAPI.Connection): Connection to server
  - `asset_id_base` (String.t): Requested exchange rates base asset identifier (from the Metadata -> Assets)
  - `opts` (keyword): Optional parameters
    - `:filter_asset_id` (String.t): Comma or semicolon delimited asset identifiers used to filter response (optional)
    - `:invert` (boolean()): True will invert all the rates (optional, if true then rates will be calculated as `rate = 1 / actual_rate` eg. `USD/BTC` as `BTC/USD`)
    - `:time` (String.t): Time for historical rates (optional)

  ### Returns

  - `{:ok, ExchangeRatesHistoricalRESTAPI.Model.V1ExchangeRates.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_exchangerate_asset_id_base_get(Tesla.Env.client, String.t, keyword()) :: {:ok, ExchangeRatesHistoricalRESTAPI.Model.V1ExchangeRates.t} | {:error, Tesla.Env.t}
  def v1_exchangerate_asset_id_base_get(connection, asset_id_base, opts \\ []) do
    optional_params = %{
      :filter_asset_id => :query,
      :invert => :query,
      :time => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/v1/exchangerate/#{asset_id_base}")
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, ExchangeRatesHistoricalRESTAPI.Model.V1ExchangeRates}
    ])
  end

  @doc """
  Timeseries periods
  You can also obtain historical exchange rates of any asset pair, grouped into time periods. Get full list of supported time periods available for requesting exchange rates historical timeseries data.              ## Timeseries periods Time unit | Period identifiers --- | --- Second | 1SEC, 2SEC, 3SEC, 4SEC, 5SEC, 6SEC, 10SEC, 15SEC, 20SEC, 30SEC Minute | 1MIN, 2MIN, 3MIN, 4MIN, 5MIN, 6MIN, 10MIN, 15MIN, 20MIN, 30MIN Hour | 1HRS, 2HRS, 3HRS, 4HRS, 6HRS, 8HRS, 12HRS Day | 1DAY, 2DAY, 3DAY, 5DAY, 7DAY, 10DAY

  ### Parameters

  - `connection` (ExchangeRatesHistoricalRESTAPI.Connection): Connection to server
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, [%V1TimeseriesPeriod{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_exchangerate_history_periods_get(Tesla.Env.client, keyword()) :: {:ok, [ExchangeRatesHistoricalRESTAPI.Model.V1TimeseriesPeriod.t]} | {:error, Tesla.Env.t}
  def v1_exchangerate_history_periods_get(connection, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/exchangerate/history/periods")
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, ExchangeRatesHistoricalRESTAPI.Model.V1TimeseriesPeriod}
    ])
  end
end
