<commit_before>module IGMarkets
  module LoginMethods
    # Logs into the IG Markets Dealing Platform, either the production platform or the demo platform.
    #
    # @param username [String] the login username
    # @param password [String] the login password
    # @param api_key [String] the login API key
    # @param platform [:production, :demo] the platform to log into
    def login(username, password, api_key, platform = :demo)
      session.login username, password, api_key, platform
    end

    # Logs out of the IG Markets Dealing Platform
    def logout
      session.logout
    end
  end

  module AccountMethods
    def accounts
      gather 'accounts', :accounts, Account
    end

    def activities_in_date_range(from_date, to_date = Date.today)
      from_date = format_activity_date(from_date)
      to_date = format_activity_date(to_date)

      gather "history/activity/#{from_date}/#{to_date}", :activities, AccountActivity
    end

    def activities_in_recent_period(milliseconds)
      gather "history/activity/#{milliseconds.to_i}", :activities, AccountActivity
    end

    def transactions_in_date_range(from_date, to_date = Date.today, transaction_type = :all)
      Validate.transaction_type! transaction_type

      from_date = format_activity_date(from_date)
      to_date = format_activity_date(to_date)

      gather "history/transactions/#{transaction_type.to_s.upcase}/#{from_date}/#{to_date}", :transactions, Transaction
    end

    def transactions_in_recent_period(milliseconds, transaction_type = :all)
      Validate.transaction_type! transaction_type

      gather "history/transactions/#{transaction_type.to_s.upcase}/#{milliseconds}", :transactions, Transaction
    end

    private

    def format_activity_date(d)
      d.strftime '%d-%m-%Y'
    end
  end

  module DealingMethods
    def positions
      session.gather 'positions', :positions, Session::API_VERSION_2 do |attributes|
        Position.new merge_market_attributes(attributes, :position)
      end
    end

    def position(deal_id)
      result = session.get("positions/#{deal_id}", Session::API_VERSION_2)

      Position.new result.fetch(:position).merge(market: result.fetch(:market))
    end

    def sprint_market_positions
      gather 'positions/sprintmarkets', :sprint_market_positions, SprintMarketPosition
    end

    def working_orders
      session.gather 'workingorders', :working_orders, Session::API_VERSION_2 do |attributes|
        WorkingOrder.new merge_market_attributes(attributes, :working_order_data)
      end
    end

    private

    def merge_market_attributes(attributes, base_key)
      market_attributes = attributes[:market] || attributes[:market_data]

      fail 'no market data in attributes' unless market_attributes

      attributes.fetch(base_key).merge(market_attributes)
    end
  end

  module MarketMethods
    def market_hierarchy(node_id = nil)
      url = ['marketnavigation', node_id].compact.join('')

      result = session.get(url)

      {
        markets: (result.fetch(:markets) || []).map { |attributes| Market.new attributes },
        nodes:   (result.fetch(:nodes) || []).map   { |attributes| MarketHierarchyNode.new attributes }
      }
    end

    def market(epic)
      markets(epic)[0]
    end

    def markets(*epics)
      fail ArgumentError, 'at least one epic must be specified' if epics.empty?

      Validate.epic! epics

      result = session.get("markets?epics=#{epics.join(',')}")

      result.fetch(:market_details).map do |attributes|
        {<commit_msg>Fixed IGMarkets::DealingPlatform<commit_after>module IGMarkets
  module LoginMethods
    # Logs into the IG Markets Dealing Platform, either the production platform or the demo platform.
    #
    # @param username [String] the login username
    # @param password [String] the login password
    # @param api_key [String] the login API key
    # @param platform [:production, :demo] the platform to log into
    def login(username, password, api_key, platform = :demo)
      session.login username, password, api_key, platform
    end

    # Logs out of the IG Markets Dealing Platform
    def logout
      session.logout
    end
  end

  module AccountMethods
    def accounts
      gather 'accounts', :accounts, Account
    end

    def activities_in_date_range(from_date, to_date = Date.today)
      from_date = format_activity_date(from_date)
      to_date = format_activity_date(to_date)

      gather "history/activity/#{from_date}/#{to_date}", :activities, AccountActivity
    end

    def activities_in_recent_period(milliseconds)
      gather "history/activity/#{milliseconds.to_i}", :activities, AccountActivity
    end

    def transactions_in_date_range(from_date, to_date = Date.today, transaction_type = :all)
      Validate.transaction_type! transaction_type

      from_date = format_activity_date(from_date)
      to_date = format_activity_date(to_date)

      gather "history/transactions/#{transaction_type.to_s.upcase}/#{from_date}/#{to_date}", :transactions, Transaction
    end

    def transactions_in_recent_period(milliseconds, transaction_type = :all)
      Validate.transaction_type! transaction_type

      gather "history/transactions/#{transaction_type.to_s.upcase}/#{milliseconds}", :transactions, Transaction
    end

    private

    def format_activity_date(d)
      d.strftime '%d-%m-%Y'
    end
  end

  module DealingMethods
    def positions
      session.gather 'positions', :positions, Session::API_VERSION_2 do |attributes|
        Position.new merge_market_attributes(attributes, :position)
      end
    end

    def position(deal_id)
      result = session.get("positions/#{deal_id}", Session::API_VERSION_2)

      Position.new result.fetch(:position).merge(market: result.fetch(:market))
    end

    def sprint_market_positions
      gather 'positions/sprintmarkets', :sprint_market_positions, SprintMarketPosition
    end

    def working_orders
      session.gather 'workingorders', :working_orders, Session::API_VERSION_2 do |attributes|
        WorkingOrder.new merge_market_attributes(attributes, :working_order_data)
      end
    end

    private

    def merge_market_attributes(attributes, base_key)
      market_attributes = attributes[:market] || attributes[:market_data]

      fail 'no market data in attributes' unless market_attributes

      attributes.fetch(base_key).merge(market_attributes)
    end
  end

  module MarketMethods
    def market_hierarchy(node_id = nil)
      url = ['marketnavigation', node_id].compact.join('/')

      result = session.get(url)

      {
        markets: (result.fetch(:markets) || []).map { |attributes| Market.new attributes },
        nodes:   (result.fetch(:nodes) || []).map   { |attributes| MarketHierarchyNode.new attributes }
      }
    end

    def market(epic)
      markets(epic)[0]
    end

    def markets(*epics)
      fail ArgumentError, 'at least one epic must be specified' if epics.empty?

      Validate.epic! epics

      result = session.get("markets?epics=#{epics.join(',')}")

      result.fetch(:market_details).map do |attributes|
        {
{'fraction_non_alphanumeric': 0.093785151856018, 'fraction_numerical': 0.0011248593925759281, 'mean_word_length': 3.5742765273311896, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '953911', 'n_tokens_mistral': 2111, 'n_tokens_neox': 2033, 'n_words': 491}