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
- .schwab_sync ⇒ Object
- .schwab_sync_exec ⇒ Object
Class Method Details
.get_coins ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/iron_warbler.rb', line 17 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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/iron_warbler.rb', line 35 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
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 |
# File 'lib/iron_warbler.rb', line 64 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
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 126 127 128 129 130 131 132 |
# File 'lib/iron_warbler.rb', line 96 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
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 164 165 166 167 168 169 170 |
# File 'lib/iron_warbler.rb', line 134 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 |
.schwab_sync ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/iron_warbler.rb', line 172 def self.schwab_sync profile = Wco::Profile.find_by email: 'piousbox@gmail.com' out = Schwab.post( "https://api.schwabapi.com/v1/oauth/token", { headers: { "Content-Type": "application/x-www-form-urlencoded" }, basic_auth: { username: SCHWAB_DATA[:key], password: SCHWAB_DATA[:secret] }, body: { grant_type: 'refresh_token', refresh_token: profile.schwab_refresh_token }, }) out = out.parsed_response puts! out, '#schwab_sync' attrs = { schwab_access_token: out['access_token'], schwab_refresh_token: out['refresh_token'], schwab_id_token: out['id_token'], } # puts! attrs, 'attrs' if attrs[:schwab_refresh_token] profile.update(attrs) profile.save! return attrs else return false end end |
.schwab_sync_exec ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/iron_warbler.rb', line 201 def self.schwab_sync_exec profile = Wco::Profile.find_by email: 'piousbox@gmail.com' out = Schwab.post( "https://api.schwabapi.com/v1/oauth/token", { headers: { "Content-Type": "application/x-www-form-urlencoded" }, basic_auth: { username: SCHWAB_EXEC[:key], password: SCHWAB_EXEC[:secret] }, body: { grant_type: 'refresh_token', refresh_token: profile.schwab_exec_refresh_token }, }) out = out.parsed_response puts! out, '#schwab_sync_exec' attrs = { schwab_exec_access_token: out['access_token'], schwab_exec_refresh_token: out['refresh_token'], schwab_exec_id_token: out['id_token'], } # puts! attrs, 'attrs' if attrs[:schwab_exec_refresh_token] profile.update(attrs) profile.save! return attrs else return false end end |