Sha256: 74b3d106c00a1cbc34f3c911de4b010bff1328090b9532b21b9bc142d5e419c3

Contents?: true

Size: 1.33 KB

Versions: 9

Compression:

Stored size: 1.33 KB

Contents

require 'httparty'

class Tda::Api
  include ::HTTParty
  base_uri 'https://api.tdameritrade.com'

  ## alias
  def self.get_quote which
    self.get_quotes( which )[0]
  end

  ## tickers = "GME"
  ## tickers = "NVDA,GME"
  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

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
iron_warbler-2.0.7.9 app/models/tda/stock.rb
iron_warbler-2.0.7.8 app/models/tda/api.rb
iron_warbler-2.0.7.7 app/models/tda/api.rb
iron_warbler-2.0.7.6 app/models/tda/api.rb
iron_warbler-2.0.7.5 app/models/tda/api.rb
iron_warbler-2.0.7.4 app/models/tda/api.rb
iron_warbler-2.0.7.3 app/models/tda/api.rb
iron_warbler-2.0.7.2 app/models/tda/api.rb
iron_warbler-2.0.7.1 app/models/tda/api.rb