Class: Tda::Stock
Class Method Summary collapse
-
.get_quote(which) ⇒ Object
alias.
-
.get_quotes(tickers) ⇒ Object
tickers = “GME” tickers = “NVDA,GME”.
Class Method Details
.get_quote(which) ⇒ Object
alias
9 10 11 |
# File 'app/models/tda/stock.rb', line 9 def self.get_quote which self.get_quotes( which )[0] end |
.get_quotes(tickers) ⇒ Object
tickers = “GME” tickers = “NVDA,GME”
15 16 17 18 19 20 21 22 23 24 25 26 27 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 |
# File 'app/models/tda/stock.rb', line 15 def self.get_quotes tickers profile = Wco::Profile.find_by email: '[email protected]' path = "/quotes" headers = { accept: 'application/json', Authorization: "Bearer #{profile.schwab_access_token}", } inns = self.get path, { headers: headers, query: { symbols: tickers } } inns = inns.parsed_response puts! inns, 'parsed response' if [ NilClass, String ].include?( inns.class ) return [] end inns.each do |k, v| inns[k] = v.deep_symbolize_keys end outs = [] inns.each do |symbol, _obj| obj = _obj[:quote] outs.push ::Iro::Priceitem.create!({ putCall: 'STOCK', symbol: symbol, ticker: symbol, bid: obj[:bidPrice], bidSize: obj[:bidSize], ask: obj[:askPrice], askSize: obj[:askSize], last: obj[:lastPrice], openPrice: obj[:openPrice], closePrice: obj[:closePrice], highPrice: obj[:highPrice], lowPrice: obj[:lowPrice], timestamp: Time.at( obj[:quoteTime]/1000 ), totalVolume: obj[:totalVolume], mark: obj[:mark], exchangeName: obj[:exchangeName], volatility: obj[:volatility], }) end return outs end |