fin 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +4 -0
- data/README.rdoc +5 -5
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/lib/fin.rb +2 -5
- data/lib/fin/book.rb +2 -2
- data/lib/fin/book_manager.rb +1 -1
- data/lib/fin/changed_list.rb +1 -1
- data/lib/fin/container_list.rb +10 -1
- data/lib/fin/deal_list.rb +2 -2
- data/lib/fin/models/deal.rb +44 -50
- data/lib/fin/models/instrument.rb +39 -57
- data/lib/fin/models/model.rb +112 -16
- data/lib/fin/models/money_limit.rb +29 -58
- data/lib/fin/models/order.rb +51 -26
- data/lib/fin/models/position.rb +13 -36
- data/lib/fin/models/quote.rb +40 -0
- data/lib/fin/quote_list.rb +17 -0
- data/lib/version.rb +1 -1
- data/spec/fin/book_spec.rb +17 -17
- data/spec/fin/deal_list_spec.rb +3 -3
- data/spec/fin/models/deal_spec.rb +49 -117
- data/spec/fin/models/instrument_spec.rb +32 -34
- data/spec/fin/models/model_spec.rb +215 -75
- data/spec/fin/models/money_limit_spec.rb +48 -119
- data/spec/fin/models/order_spec.rb +29 -48
- data/spec/fin/models/position_spec.rb +34 -55
- data/spec/fin/models/quote_spec.rb +73 -0
- data/spec/fin/models/shared_examples.rb +84 -3
- data/spec/fin/order_list_spec.rb +12 -12
- data/spec/fin/shared_examples.rb +1 -1
- data/tasks/common.rake +2 -2
- data/tasks/spec.rake +1 -1
- data/tasks/version.rake +7 -7
- metadata +6 -3
- data/lib/fin/order_list.rb +0 -17
@@ -2,66 +2,47 @@ require 'spec_helper'
|
|
2
2
|
require 'fin/models/shared_examples'
|
3
3
|
|
4
4
|
describe Fin::Order do
|
5
|
+
let(:model_class_id) { 14 }
|
5
6
|
|
6
|
-
|
7
|
+
shared_examples_for 'order_with_set_properties' do
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
its (:repl_id) {should == nil}
|
12
|
-
its (:rev) {should == nil}
|
13
|
-
its (:isin_id) {should == nil}
|
14
|
-
its (:isin) {should == nil}
|
15
|
-
its (:price) {should == nil}
|
16
|
-
its (:volume) {should == nil}
|
17
|
-
its (:dir) {should == nil}
|
18
|
-
its (:buysell) {should == nil}
|
19
|
-
its (:moment) {should == nil}
|
20
|
-
its (:book) {should == nil}
|
21
|
-
end
|
22
|
-
|
23
|
-
describe '#new with opts' do
|
24
|
-
subject { Fin::Order.new :isin => 1234567,
|
25
|
-
:repl_id => 12,
|
26
|
-
:rev => 123,
|
27
|
-
:price => 1234,
|
28
|
-
:volume => 12345,
|
29
|
-
:buysell => 1,
|
30
|
-
:moment => 'time',
|
31
|
-
:book => 123456
|
32
|
-
}
|
9
|
+
it_behaves_like 'model'
|
10
|
+
it_behaves_like 'price_as_integer'
|
33
11
|
|
34
|
-
|
35
|
-
its (:rev) {should == 123}
|
36
|
-
its (:isin_id) {should == 1234567}
|
37
|
-
its (:isin) {should == 1234567}
|
38
|
-
its (:price) {should == 1234}
|
39
|
-
its (:volume) {should == 12345}
|
40
|
-
its (:dir) {should == 1}
|
41
|
-
its (:buysell) {should == 1}
|
42
|
-
its (:moment) {should == 'time'}
|
43
|
-
its (:book) {should == 123456}
|
44
|
-
|
45
|
-
describe '#to_s, #inspect' do
|
12
|
+
describe '#to_s' do
|
46
13
|
it 'is just right' do
|
47
14
|
subject.to_s.should == "12:1234>12345+"
|
48
|
-
subject.inspect.should == "12:1234>12345+"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#price=' do
|
53
|
-
it 'converts given price to Integer if it is integer' do
|
54
|
-
subject.price = 1313.0
|
55
|
-
subject.price.should == 1313
|
56
|
-
subject.price.should be_an Integer
|
57
15
|
end
|
58
16
|
end
|
59
17
|
|
60
18
|
describe '#index' do
|
61
|
-
it 'should be equal to
|
19
|
+
it 'should be equal to repl_id' do
|
62
20
|
subject.index.should == subject.repl_id
|
63
21
|
end
|
64
22
|
end
|
65
23
|
end
|
24
|
+
|
25
|
+
describe '#new with empty initializer' do
|
26
|
+
let(:property_hash) { {} }
|
27
|
+
subject { Fin::Order.new }
|
28
|
+
|
29
|
+
it_behaves_like 'model'
|
30
|
+
|
31
|
+
it 'has all nil properties' do
|
32
|
+
subject.class.attribute_types.each { |prop, _| subject.send(prop).should == nil }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#new with opts' do
|
37
|
+
let(:property_hash) do
|
38
|
+
{:repl_id => 12,
|
39
|
+
:amount => 12345,
|
40
|
+
:price => 1234,
|
41
|
+
:dir => 1
|
42
|
+
}
|
43
|
+
end
|
44
|
+
subject { Fin::Order.new property_hash }
|
45
|
+
it_behaves_like 'order_with_set_properties'
|
46
|
+
end
|
66
47
|
end
|
67
48
|
|
@@ -2,65 +2,14 @@ require 'spec_helper'
|
|
2
2
|
require 'fin/models/shared_examples'
|
3
3
|
|
4
4
|
describe Fin::Position do
|
5
|
+
let(:model_class_id) { 15 }
|
5
6
|
|
6
|
-
|
7
|
+
shared_examples_for 'position_with_set_properties' do
|
8
|
+
it_behaves_like 'model'
|
7
9
|
|
8
|
-
|
9
|
-
subject { Fin::Position.new }
|
10
|
-
|
11
|
-
its (:repl_id) {should == nil} # replId
|
12
|
-
its (:repl_rev) {should == nil} # replRev
|
13
|
-
its (:isin_id) {should == nil}
|
14
|
-
its (:client_code) {should == nil}
|
15
|
-
its (:open_qty) {should == nil}
|
16
|
-
its (:buys_qty) {should == nil}
|
17
|
-
its (:sells_qty) {should == nil}
|
18
|
-
its (:pos) {should == nil}
|
19
|
-
its (:net_volume_rur) {should == nil}
|
20
|
-
its (:last_deal_id) {should == nil}
|
21
|
-
|
22
|
-
# isin_id i4 ���������� �������� ������������� �����������
|
23
|
-
# client_code c7 ��� �������
|
24
|
-
# open_qty i4 ���������� ������� �� ������ ������
|
25
|
-
# buys_qty i4 ���������� ��������� ���������� � ���� ������
|
26
|
-
# sells_qty i4 ���������� ��������� ���������� � ���� ������
|
27
|
-
# pos i4 ������� �������
|
28
|
-
# net_volume_rur d26.2 �����-����� �����, � ������, �� ������� ���� ��������� ������.
|
29
|
-
# ������������� ����� � ������ ��������, ������������� � ������ �������������
|
30
|
-
# last_deal_id i8 ������������� ��������� ������
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#new with opts' do
|
34
|
-
subject { Fin::Position.new :isin_id => 1234567,
|
35
|
-
:repl_id => 12,
|
36
|
-
:repl_rev => 123,
|
37
|
-
:client_code => 'fz1234',
|
38
|
-
:open_qty => 12345,
|
39
|
-
:buys_qty => 1212,
|
40
|
-
:sells_qty => 1213,
|
41
|
-
:pos => 12344,
|
42
|
-
:net_volume_rur => 123456,
|
43
|
-
:last_deal_id => 654321,
|
44
|
-
|
45
|
-
}
|
46
|
-
|
47
|
-
its (:isin_id) {should == 1234567}
|
48
|
-
its (:isin) {should == 1234567}
|
49
|
-
its (:id) {should == 12}
|
50
|
-
its (:rev) {should == 123}
|
51
|
-
its (:client_code) {should == 'fz1234'}
|
52
|
-
its (:open_qty) {should == 12345}
|
53
|
-
|
54
|
-
its (:buys_qty) {should == 1212}
|
55
|
-
its (:sells_qty) {should == 1213}
|
56
|
-
its (:pos) {should == 12344}
|
57
|
-
its (:net_volume_rur) {should == 123456}
|
58
|
-
its (:last_deal_id) {should == 654321}
|
59
|
-
|
60
|
-
describe '#to_s, #inspect' do
|
10
|
+
describe '#to_s' do
|
61
11
|
it 'is just right' do
|
62
12
|
subject.to_s.should == "12[1234567] 12344, open: 12345, buys: 1212, sells: 1213"
|
63
|
-
subject.inspect.should == "12[1234567] 12344, open: 12345, buys: 1212, sells: 1213"
|
64
13
|
end
|
65
14
|
end
|
66
15
|
|
@@ -70,5 +19,35 @@ describe Fin::Position do
|
|
70
19
|
end
|
71
20
|
end
|
72
21
|
end
|
22
|
+
|
23
|
+
describe '#new with empty initializer' do
|
24
|
+
let(:property_hash) { {} }
|
25
|
+
subject { Fin::Position.new }
|
26
|
+
|
27
|
+
it_behaves_like 'model'
|
28
|
+
|
29
|
+
it 'has all nil properties' do
|
30
|
+
subject.class.attribute_types.each { |prop, _| subject.send(prop).should == nil }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#new with opts' do
|
35
|
+
let(:property_hash) do
|
36
|
+
{:isin_id => 1234567,
|
37
|
+
:repl_id => 12,
|
38
|
+
:repl_rev => 123,
|
39
|
+
:client_code => 'fz1234',
|
40
|
+
:open_qty => 12345,
|
41
|
+
:buys_qty => 1212,
|
42
|
+
:sells_qty => 1213,
|
43
|
+
:pos => 12344,
|
44
|
+
:net_volume_rur => 123456,
|
45
|
+
:last_deal_id => 654321,
|
46
|
+
|
47
|
+
}
|
48
|
+
end
|
49
|
+
subject { Fin::Position.new property_hash }
|
50
|
+
it_behaves_like 'position_with_set_properties'
|
51
|
+
end
|
73
52
|
end
|
74
53
|
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fin/models/shared_examples'
|
3
|
+
|
4
|
+
describe Fin::Quote do
|
5
|
+
let(:model_class_id) { 16 }
|
6
|
+
|
7
|
+
shared_examples_for 'quote_with_set_properties' do
|
8
|
+
it_behaves_like 'model'
|
9
|
+
it_behaves_like 'price_as_integer'
|
10
|
+
|
11
|
+
its (:book) {should == 123456}
|
12
|
+
|
13
|
+
describe '#to_s' do
|
14
|
+
it 'is just right' do
|
15
|
+
subject.to_s.should == "12:1234>12345+"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#index' do
|
20
|
+
it 'should be equal to repl_id' do
|
21
|
+
subject.index.should == subject.repl_id
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#new with empty initializer' do
|
27
|
+
let(:property_hash) { {} }
|
28
|
+
subject { Fin::Quote.new }
|
29
|
+
|
30
|
+
its (:book) {should == nil}
|
31
|
+
|
32
|
+
it_behaves_like 'model'
|
33
|
+
|
34
|
+
it 'has all nil properties' do
|
35
|
+
subject.class.attribute_types.each { |prop, _| subject.send(prop).should == nil }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'with properties' do
|
40
|
+
let(:property_hash) do
|
41
|
+
{:isin_id => 1234567,
|
42
|
+
:repl_id => 12,
|
43
|
+
:rev => 123,
|
44
|
+
:repl_act => 1,
|
45
|
+
:price => 1234.0,
|
46
|
+
:volume => 12345,
|
47
|
+
:buysell => 1,
|
48
|
+
:moment => 'time',
|
49
|
+
:book => 123456
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'initialized with property options hash' do
|
54
|
+
subject { Fin::Quote.new property_hash }
|
55
|
+
it_behaves_like 'quote_with_set_properties'
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'initialized with property array' do
|
59
|
+
subject { Fin::Quote.new 12,
|
60
|
+
123,
|
61
|
+
1,
|
62
|
+
1234567,
|
63
|
+
1234.0,
|
64
|
+
12345,
|
65
|
+
1,
|
66
|
+
'time',
|
67
|
+
:book => 123456
|
68
|
+
}
|
69
|
+
|
70
|
+
it_behaves_like 'quote_with_set_properties'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -1,5 +1,86 @@
|
|
1
1
|
shared_examples_for 'model' do
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
it 'has index method' do
|
3
|
+
expect { subject.index }.to_not raise_error
|
4
|
+
end
|
5
|
+
|
6
|
+
it 'has pre-defined replID, replRev, replAct properties' do
|
7
|
+
expect do
|
8
|
+
subject.replID
|
9
|
+
subject.repl_id
|
10
|
+
subject.replRev
|
11
|
+
subject.repl_rev
|
12
|
+
subject.rev
|
13
|
+
subject.replAct
|
14
|
+
subject.repl_act
|
15
|
+
end.to_not raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'properties' do
|
19
|
+
|
20
|
+
it 'has all properties set correctly' do
|
21
|
+
property_hash.each { |prop, value| subject.send(prop).should == value }
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'enumeration' do
|
25
|
+
|
26
|
+
specify { should be_kind_of Enumerable }
|
27
|
+
|
28
|
+
describe '#each' do
|
29
|
+
it 'enumerates through property names and respective values' do
|
30
|
+
@property_names = []
|
31
|
+
@property_values = []
|
32
|
+
subject.each do |name, value|
|
33
|
+
@property_names << name
|
34
|
+
@property_values << value
|
35
|
+
end
|
36
|
+
@property_values.size.should == subject.class.attribute_types.size
|
37
|
+
@property_names.should == subject.class.attribute_types.keys
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#each_property' do
|
42
|
+
it 'enumerates through property names and respective values' do
|
43
|
+
@property_names = []
|
44
|
+
@property_values = []
|
45
|
+
subject.each_property do |name, value|
|
46
|
+
@property_names << name
|
47
|
+
@property_values << value
|
48
|
+
end
|
49
|
+
@property_values.size.should == subject.class.attribute_types.size
|
50
|
+
@property_names.should == subject.class.attribute_types.keys
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#inspect' do
|
57
|
+
it 'lists all properties' do
|
58
|
+
subject.inspect.should == subject.map { |prop, value| "#{prop}=#{value}" }.join(',')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '.model_class_id' do
|
63
|
+
it 'is properly set' do
|
64
|
+
described_class.model_class_id.should == model_class_id
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'is added to model classes list' do
|
68
|
+
id = described_class.model_class_id
|
69
|
+
Fin::Model.model_classes[id].should == described_class
|
70
|
+
described_class.model_classes[id].should == described_class
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
shared_examples_for 'price_as_integer' do
|
76
|
+
describe '#price_as_integer' do
|
77
|
+
it 'returns price as Integer if it is Integer' do
|
78
|
+
subject.price = 1313.0
|
79
|
+
subject.price.should == 1313.0
|
80
|
+
subject.price_as_integer.should == 1313
|
81
|
+
subject.price = 1313.5
|
82
|
+
subject.price.should == 1313.5
|
83
|
+
subject.price_as_integer.should == 1313.5
|
84
|
+
end
|
85
|
+
end
|
5
86
|
end
|
data/spec/fin/order_list_spec.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'fin/shared_examples.rb'
|
3
3
|
|
4
|
-
describe Fin::
|
5
|
-
subject { Fin::
|
6
|
-
let(:item_index) { @item.
|
4
|
+
describe Fin::QuoteList do
|
5
|
+
subject { Fin::QuoteList.new }
|
6
|
+
let(:item_index) { @item.repl_id }
|
7
7
|
let (:new_item_book_index) {new_item.price}
|
8
8
|
|
9
9
|
before(:each) do
|
10
|
-
@item = Fin::
|
11
|
-
@item1 = Fin::
|
10
|
+
@item = Fin::Quote.new :isin_id => 1234, :repl_id => 0, :price => 20
|
11
|
+
@item1 = Fin::Quote.new :isin_id => 1234, :repl_id => 1, :price => 10
|
12
12
|
@same_isin_item = @item1
|
13
|
-
@item2 = Fin::
|
13
|
+
@item2 = Fin::Quote.new :isin_id => 5678, :repl_id => 2, :price => 10
|
14
14
|
@diff_isin_item = @item2
|
15
|
-
@zero_price_item = Fin::
|
16
|
-
@repeat_item = Fin::
|
17
|
-
@repeat_zero_price_item = Fin::
|
15
|
+
@zero_price_item = Fin::Quote.new :isin_id => 1234, :repl_id => 3, :price => 0
|
16
|
+
@repeat_item = Fin::Quote.new :isin_id => 1234, :repl_id => 0, :price => 13
|
17
|
+
@repeat_zero_price_item = Fin::Quote.new :isin_id => 1234, :repl_id => 0, :price => 0
|
18
18
|
end
|
19
19
|
|
20
20
|
it_behaves_like 'changed_list'
|
@@ -31,7 +31,7 @@ describe Fin::OrderList do
|
|
31
31
|
describe 'adding item' do
|
32
32
|
let(:expected_number_of_books) { 1 }
|
33
33
|
|
34
|
-
context 'to empty
|
34
|
+
context 'to empty QuoteList' do
|
35
35
|
let(:new_item) { @item }
|
36
36
|
|
37
37
|
it_behaves_like 'adding_item_to_books'
|
@@ -43,7 +43,7 @@ describe Fin::OrderList do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
context 'to non-empty
|
46
|
+
context 'to non-empty QuoteList' do
|
47
47
|
before(:each) do
|
48
48
|
subject.add(@item).size.should == 1
|
49
49
|
end
|
@@ -111,7 +111,7 @@ describe Fin::OrderList do
|
|
111
111
|
|
112
112
|
it 'deletes item from the list' do
|
113
113
|
subject.remove(unwanted_item)
|
114
|
-
subject[unwanted_item.
|
114
|
+
subject[unwanted_item.repl_id].should == nil
|
115
115
|
subject.size.should == expected_size
|
116
116
|
end
|
117
117
|
|
data/spec/fin/shared_examples.rb
CHANGED
@@ -340,7 +340,7 @@ shared_examples_for 'creating_books' do
|
|
340
340
|
book = subject.books[new_item.isin_id]
|
341
341
|
if new_item_book_index == 0
|
342
342
|
case subject
|
343
|
-
when Fin::
|
343
|
+
when Fin::QuoteList
|
344
344
|
new_item.book.should == nil
|
345
345
|
else
|
346
346
|
new_item.book.should == book
|
data/tasks/common.rake
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#task 'gem:release' => 'test:run'
|
3
3
|
|
4
4
|
task :notes do
|
5
|
-
|
5
|
+
puts 'Output annotations (TBD)'
|
6
6
|
end
|
7
7
|
|
8
8
|
#Bundler not ready for prime time just yet
|
@@ -15,4 +15,4 @@ end
|
|
15
15
|
# system "bundle install"
|
16
16
|
# puts
|
17
17
|
# end
|
18
|
-
#end
|
18
|
+
#end
|
data/tasks/spec.rake
CHANGED