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

defmodule CoinAPIMarketDataRESTAPI.Api.Trades do
  @moduledoc """
  API calls for all endpoints tagged `Trades`.
  """

  alias CoinAPIMarketDataRESTAPI.Connection
  import CoinAPIMarketDataRESTAPI.RequestBuilder

  @doc """
  Latest data
  Get latest trades executed up to 1 minute ago. Latest data is always returned in time descending order.

  ### Parameters

  - `connection` (CoinAPIMarketDataRESTAPI.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:filter_symbol_id` (String.t): Comma or semicolon delimited parts of symbol identifier used to filter response. (optional)
    - `:include_id` (boolean()): Information that additional exchange trade identifier should be included in the `id_trade` parameter of the trade if exchange providing identifiers.
    - `: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, [%V1Trade{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_trades_latest_get(Tesla.Env.client, keyword()) :: {:ok, [CoinAPIMarketDataRESTAPI.Model.V1Trade.t]} | {:error, Tesla.Env.t}
  def v1_trades_latest_get(connection, opts \\ []) do
    optional_params = %{
      :filter_symbol_id => :query,
      :include_id => :query,
      :limit => :query
    }

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

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

  @doc """
  Historical data
  Get history transactions from specific symbol, returned in time ascending order.  :::warning The 'time_start' and 'time_end' parameters must be from the same day as this endpoint provides intraday data only for specific day. Please use the 'date' parameter instead for querying data for a specific day without filter. :::

  ### Parameters

  - `connection` (CoinAPIMarketDataRESTAPI.Connection): Connection to server
  - `symbol_id` (String.t): Symbol identifier for requested timeseries (from the Metadata -> Symbols)
  - `opts` (keyword): Optional parameters
    - `:date` (String.t): Date in ISO 8601, returned data is for the whole given day (required if 'time_start' is not provided)
    - `:time_start` (String.t): Starting time in ISO 8601
    - `:time_end` (String.t): Timeseries ending time in ISO 8601
    - `:limit` (integer()): Amount of items to return (optional, minimum is 1, maximum is 100000, default value is 100, if the parameter is used then every 100 output items are counted as one request)
    - `:include_id` (boolean()): Information that additional exchange trade identifier should be included in the `id_trade` parameter of the trade if exchange providing identifiers.

  ### Returns

  - `{:ok, [%V1Trade{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_trades_symbol_id_history_get(Tesla.Env.client, String.t, keyword()) :: {:ok, [CoinAPIMarketDataRESTAPI.Model.V1Trade.t]} | {:error, Tesla.Env.t}
  def v1_trades_symbol_id_history_get(connection, symbol_id, opts \\ []) do
    optional_params = %{
      :date => :query,
      :time_start => :query,
      :time_end => :query,
      :limit => :query,
      :include_id => :query
    }

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

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

  @doc """
  Latest data by symbol_id
  Get latest trades executed up to 1 minute ago. Latest data is always returned in time descending order.

  ### Parameters

  - `connection` (CoinAPIMarketDataRESTAPI.Connection): Connection to server
  - `symbol_id` (String.t): Symbol identifier for requested timeseries (from the Metadata -> Symbols)
  - `opts` (keyword): Optional parameters
    - `: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)
    - `:include_id` (boolean()): Information that additional exchange trade identifier should be included in the `id_trade` parameter of the trade if exchange providing identifiers.

  ### Returns

  - `{:ok, [%V1Trade{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_trades_symbol_id_latest_get(Tesla.Env.client, String.t, keyword()) :: {:ok, [CoinAPIMarketDataRESTAPI.Model.V1Trade.t]} | {:error, Tesla.Env.t}
  def v1_trades_symbol_id_latest_get(connection, symbol_id, opts \\ []) do
    optional_params = %{
      :limit => :query,
      :include_id => :query
    }

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

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