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

defmodule FinFeedAPIStockRESTAPI.Api.Ohlcv do
  @moduledoc """
  API calls for all endpoints tagged `Ohlcv`.
  """

  alias FinFeedAPIStockRESTAPI.Connection
  import FinFeedAPIStockRESTAPI.RequestBuilder

  @doc """
  Historical data by exchange
  Get OHLCV timeseries data returned in time ascending order. Data can be requested by the period and for the specific exchange.

  ### Parameters

  - `connection` (FinFeedAPIStockRESTAPI.Connection): Connection to server
  - `exchange_id` (String.t): Exchange identifier of requested timeseries (from the Metadata -> Exchanges)
  - `period_id` (String.t): Identifier of requested timeseries period (e.g. `5SEC` or `1DAY`)
  - `time_start` (String.t): Timeseries starting time in ISO 8601
  - `time_end` (String.t): Timeseries ending time in ISO 8601
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, [%OhlcvExchangeTimeseriesItem{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_ohlcv_exchange_exchange_id_history_get(Tesla.Env.client, String.t, String.t, String.t, String.t, keyword()) :: {:ok, [FinFeedAPIStockRESTAPI.Model.OhlcvExchangeTimeseriesItem.t]} | {:error, Tesla.Env.t}
  def v1_ohlcv_exchange_exchange_id_history_get(connection, exchange_id, period_id, time_start, time_end, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/ohlcv/exchange/#{exchange_id}/history")
      |> add_param(:query, :period_id, period_id)
      |> add_param(:query, :time_start, time_start)
      |> add_param(:query, :time_end, time_end)
      |> Enum.into([])

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

  @doc """
  Historical data
  Get OHLCV timeseries data returned in time ascending order.

  ### Parameters

  - `connection` (FinFeedAPIStockRESTAPI.Connection): Connection to server
  - `exchange_id` (String.t): Exchange identifier of requested timeseries (from the Metadata -> Exchanges)
  - `symbol_id` (String.t): Symbol identifier of requested timeseries (from the Metadata -> Symbols)
  - `period_id` (String.t): Identifier of requested timeseries period (e.g. `5SEC` or `2MTH`)
  - `opts` (keyword): Optional parameters
    - `:time_start` (String.t): Timeseries starting time in ISO 8601
    - `:time_end` (String.t): Timeseries ending time in ISO 8601
    - `:limit` (integer()): Amount of items to return (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, [%OhlcvTimeseriesItem{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_ohlcv_exchange_symbol_exchange_id_symbol_id_history_get(Tesla.Env.client, String.t, String.t, String.t, keyword()) :: {:ok, [FinFeedAPIStockRESTAPI.Model.OhlcvTimeseriesItem.t]} | {:error, Tesla.Env.t}
  def v1_ohlcv_exchange_symbol_exchange_id_symbol_id_history_get(connection, exchange_id, symbol_id, period_id, opts \\ []) do
    optional_params = %{
      :time_start => :query,
      :time_end => :query,
      :limit => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/v1/ohlcv/exchange-symbol/#{exchange_id}/#{symbol_id}/history")
      |> add_param(:query, :period_id, period_id)
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

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

  @doc """
  Latest data
  Get OHLCV latest timeseries data returned in time descending order. Data can be requested by the period and for the specific symbol eg `BITSTAMP_SPOT_BTC_USD`, if you need to query timeseries by asset pairs eg. `BTC/USD`, then please reffer to the Exchange Rates Timeseries data              :::info OHLCV Latest endpoint is just the shortcut to the OHLCV Historical endpoint with substituted `time_start` and `time_end` parameters.  The OHLCV Historical endpoint data can be delayed a few seconds. Use OHLCV real-time data stream to get data without delay. :::

  ### Parameters

  - `connection` (FinFeedAPIStockRESTAPI.Connection): Connection to server
  - `exchange_id` (String.t): Exchange identifier of requested timeseries (from the Metadata -> Exchanges)
  - `symbol_id` (String.t): Symbol identifier of requested timeseries (from the Metadata -> Symbols)
  - `period_id` (String.t): Identifier of requested timeseries period (e.g. `5SEC` or `2MTH`)
  - `opts` (keyword): Optional parameters
    - `:limit` (integer()): Amount of items to return (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, [%OhlcvTimeseriesItem{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_ohlcv_exchange_symbol_exchange_id_symbol_id_latest_get(Tesla.Env.client, String.t, String.t, String.t, keyword()) :: {:ok, [FinFeedAPIStockRESTAPI.Model.OhlcvTimeseriesItem.t]} | {:error, Tesla.Env.t}
  def v1_ohlcv_exchange_symbol_exchange_id_symbol_id_latest_get(connection, exchange_id, symbol_id, period_id, opts \\ []) do
    optional_params = %{
      :limit => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/v1/ohlcv/exchange-symbol/#{exchange_id}/#{symbol_id}/latest")
      |> add_param(:query, :period_id, period_id)
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

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

  @doc """
  List all periods
  Get full list of supported time periods available for requesting OHLCV timeseries data.              ### Available 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 Month | 1MTH, 2MTH, 3MTH, 4MTH, 6MTH Year | 1YRS, 2YRS, 3YRS, 4YRS, 5YRS              :::tip You can assume that we will not remove any periods from this response, however, we may add new ones. :::

  ### Parameters

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

  ### Returns

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

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