Class: Ticker
- Inherits:
-
Object
- Object
- Ticker
- 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
- .aggregate_bars(ticker, multiplier, timespan, from, to) ⇒ Object
- .get(base, path) ⇒ Object
- .historic_trades(ticker, date, opts = {}) ⇒ Object
- .last_quote(symbol) ⇒ Object
- .last_trade(symbol) ⇒ Object
- .prev_close(symbol) ⇒ Object
Class Method Details
.aggregate_bars(ticker, multiplier, timespan, from, to) ⇒ Object
35 36 37 38 39 |
# File 'lib/polygon/tickers.rb', line 35 def 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 |