Module: Schwab::MarketData
- Defined in:
- lib/schwab/market_data.rb
Overview
Market Data API endpoints for retrieving quotes, price history, and market information
Class Method Summary collapse
-
.get_market_hour(market_id, date: nil, client: nil) ⇒ Object
Get market hours for a single market Note: This appears to be the same endpoint as get_market_hours but with a single market instead of multiple.
-
.get_market_hours(markets, date: nil, client: nil) ⇒ Hash
Get market hours for one or more markets.
-
.get_movers(index, direction: nil, change: nil, client: nil) ⇒ Hash
Get market movers for an index.
-
.get_quote(symbol, fields: nil, client: nil) ⇒ Hash
Get detailed quote for a single symbol.
-
.get_quote_history(symbol, period_type: nil, period: nil, frequency_type: nil, frequency: nil, start_date: nil, end_date: nil, need_extended_hours: true, need_previous_close: false, client: nil) ⇒ Hash
Get price history for a symbol.
-
.get_quotes(symbols, fields: nil, indicative: false, client: nil) ⇒ Hash
Get quotes for one or more symbols.
Class Method Details
.get_market_hour(market_id, date: nil, client: nil) ⇒ Object
Get market hours for a single market Note: This appears to be the same endpoint as get_market_hours but with a single market instead of multiple
123 124 125 |
# File 'lib/schwab/market_data.rb', line 123 def get_market_hour(market_id, date: nil, client: nil) get_market_hours(market_id, date: date, client: client) end |
.get_market_hours(markets, date: nil, client: nil) ⇒ Hash
Get market hours for one or more markets
110 111 112 113 114 115 116 117 118 |
# File 'lib/schwab/market_data.rb', line 110 def get_market_hours(markets, date: nil, client: nil) client ||= default_client params = { markets: normalize_markets(markets), } params[:date] = format_date(date) if date client.get("/marketdata/v1/markets", params) end |
.get_movers(index, direction: nil, change: nil, client: nil) ⇒ Hash
Get market movers for an index
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/schwab/market_data.rb', line 91 def get_movers(index, direction: nil, change: nil, client: nil) client ||= default_client path = "/marketdata/v1/movers/#{URI.encode_www_form_component(index)}" params = {} params[:direction] = direction if direction params[:change] = change if change client.get(path, params) end |
.get_quote(symbol, fields: nil, client: nil) ⇒ Hash
Get detailed quote for a single symbol
39 40 41 42 43 44 45 46 |
# File 'lib/schwab/market_data.rb', line 39 def get_quote(symbol, fields: nil, client: nil) client ||= default_client path = "/marketdata/v1/#{URI.encode_www_form_component(symbol)}/quotes" params = {} params[:fields] = normalize_fields(fields) if fields client.get(path, params) end |
.get_quote_history(symbol, period_type: nil, period: nil, frequency_type: nil, frequency: nil, start_date: nil, end_date: nil, need_extended_hours: true, need_previous_close: false, client: nil) ⇒ Hash
Get price history for a symbol
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/schwab/market_data.rb', line 63 def get_quote_history(symbol, period_type: nil, period: nil, frequency_type: nil, frequency: nil, start_date: nil, end_date: nil, need_extended_hours: true, need_previous_close: false, client: nil) client ||= default_client path = "/marketdata/v1/pricehistory" params = { symbol: symbol } params[:periodType] = period_type if period_type params[:period] = period if period params[:frequencyType] = frequency_type if frequency_type params[:frequency] = frequency if frequency params[:startDate] = (start_date) if start_date params[:endDate] = (end_date) if end_date params[:needExtendedHoursData] = need_extended_hours params[:needPreviousClose] = need_previous_close client.get(path, params) end |
.get_quotes(symbols, fields: nil, indicative: false, client: nil) ⇒ Hash
Get quotes for one or more symbols
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/schwab/market_data.rb', line 20 def get_quotes(symbols, fields: nil, indicative: false, client: nil) client ||= default_client params = { symbols: normalize_symbols(symbols), indicative: indicative, } params[:fields] = normalize_fields(fields) if fields client.get("/marketdata/v1/quotes", params) end |