Module: Polygon::Api::Endpoints

Included in:
Client
Defined in:
lib/polygon/api/endpoints.rb

Instance Method Summary collapse

Instance Method Details

#aggregates(symbol:, multiplier:, timespan:, from:, to:, options: {}) ⇒ Object



21
22
23
# File 'lib/polygon/api/endpoints.rb', line 21

def aggregates(symbol:, multiplier:, timespan:, from:, to:, options: {})
  get("/v2/aggs/ticker/#{symbol}/range/#{multiplier}/#{timespan}/#{from}/#{to}", { apiKey: api_key }.merge(options))
end

#all_trades(symbol:, date:, options: {}, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/polygon/api/endpoints.rb', line 10

def all_trades(symbol:, date:, options: {}, &block)
  last_trade = nil
  loop do
    offset_options = last_trade ? options.merge(timestamp: last_trade&.dig(:t)) : options
    trades = trades(symbol: symbol, date: date, options: offset_options)[:results]
    trades.each { |trade| block.call(trade) }
    last_trade = trades.last
    break if trades.size < (options[:limit] || 50_000)
  end
end

#trades(symbol:, date:, options: {}) ⇒ Object



6
7
8
# File 'lib/polygon/api/endpoints.rb', line 6

def trades(symbol:, date:, options: {})
  get("/v2/ticks/stocks/trades/#{symbol}/#{date}", { apiKey: api_key }.merge(options))
end