Class: Tda::Api

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
app/models/tda/stock.rb

Class Method Summary collapse

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
# File 'app/models/tda/stock.rb', line 15

def self.get_quotes tickers
  path = "/v1/marketdata/quotes"
  inns = self.get path, { query: { apikey: ::TD_AMERITRADE[:apiKey], symbol: tickers } }
  inns = inns.parsed_response
  inns.each do |k, v|
    inns[k] = v.deep_symbolize_keys
  end
  outs = []
  inns.each do |symbol, obj|
    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],
      quoteTimeInLong: obj[:quoteTimeInLong],
      timestamp:       Time.at( obj[:quoteTimeInLong]/1000 ),
      totalVolume:     obj[:totalVolume],
      mark:            obj[:mark],
      exchangeName:    obj[:exchangeName],
      volatility:      obj[:volatility],
    })
  end
  return outs
end