Class: Iro::Iro
- Inherits:
-
Object
- Object
- Iro::Iro
- Defined in:
- lib/iron_warbler.rb
Class Method Summary collapse
- .get_coins ⇒ Object
- .get_currencies ⇒ Object
- .get_treasuries ⇒ Object
- .import_1990_2023_treasuries ⇒ Object
- .import_2024_treasuries ⇒ Object
Class Method Details
.get_coins ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/iron_warbler.rb', line 10 def self.get_coins out = HTTParty.get( "https://pro-api.coinmarketcap.com/v2/cryptocurrency/quotes/latest?slug=bitcoin,ethereum", { headers: { 'X-CMC_PRO_API_KEY' => COINMARKETCAP[:key] }, }) out = out.parsed_response.deep_symbolize_keys out[:data].each do |k, item| opi = Iro::Datapoint.new({ date: Time.now.to_date, kind: Iro::Datapoint::KIND_CRYPTO, symbol: item[:symbol], quote_at: item[:quote][:USD][:last_updated], value: item[:quote][:USD][:price], volume: item[:quote][:USD][:volume_24h], }) opi.save! end end |
.get_currencies ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/iron_warbler.rb', line 28 def self.get_currencies out = HTTParty.get "https://api.currencyfreaks.com/v2.0/rates/latest?apikey=#{CURRENCYFREAKS[:key]}&symbols=COP,EUR,JPY" out = out.parsed_response.deep_symbolize_keys! out[:rates].each do |currency, value| # opi = OPI.new({ # putCall: 'CURRENCY', # symbol: currency, # ticker: currency, # exchangeName: 'currencyfreaks', # mark: value, # lastPrice: value, # timestamp: Time.now.to_date, # }) # opi.save! datapoint = Iro::Datapoint.new({ date: Time.now.to_date, quote_at: Time.now, kind: Iro::Datapoint::KIND_CURRENCY, symbol: currency, value: value, }) datapoint.save! print '^' end end |
.get_treasuries ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/iron_warbler.rb', line 57 def self.get_treasuries response = HTTParty.get( "https://home.treasury.gov/resource-center/data-chart-center/interest-rates/daily-treasury-rates.csv/all/#{Time.now.strftime('%Y%m')}?type=daily_treasury_yield_curve&field_tdr_date_value_month=#{Time.now.strftime('%Y%m')}&page&_format=csv") outs = CSV.parse( response.body, { headers: true }) out = outs[0] date = Date.strptime(out['Date'], '%m/%d/%Y') { '1 Mo' => Iro::Datapoint::SYMBOL_T1MO, '2 Mo' => Iro::Datapoint::SYMBOL_T2MO, '3 Mo' => Iro::Datapoint::SYMBOL_T3MO, '4 Mo' => Iro::Datapoint::SYMBOL_T4MO, '6 Mo' => Iro::Datapoint::SYMBOL_T6MO, '1 Yr' => Iro::Datapoint::SYMBOL_T1YR, '2 Yr' => Iro::Datapoint::SYMBOL_T2YR, '3 Yr' => Iro::Datapoint::SYMBOL_T3YR, '5 Yr' => Iro::Datapoint::SYMBOL_T5YR, '7 Yr' => Iro::Datapoint::SYMBOL_T7YR, '10 Yr' => Iro::Datapoint::SYMBOL_T10YR, '20 Yr' => Iro::Datapoint::SYMBOL_T20YR, '30 Yr' => Iro::Datapoint::SYMBOL_T30YR, }.each do |k, v| opi = Iro::Datapoint.new({ date: date, quote_at: date, kind: Iro::Datapoint::KIND_TREASURY, symbol: v, value: out[k], }) opi.save! print '^' end end |
.import_1990_2023_treasuries ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/iron_warbler.rb', line 89 def self.import_1990_2023_treasuries outs = CSV.parse( File.read( Rails.root.join('data', 'treasuries', '1990..23 daily-treasury-rates.csv') ), { headers: true }) outs.each do |out| date = Date.strptime(out['Date'], '%m/%d/%y') { '1 Mo' => Iro::Datapoint::SYMBOL_T1MO, '2 Mo' => Iro::Datapoint::SYMBOL_T2MO, '3 Mo' => Iro::Datapoint::SYMBOL_T3MO, '4 Mo' => Iro::Datapoint::SYMBOL_T4MO, '6 Mo' => Iro::Datapoint::SYMBOL_T6MO, '1 Yr' => Iro::Datapoint::SYMBOL_T1YR, '2 Yr' => Iro::Datapoint::SYMBOL_T2YR, '3 Yr' => Iro::Datapoint::SYMBOL_T3YR, '5 Yr' => Iro::Datapoint::SYMBOL_T5YR, '7 Yr' => Iro::Datapoint::SYMBOL_T7YR, '10 Yr' => Iro::Datapoint::SYMBOL_T10YR, '20 Yr' => Iro::Datapoint::SYMBOL_T20YR, '30 Yr' => Iro::Datapoint::SYMBOL_T30YR, }.each do |k, v| if out[k] opi = Iro::Datapoint.new({ date: date, quote_at: date, kind: Iro::Datapoint::KIND_TREASURY, symbol: v, value: out[k], }) begin opi.save! rescue Mongoid::Errors::Validations => err puts! err, 'err' end print '^' end end end end |
.import_2024_treasuries ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/iron_warbler.rb', line 127 def self.import_2024_treasuries outs = CSV.parse( File.read( Rails.root.join('data', 'treasuries', '2024 daily-treasury-rates.csv') ), { headers: true }) outs.each do |out| date = Date.strptime(out['Date'], '%m/%d/%Y') { '1 Mo' => Iro::Datapoint::SYMBOL_T1MO, '2 Mo' => Iro::Datapoint::SYMBOL_T2MO, '3 Mo' => Iro::Datapoint::SYMBOL_T3MO, '4 Mo' => Iro::Datapoint::SYMBOL_T4MO, '6 Mo' => Iro::Datapoint::SYMBOL_T6MO, '1 Yr' => Iro::Datapoint::SYMBOL_T1YR, '2 Yr' => Iro::Datapoint::SYMBOL_T2YR, '3 Yr' => Iro::Datapoint::SYMBOL_T3YR, '5 Yr' => Iro::Datapoint::SYMBOL_T5YR, '7 Yr' => Iro::Datapoint::SYMBOL_T7YR, '10 Yr' => Iro::Datapoint::SYMBOL_T10YR, '20 Yr' => Iro::Datapoint::SYMBOL_T20YR, '30 Yr' => Iro::Datapoint::SYMBOL_T30YR, }.each do |k, v| if out[k] opi = Iro::Datapoint.new({ date: date, quote_at: date, kind: Iro::Datapoint::KIND_TREASURY, symbol: v, value: out[k], }) begin opi.save! rescue Mongoid::Errors::Validations => err puts! err, 'err' end print '^' end end end end |