Class: SchwabRb::DataObjects::MarketHours::MarketInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/schwab_rb/data_objects/market_hours.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ MarketInfo

Returns a new instance of MarketInfo.



125
126
127
128
129
130
131
132
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 125

def initialize(data)
  @date = data["date"]
  @market_type = data["marketType"]
  @product = data["product"]
  @product_name = data["productName"]
  @is_open = data["isOpen"]
  @session_hours = data["sessionHours"] ? SessionHours.new(data["sessionHours"]) : nil
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



123
124
125
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 123

def date
  @date
end

#is_openObject (readonly)

Returns the value of attribute is_open.



123
124
125
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 123

def is_open
  @is_open
end

#market_typeObject (readonly)

Returns the value of attribute market_type.



123
124
125
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 123

def market_type
  @market_type
end

#productObject (readonly)

Returns the value of attribute product.



123
124
125
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 123

def product
  @product
end

#product_nameObject (readonly)

Returns the value of attribute product_name.



123
124
125
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 123

def product_name
  @product_name
end

#session_hoursObject (readonly)

Returns the value of attribute session_hours.



123
124
125
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 123

def session_hours
  @session_hours
end

Instance Method Details

#bond?Boolean

Returns:

  • (Boolean)


196
197
198
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 196

def bond?
  @market_type == "BOND"
end

#closed?Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 150

def closed?
  !open?
end

#date_objectObject



154
155
156
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 154

def date_object
  Date.parse(@date) if @date
end

#equity?Boolean

Returns:

  • (Boolean)


180
181
182
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 180

def equity?
  @market_type == "EQUITY"
end

#forex?Boolean

Returns:

  • (Boolean)


192
193
194
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 192

def forex?
  @market_type == "FOREX"
end

#future?Boolean

Returns:

  • (Boolean)


188
189
190
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 188

def future?
  @market_type == "FUTURE"
end

#has_session_hours?Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 158

def has_session_hours?
  !@session_hours.nil?
end

#open?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 146

def open?
  @is_open == true
end

#option?Boolean

Returns:

  • (Boolean)


184
185
186
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 184

def option?
  @market_type == "OPTION"
end

#post_market_hoursObject



174
175
176
177
178
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 174

def post_market_hours
  return nil unless @session_hours

  @session_hours.post_market
end

#pre_market_hoursObject



168
169
170
171
172
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 168

def pre_market_hours
  return nil unless @session_hours

  @session_hours.pre_market
end

#regular_market_hoursObject



162
163
164
165
166
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 162

def regular_market_hours
  return nil unless @session_hours

  @session_hours.regular_market
end

#to_hObject



134
135
136
137
138
139
140
141
142
143
144
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 134

def to_h
  result = {
    "date" => @date,
    "marketType" => @market_type,
    "product" => @product,
    "isOpen" => @is_open
  }
  result["productName"] = @product_name if @product_name
  result["sessionHours"] = @session_hours.to_h if @session_hours
  result
end