Class: Ticker

Inherits:
Object
  • Object
show all
Defined in:
lib/polygon/tickers.rb

Overview

Indices, Crypto, FX, and Stocks/Equities

Constant Summary collapse

DOMAIN =
'https://api.polygon.io'
BASE_URL =
'https://api.polygon.io/v1'

Class Method Summary collapse

Class Method Details

.aggregate_bars(ticker, multiplier, timespan, from, to) ⇒ Object



35
36
37
38
39
# File 'lib/polygon/tickers.rb', line 35

def aggregate_bars ticker, multiplier, timespan, from, to
  r = get DOMAIN, "/v2/aggs/ticker/#{ticker}/range/#{multiplier}/#{timespan}/#{from}/#{to}?apiKey=#{Config.keys['POLYGON']}"
  #binding.pry
  r['status'] == 'OK' ? r : nil
end

.get(base, path) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/polygon/tickers.rb', line 7

def get base, path
  uri = URI(base + path)

  req = Net::HTTP::Get.new(uri)

  res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) {|http|
    http.request(req)
  }

    JSON.parse res.body
end

.historic_trades(ticker, date, opts = {}) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/polygon/tickers.rb', line 41

def historic_trades ticker, date, opts={}
  qp = opts.map {|k,v| "#{k}=#{v}"}.join '&'
  qp = "&#{qp}" if qp

  r = get DOMAIN, "/v2/ticks/stocks/trades/#{ticker}/#{date}?apiKey=#{Config.keys['POLYGON']}#{qp}"
  #binding.pry
  r['success'] == true ? r : nil
end

.last_quote(symbol) ⇒ Object



24
25
26
27
# File 'lib/polygon/tickers.rb', line 24

def last_quote symbol
  r = get BASE_URL, "/last_quote/stocks/#{symbol}?apiKey=#{Config.keys['POLYGON']}"
  r['status'] == 'success' ? r : nil
end

.last_trade(symbol) ⇒ Object



19
20
21
22
# File 'lib/polygon/tickers.rb', line 19

def last_trade symbol
  r = get BASE_URL, "/last/stocks/#{symbol}?apiKey=#{Config.keys['POLYGON']}"
  r['status'] == 'success' ? r : nil
end

.prev_close(symbol) ⇒ Object



29
30
31
32
33
# File 'lib/polygon/tickers.rb', line 29

def prev_close symbol
  r = get DOMAIN, "/v2/aggs/ticker/#{symbol}/prev?apiKey=#{Config.keys['POLYGON']}"
  #binding.pry
  r['status'] == 'OK' ? r : nil
end