Class: Polygonio::Rest::Forex

Inherits:
PolygonRestHandler show all
Defined in:
lib/polygonio/rest/api/forex.rb

Defined Under Namespace

Classes: CurrencyConversionResponse, FullSnapshotResponse, HistoricTicksResponse, LastQuoteResponse, SnapshotGainersLosersResponse, SnapshotTicker

Instance Attribute Summary

Attributes inherited from PolygonRestHandler

#client

Instance Method Summary collapse

Methods inherited from PolygonRestHandler

#initialize

Constructor Details

This class inherits a constructor from Polygonio::Rest::PolygonRestHandler

Instance Method Details

#convert_currency(from, to, amount, precision = 2) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/polygonio/rest/api/forex.rb', line 45

def convert_currency(from, to, amount, precision = 2)
  from = Types::String[from]
  to = Types::String[to]
  amount = Types::Coercible::Decimal[amount]
  precision = Types::Integer[precision]
  opts = { amount: amount, precision: precision }

  res = client.request.get("/v1/conversion/#{from}/#{to}", opts)
  CurrencyConversionResponse[res.body]
end

#full_snapshotObject



115
116
117
118
# File 'lib/polygonio/rest/api/forex.rb', line 115

def full_snapshot
  res = client.request.get("/v2/snapshot/locale/global/markets/forex/tickers")
  FullSnapshotResponse[res.body]
end

#historic_ticks(from, to, date, opts = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/polygonio/rest/api/forex.rb', line 21

def historic_ticks(from, to, date, opts = {})
  from = Types::String[from]
  to = Types::String[to]
  date = Types::JSON::Date[date]
  opts = PagingParameters[opts]

  res = client.request.get("/v1/historic/forex/#{from}/#{to}/#{date}", opts.to_h)
  HistoricTicksResponse[res.body]
end

#last_quote(from, to) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/polygonio/rest/api/forex.rb', line 67

def last_quote(from, to)
  from = Types::String[from]
  to = Types::String[to]

  res = client.request.get("/v1/last_quote/currencies/#{from}/#{to}")
  LastQuoteResponse[res.body]
end

#snapshot_gainers_losers(direction) ⇒ Object



122
123
124
125
126
# File 'lib/polygonio/rest/api/forex.rb', line 122

def snapshot_gainers_losers(direction)
  direction = Types::Coercible::String.enum("gainers", "losers")[direction]
  res = client.request.get("/v2/snapshot/locale/global/markets/forex/#{direction}")
  SnapshotGainersLosersResponse[res.body]
end