Class: Finexclub::Chart
- Inherits:
-
Object
- Object
- Finexclub::Chart
- Includes:
- Document
- Defined in:
- lib/finexclub/chart.rb
Constant Summary collapse
- SYMBOLS =
%w(chfjpy eurchf audusd audcad eurnzd nzdusd gbpchf nzdcad usdcad cadjpy audjpy euraud gbpnzd nzdjpy eurusd usdjpy eurcad cadchf gbpaud gbpusd audchf eurjpy gbpcad usdchf nzdchf audnzd eurgbp gbpjpy)
Instance Attribute Summary collapse
-
#core ⇒ Object
readonly
Returns the value of attribute core.
-
#indicators ⇒ Object
Returns the value of attribute indicators.
Class Method Summary collapse
- .add_handler_for(indicator, klass) ⇒ Object
- .build_new(core, symbol, tf, time) ⇒ Object
- .handler_for(indicator) ⇒ Object
- .indicator_handler(indicator, indicator_handler_class) ⇒ Object
- .timeframe_range(tf, time) ⇒ Object
Instance Method Summary collapse
- #handler_for(indicator) ⇒ Object
-
#initialize(core) ⇒ Chart
constructor
A new instance of Chart.
Methods included from Document
Constructor Details
#initialize(core) ⇒ Chart
Returns a new instance of Chart.
18 19 20 21 |
# File 'lib/finexclub/chart.rb', line 18 def initialize(core) @core = core @indicators = {} end |
Instance Attribute Details
#core ⇒ Object (readonly)
Returns the value of attribute core.
13 14 15 |
# File 'lib/finexclub/chart.rb', line 13 def core @core end |
#indicators ⇒ Object
Returns the value of attribute indicators.
14 15 16 |
# File 'lib/finexclub/chart.rb', line 14 def indicators @indicators end |
Class Method Details
.add_handler_for(indicator, klass) ⇒ Object
70 71 72 73 |
# File 'lib/finexclub/chart.rb', line 70 def self.add_handler_for(indicator, klass) @handlers ||= {} @handlers[indicator.to_s] = klass end |
.build_new(core, symbol, tf, time) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/finexclub/chart.rb', line 42 def self.build_new(core, symbol, tf, time) tf_hash = self.timeframe_range(tf, time) c = Chart.new(core) c.updated= time.to_i c.symbol= symbol c.timeframe = tf c.starts = tf_hash[:starts] c.expires = tf_hash[:expires] c end |
.handler_for(indicator) ⇒ Object
75 76 77 78 |
# File 'lib/finexclub/chart.rb', line 75 def self.handler_for(indicator) @handlers ||= {} @handlers[indicator.to_s] end |
.indicator_handler(indicator, indicator_handler_class) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/finexclub/chart.rb', line 54 def self.indicator_handler(indicator, indicator_handler_class) add_handler_for(indicator, indicator_handler_class) #define_method("#{indicator}=") do |doc| #@indicator_docs[indicator] = doc #end define_method("#{indicator}") do return nil unless doc = indicators[indicator.to_s] indicator_obj = handler_for(indicator.to_s).new(core) indicator_obj.build(doc) indicator_obj end end |
.timeframe_range(tf, time) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/finexclub/chart.rb', line 27 def self.timeframe_range(tf, time) time = time.is_a?(Time) ? time : Time.at(time).utc delta = case tf when 'h1', :h1 then 1 when 'h4', :h4 then 4 when 'd1', :d1 then 24 else 1 end starts = Time.utc(time.year, time.month, time.day, (time.hour/delta)*delta, 0) expires = starts + delta*60*60 { :starts => starts.to_i, :expires => expires.to_i } end |
Instance Method Details
#handler_for(indicator) ⇒ Object
23 24 25 |
# File 'lib/finexclub/chart.rb', line 23 def handler_for(indicator) self.class.handler_for(indicator) end |