Sha256: 82727c93a96aed2c375da6086736325eb7b5736db93254a336f6ce8a20cbd25f

Contents?: true

Size: 1.58 KB

Versions: 15

Compression:

Stored size: 1.58 KB

Contents

require 'httparty'

class Tda::Stock
  include ::HTTParty
  base_uri 'https://api.schwabapi.com/marketdata/v1'

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

  ## tickers = "GME"
  ## tickers = "NVDA,GME"
  def self.get_quotes tickers
    profile = Wco::Profile.find_by email: 'piousbox@gmail.com'

    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

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
iron_warbler-2.0.7.43 app/models/tda/stock.rb
iron_warbler-2.0.7.42 app/models/tda/stock.rb
iron_warbler-2.0.7.41 app/models/tda/stock.rb
iron_warbler-2.0.7.40 app/models/tda/stock.rb
iron_warbler-2.0.7.39 app/models/tda/stock.rb
iron_warbler-2.0.7.38 app/models/tda/stock.rb
iron_warbler-2.0.7.37 app/models/tda/stock.rb
iron_warbler-2.0.7.36 app/models/tda/stock.rb
iron_warbler-2.0.7.35 app/models/tda/stock.rb
iron_warbler-2.0.7.34 app/models/tda/stock.rb
iron_warbler-2.0.7.33 app/models/tda/stock.rb
iron_warbler-2.0.7.32 app/models/tda/stock.rb
iron_warbler-2.0.7.31 app/models/tda/stock.rb
iron_warbler-2.0.7.30 app/models/tda/stock.rb
iron_warbler-2.0.7.29 app/models/tda/stock.rb