Class: Utxoracle::Oracle
- Inherits:
-
Object
- Object
- Utxoracle::Oracle
- Defined in:
- lib/utxoracle/oracle.rb
Constant Summary collapse
- SECONDS_PER_DAY =
86_400
- FOUR_HOURS =
14_400
- MAINNET_PORT =
8332
- TESTNET_PORT =
18_332
- NUMBER_OF_BINS =
2401
Instance Method Summary collapse
-
#initialize(provider, log = false) ⇒ Oracle
constructor
A new instance of Oracle.
- #price(requested_date) ⇒ Object
Constructor Details
#initialize(provider, log = false) ⇒ Oracle
Returns a new instance of Oracle.
13 14 15 16 17 18 |
# File 'lib/utxoracle/oracle.rb', line 13 def initialize(provider, log = false) @provider = provider @log = log @round_usd_stencil = build_round_usd_stencil @cache = {} end |
Instance Method Details
#price(requested_date) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/utxoracle/oracle.rb', line 20 def price(requested_date) unless validate_date(requested_date) if @log puts "Invalid date.\nEarliest available: 2020-07-26.\nLatest available #{Date.today}.\nFormat: YYYY-MM-DD." end return -1 end if price_estimate = @cache[requested_date] puts "Price Estimate: $#{price_estimate.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse}" if @log return price_estimate end @requested_date = Time.parse requested_date.tr('\n', '') @cache[requested_date] = run @cache[requested_date] end |