Class: Iro::Iro
- Inherits:
-
Object
- Object
- Iro::Iro
- Defined in:
- lib/iron_warbler.rb
Class Method Summary collapse
- .get_coins ⇒ 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_treasuries ⇒ 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 56 57 58 |
# File 'lib/iron_warbler.rb', line 28 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
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 88 89 90 91 92 93 94 95 96 |
# File 'lib/iron_warbler.rb', line 60 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
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 126 127 128 129 130 131 132 133 134 |
# File 'lib/iron_warbler.rb', line 98 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 |