finexclub 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/finexclub.gemspec +1 -1
- data/lib/finexclub/chart.rb +18 -2
- data/spec/finexclub/chart_spec.rb +50 -13
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.2
|
data/finexclub.gemspec
CHANGED
data/lib/finexclub/chart.rb
CHANGED
@@ -27,12 +27,19 @@ module Finexclub
|
|
27
27
|
def self.build_new(core, symbol, tf, time)
|
28
28
|
time = time.is_a?(Time) ? time : Time.at(time).utc
|
29
29
|
|
30
|
+
delta = self.timeframe_delta(tf)
|
31
|
+
starts = Time.utc(time.year, time.month, time.day, (time.hour/delta)*delta, 0)
|
32
|
+
expires = Chronic.parse("#{delta} hours from now", :now => starts)
|
33
|
+
|
34
|
+
#c.starts = Time.utc(time.year, time.month, time.day, time.hour, 0).to_i
|
35
|
+
#c.expires = c.starts + 1*60*60
|
36
|
+
|
30
37
|
c = Chart.new(core)
|
31
38
|
c.updated= time.to_i
|
32
39
|
c.symbol= symbol
|
33
40
|
c.timeframe = tf
|
34
|
-
c.starts =
|
35
|
-
c.expires =
|
41
|
+
c.starts = starts.to_i
|
42
|
+
c.expires = expires.to_i
|
36
43
|
c
|
37
44
|
end
|
38
45
|
|
@@ -66,5 +73,14 @@ module Finexclub
|
|
66
73
|
indicator_handler :zeta, Finexclub::Signals::Zeta
|
67
74
|
indicator_handler :octopus, Finexclub::Signals::Octopus
|
68
75
|
indicator_handler :prognosis, Finexclub::Signals::Prognosis
|
76
|
+
|
77
|
+
def self.timeframe_delta(tf)
|
78
|
+
case tf
|
79
|
+
when 'h1', :h1 then 1
|
80
|
+
when 'h4', :h4 then 4
|
81
|
+
when 'd1', :d1 then 24
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
69
85
|
end
|
70
86
|
end
|
@@ -88,22 +88,59 @@ describe 'Finexclub::Chart' do
|
|
88
88
|
end
|
89
89
|
|
90
90
|
describe 'Chart.build_new(symbol, tf, time)' do
|
91
|
-
|
92
|
-
|
93
|
-
|
91
|
+
describe 'h1 timeframe' do
|
92
|
+
it 'should return valid new (unsaved) chart instance' do
|
93
|
+
chart = Finexclub::Chart.build_new(@core, 'eurusd', 'h1', Time.utc(2010, 12, 27, 11, 30).to_i)
|
94
|
+
chart._id.should == nil
|
95
|
+
chart.symbol.should == 'eurusd'
|
96
|
+
chart.timeframe.should == 'h1'
|
97
|
+
chart.starts.should == Time.utc(2010, 12, 27, 11, 0).to_i
|
98
|
+
chart.expires.should == Time.utc(2010, 12, 27, 12, 0).to_i
|
99
|
+
chart.updated.should == Time.utc(2010, 12, 27, 11, 30).to_i
|
100
|
+
chart.indicators.should == {}
|
101
|
+
end
|
94
102
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
@chart.timeframe.should == 'h1'
|
99
|
-
@chart.starts.should == Time.utc(2010, 12, 27, 11, 0).to_i
|
100
|
-
@chart.expires.should == Time.utc(2010, 12, 27, 12, 0).to_i
|
101
|
-
@chart.updated.should == Time.utc(2010, 12, 27, 11, 30).to_i
|
102
|
-
@chart.indicators.should == {}
|
103
|
+
it 'should build valid chart given time as Time object' do
|
104
|
+
Finexclub::Chart.build_new(@core, 'eurusd', 'h1', Time.utc(2010, 12, 27, 11, 30)).starts.should == Time.utc(2010, 12, 27, 11, 0).to_i
|
105
|
+
end
|
103
106
|
end
|
104
107
|
|
105
|
-
|
106
|
-
|
108
|
+
{
|
109
|
+
:h1 => {
|
110
|
+
[2010, 12, 27, 00, 00] => [[2010, 12, 27, 00, 00], [2010, 12, 27, 01, 00]],
|
111
|
+
[2010, 12, 27, 03, 07] => [[2010, 12, 27, 03, 00], [2010, 12, 27, 04, 00]],
|
112
|
+
[2010, 12, 27, 16, 37] => [[2010, 12, 27, 16, 00], [2010, 12, 27, 17, 00]],
|
113
|
+
[2010, 12, 27, 23, 59] => [[2010, 12, 27, 23, 00], [2010, 12, 28, 00, 00]]
|
114
|
+
},
|
115
|
+
:h4 => {
|
116
|
+
[2010, 12, 27, 00, 00] => [[2010, 12, 27, 00, 00], [2010, 12, 27, 04, 00]],
|
117
|
+
[2010, 12, 27, 03, 07] => [[2010, 12, 27, 00, 00], [2010, 12, 27, 04, 00]],
|
118
|
+
[2010, 12, 27, 16, 37] => [[2010, 12, 27, 16, 00], [2010, 12, 27, 20, 00]],
|
119
|
+
[2010, 12, 27, 23, 59] => [[2010, 12, 27, 20, 00], [2010, 12, 28, 00, 00]]
|
120
|
+
},
|
121
|
+
:d1 => {
|
122
|
+
[2010, 12, 27, 00, 00] => [[2010, 12, 27, 00, 00], [2010, 12, 28, 00, 00]],
|
123
|
+
[2010, 12, 27, 03, 07] => [[2010, 12, 27, 00, 00], [2010, 12, 28, 00, 00]],
|
124
|
+
[2010, 12, 27, 16, 37] => [[2010, 12, 27, 00, 00], [2010, 12, 28, 00, 00]],
|
125
|
+
[2010, 12, 27, 23, 59] => [[2010, 12, 27, 00, 00], [2010, 12, 28, 00, 00]]
|
126
|
+
}
|
127
|
+
}.each do |tf, time_table|
|
128
|
+
describe "#{tf} timeframe" do
|
129
|
+
time_table.each do |initial_time, tf_boundary|
|
130
|
+
time = Time.utc(*initial_time)
|
131
|
+
starts = Time.utc(*tf_boundary.first)
|
132
|
+
expires = Time.utc(*tf_boundary.last)
|
133
|
+
|
134
|
+
describe "chart at #{time}" do
|
135
|
+
it "should start at #{starts}, expire at #{expires}" do
|
136
|
+
chart = Finexclub::Chart.build_new(@core, 'eurusd', tf, time)
|
137
|
+
chart.starts.should == starts.to_i
|
138
|
+
chart.expires.should == expires.to_i
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
107
144
|
end
|
108
145
|
|
109
146
|
end
|