malloryerik / ibex

Pre-alpha. Elixir wrapper for Interactive Brokers' TWS API.
https://github.com/malloryerik/ibex
MIT License
1 stars 0 forks source link

Change request "options" to "schedule" or something better. #2

Open malloryerik opened 5 months ago

malloryerik commented 5 months ago
      defmodule Ibex.Tws.RequestOptions do
        @moduledoc """
        Constructs options maps for various TWS API requests, ensuring they adhere to expected formats and values.
        """

        @doc """
        Creates a schedule map for historical data requests with default values and allows overriding.
        """
        def historical_data_schedule(overrides \\ %{}) do
          defaults = %{
            endDateTime: "", # Use current time if empty
            durationStr: "1 M",
            barSizeSetting: "1 day",
            whatToShow: "MIDPOINT",
            useRTH: true,
            formatDate: 1 # 1 for yyyyMMdd format
          }

          Enum.into(overrides, defaults)
        end
      end
      defmodule Ibex.IbexFetchers do
        @moduledoc """
        Provides functionalities to start and manage data fetcher processes.
        """

        alias Ibex.Supervisors.FetchersSupervisor
        alias Ibex.Fetchers.HistoricalDataFetcher

        @doc """
        Starts a HistoricalDataFetcher process with the given contract and schedule.
        """

        def start_historical_data_fetcher(contract, schedule) do
          args = {contract, schedule}
          case DynamicSupervisor.start_child(FetchersSupervisor, {HistoricalDataFetcher, args}) do
            {:ok, pid} -> {:ok, pid}
            {:error, {:already_started, pid}} -> {:ok, pid}
            {:error, _} = error -> error
          end
        end
      end
malloryerik commented 5 months ago

Consider "details", so a request has a takes a "contract" -- say USD/JPY or ESH4 -- and "details", which are times, dates, what to show like bid or historical volatility, etc.

This avoids easy-to-confuse words like "options" (did they mean stock options?) and even "schedule".

malloryerik commented 5 months ago

Changed to "details", but now thinking should change to "opts" and simply always refer to those params / args as "opts" even in documentation, to avoid name conflict with options the financial instruments.

"opts" seems closer to idiomatic Elixir.