Class: XRBP::Model::Parsers::Quote
- Inherits:
-
PluginBase
- Object
- PluginBase
- XRBP::Model::Parsers::Quote
- Defined in:
- lib/xrbp/model/parsers/quote.rb
Overview
Market quotes data parser
Instance Attribute Summary
Attributes inherited from PluginBase
Instance Method Summary collapse
Methods inherited from PluginBase
Constructor Details
This class inherits a constructor from XRBP::PluginBase
Instance Method Details
#parse_result(res, req) ⇒ Object
13 14 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 |
# File 'lib/xrbp/model/parsers/quote.rb', line 13 def parse_result(res, req) return [] unless res && res != '' j = JSON.parse(res) return [] unless j["result"] j["result"].collect { |p, quotes| next nil unless quotes quotes.collect { |q| t = q[0] o = q[1] h = q[2] l = q[3] c = q[4] vol = q[5] # discard invalid data # (some exchanges periodically # return '0's for some timestamps, # perhaps for periods with no trades?) next nil if o.zero? || h.zero? || l.zero? || c.zero? || vol.zero? {:timestamp => Time.at(t).to_datetime, :open => o, :high => h, :low => l, :close => c, :volume => vol} } }.flatten.compact end |
#parser_priority ⇒ Object
9 10 11 |
# File 'lib/xrbp/model/parsers/quote.rb', line 9 def parser_priority 0 end |