# 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.OrderBook do
  @moduledoc """
  API calls for all endpoints tagged `OrderBook`.
  """

  alias CoinAPIMarketDataRESTAPI.Connection
  import CoinAPIMarketDataRESTAPI.RequestBuilder

  @doc """
  Get current order book
  Retrieves the current order book for the specified symbol.

  ### Parameters

  - `connection` (CoinAPIMarketDataRESTAPI.Connection): Connection to server
  - `symbol_id` (String.t): The symbol ID (from the Metadata -> Symbols)
  - `opts` (keyword): Optional parameters
    - `:limit_levels` (integer()): The maximum number of levels to include in the response.

  ### Returns

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

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

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

  @doc """
  Current depth of the order book
  Retrieves the current depth of the order book for the specified symbol.

  ### Parameters

  - `connection` (CoinAPIMarketDataRESTAPI.Connection): Connection to server
  - `symbol_id` (String.t): The symbol ID (from the Metadata -> Symbols)
  - `opts` (keyword): Optional parameters
    - `:limit_levels` (integer()): The maximum number of levels to include in the response.

  ### Returns

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

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

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

  @doc """
  Historical data
  Get historical order book snapshots for a specific symbol within time range, returned in time ascending order.              :::info The historical order book data via the REST API is currently limited by a number of updates and to the maximum number of 20 levels. :::  :::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 (preferred method, required if 'time_start' is not provided)
    - `:time_start` (String.t): Starting time in ISO 8601 (deprecated, use 'date' instead)
    - `:time_end` (String.t): Timeseries ending time in ISO 8601 (deprecated, use 'date' instead)
    - `: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)
    - `:limit_levels` (integer()): Maximum amount of levels from each side of the book to include in response (optional)

  ### Returns

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

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

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

  @doc """
  Latest data
  Get latest order book snapshots for a specific symbol, returned in time descending order.              :::info The historical order book data via the REST API is currently limited by a number of updates and to the maximum number of 20 levels. :::

  ### Parameters

  - `connection` (CoinAPIMarketDataRESTAPI.Connection): Connection to server
  - `symbol_id` (String.t): Symbol identifier of 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)
    - `:limit_levels` (integer()): Maximum amount of levels from each side of the book to include in response (optional)

  ### Returns

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

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

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