fin 0.1.0 → 0.1.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.
@@ -5,77 +5,48 @@ module Fin
5
5
  # Source table: FORTS_ PART_REPL::part � ���������� � ��������� � �������
6
6
  #
7
7
  class MoneyLimit < Model
8
- # Properties as per P2ClientGate API
9
- prop_accessor [:repl_id, :id], [:repl_rev, :rev],
10
- :client_code, # c7 ��� �������
11
- :money_old, # d26.2 ����� �� ������ ������
12
- :money_amount, # d26.2 ����� �����
13
- :money_free, # d26.2 �������� �����
14
- :money_blocked, # d26.2 ������������� �����
15
- :pledge_old, # d26.2 ������� �� ������ ������
16
- :pledge_amount, # d26.2 ����� �������
17
- :pledge_free, # d26.2 �������� �������
18
- :pledge_blocked, # d26.2 ������������� �������
19
- :vm_reserve, # d26.2 �����, ����������������� ��� ������������ �����
20
- :vm_intercl, # d26.2 M����, ��������� ��� ���������� � ����. �������
21
- :fee, # d26.2 ��������� ����
22
- :fee_reserve, # d26.2 ��������������� ������ ����� ��� ������
23
- :limit_spot_buy, # d26.2 ����� �� ������� ������.
24
- :limit_spot_buy_used, # d26.2 �������������� ����� �� ������� ������
25
- :coeff_go, # d16.5 ����������� ����������� ��
26
- :coeff_liquidity, # d16.5 ����������� �����������
27
- :premium, # d26.2 ������
28
- :premium_order_reserve, # f ������ ������ ��� ������
29
-
30
- # Not extracted from record:
31
- :is_auto_update_limit, # i1 ������� ������������� ������ �� ��������
32
- # ������ ��� ������� ����� ��������: 0-���, 1-������.
33
- :is_auto_update_spot_limit, # i1 ������� ������������� ������� �� ������
34
- # (�� �������, � �� �������) ��� ������� ����� ��������: 0-���, 1-������.
35
- :no_fut_discount, # i1 ���������� ������������� ������ ��
36
- # ���������: 1-������, 0-���.
37
- :limits_set # i1 ������� �������. 0 � ������ �����������
38
-
8
+ model_class_id 13
39
9
 
40
- def self.from_record rec
41
- new :repl_id => rec.GetValAsString('replID').to_i,
42
- :repl_rev => rec.GetValAsString('replRev').to_i,
43
- :client_code => rec.GetValAsString('client_code'),
44
- :money_old => rec.GetValAsString('money_old').to_f,
45
- :money_amount => rec.GetValAsString('money_amount').to_f,
46
- :money_free => rec.GetValAsString('money_free').to_f,
47
- :money_blocked => rec.GetValAsString('money_blocked').to_f,
48
- :pledge_old => rec.GetValAsString('pledge_old').to_f,
49
- :pledge_amount => rec.GetValAsString('pledge_amount').to_f,
50
- :pledge_free => rec.GetValAsString('pledge_free').to_f,
51
- :pledge_blocked => rec.GetValAsString('pledge_blocked').to_f,
52
- :vm_reserve => rec.GetValAsString('vm_reserve').to_f,
53
- :vm_intercl => rec.GetValAsString('vm_intercl').to_f,
54
- :fee => rec.GetValAsString('vm_intercl').to_f,
55
- :fee_reserve => rec.GetValAsString('vm_reserve').to_f,
56
- :limit_spot_buy => rec.GetValAsString('vm_reserve').to_f,
57
- :limit_spot_buy_used => rec.GetValAsString('vm_reserve').to_f,
58
- :coeff_go => rec.GetValAsString('coeff_go').to_f,
59
- :coeff_liquidity => rec.GetValAsString('coeff_liquidity').to_f,
60
- :premium => rec.GetValAsString('premium').to_f,
61
- :premium_order_reserve => rec.GetValAsString('premium_order_reserve').to_f,
62
- end
10
+ # Properties as per P2ClientGate API
11
+ property :client_code => :c7, # ��� �������
12
+ :money_old => :'d26.2', # ����� �� ������ ������
13
+ :money_amount => :'d26.2', # ����� �����
14
+ :money_free => :'d26.2', # �������� �����
15
+ :money_blocked => :'d26.2', # ������������� �����
16
+ :pledge_old => :'d26.2', # ������� �� ������ ������
17
+ :pledge_amount => :'d26.2', # ����� �������
18
+ :pledge_free => :'d26.2', # �������� �������
19
+ :pledge_blocked => :'d26.2', # ������������� �������
20
+ :vm_reserve => :'d26.2', # ���������������� ��� ������������ �����
21
+ :vm_intercl => :'d26.2', # M����, ���������/���������� � ����. �������
22
+ :fee => :'d26.2', # ��������� ����
23
+ :fee_reserve => :'d26.2', # ��������������� ������ ����� ��� ������
24
+ :limit_spot_buy => :'d26.2', # ����� �� ������� ������.
25
+ :limit_spot_buy_used => :'d26.2', # �������������� ����� �� ����-�������
26
+ :coeff_go => :'d16.5', # ����������� ����������� ��
27
+ :coeff_liquidity => :'d16.5', # ����������� �����������
28
+ :premium => :'d26.2', # ������
29
+ :premium_order_reserve => :f, # ������ ������ ��� ������
30
+ :is_auto_update_limit => :i1, # ������� ������������� ������ ��
31
+ # �������� ������ ��� ������� ����� ��������: 0-���, 1-������.
32
+ :is_auto_update_spot_limit => :i1, # ������������� ������� �� ������
33
+ # (�� �������, � �� �������) ��� ������� ����� ��������: 0-���, 1-������.
34
+ :no_fut_discount => :i1, # 1 - ��������� ������������ ������ �� ���������, 0-���.
35
+ :limits_set => :i1 # 1 - ������ �����������, 0 � �����������
63
36
 
64
37
  def self.index_for rec
65
38
  rec.GetValAsLong('replID')
66
39
  end
67
40
 
68
41
  def index
69
- @repl_id
42
+ repl_id
70
43
  end
71
44
 
72
- def inspect
45
+ def to_s
73
46
  "Money: Old #{money_old} Amt #{money_amount} Free #{money_free} Blck #{money_blocked} " +
74
47
  "Pledge: Old #{pledge_old} Amt #{pledge_amount} Free #{pledge_free} Blck #{pledge_blocked} " +
75
48
  "VM: Reserve #{vm_reserve} Intercl #{vm_intercl} Fee: #{fee} Reserve #{fee_reserve} " +
76
49
  "Limit Spot: Buy #{limit_spot_buy} Used #{limit_spot_buy_used}"
77
50
  end
78
-
79
- alias to_s inspect
80
51
  end
81
52
  end
@@ -1,45 +1,70 @@
1
1
  require 'fin/models/model'
2
2
 
3
3
  module Fin
4
+
5
+ # Source table: FORTS_FUTTRADE_REPL::orders_log - ������� ��������� ������ � ������.
6
+ # Each record in this table represents an action related to some client Order:
7
+ # - Order added, Order deleted, Order (partially) executed...
8
+ #
9
+ # In principle, you can construct/update NOT only Orders, but also Deals and Quotes
10
+ # from information arriving via (full) 'orders_log' table...
11
+ #
4
12
  class Order < Model
13
+ model_class_id 14
5
14
 
6
15
  # Properties as per P2ClientGate API
7
- prop_accessor [:repl_id, :id], [:repl_rev, :rev],
8
- [:isin_id, :isin],
9
- :price, # d16.5 ���� ���������
10
- :volume, # i8 ����� �������������� ���������
11
- [:dir, :buysell], # i1 ����������� ���������: ������� (1) /������� (2)
12
- :moment # t ����� ���������� ���������� ���������
13
-
14
- attr_accessor :book
15
-
16
- def self.from_record rec
17
- new :isin_id => rec.GetValAsLong('isin_id'),
18
- :repl_id => rec.GetValAsString('replID').to_i,
19
- :repl_rev => rec.GetValAsString('replRev').to_i,
20
- :price => rec.GetValAsString('price').to_f,
21
- :volume => rec.GetValAsString('volume').to_f,
22
- :moment => rec.GetValAsString('moment'),
23
- :dir => rec.GetValAsLong('dir')
24
- end
16
+ property [:id_ord, :order_id] => :i8, # ����� ������
17
+ [:sess_id, :session_id] => :i4, # ������������� ������
18
+ :client_code => :c7, # ��� �������
19
+ :moment => :t, # ����� ��������� ��������� ������
20
+ :isin_id => :i4, # ���������� �������� ������������� �����������
21
+ :dir => :i1, # �����������, 1 �������, 2 � �������
22
+ :price => :'d16.5', # ���� (������)
23
+ :amount => :i4, # ���������� � ��������
24
+ :amount_rest => :i4, # ���������� ���������� � ������
25
+ :comment => :c20, # ����������� ��������
26
+ :hedge => :i1, # ������� �������� ������ (1 / 0)
27
+ :trust => :i1, # ������� ������ �������������� ���������� (1 / 0)
28
+ :login_from => :c20, # ����� ������������, ������������ ������
29
+ :broker_to => :c7, # ��� FORTS �����-�������� ������������ ������
30
+ :broker_to_rts => :c7, # ��� RTS �����-�������� ������������ ������
31
+ :ext_id => :i4, # ������� �����. ����������� � ������, ������
32
+ :date_exp => :t, # ���� ��������� ������
33
+ :id_ord1 => :i4, # ����� ������ ������ (��� ������������?)
34
+ :broker_from_rts => :c7, # ��� ��� ����� - ��������� ������
35
+ :id_deal => :i8, # ������������� ������ �� ������ ������ ������� ������
36
+ :deal_price => :'d16.5', # ���� ����������� ������
37
+ :status => :i4, # ������ ������ - ������������ ����� ������� �����:
38
+ # o 0x01 � ������������
39
+ # o 0x02 � ���������
40
+ # o 0x04 � ������������
41
+ # o 0x100000 � ������ �������� ����������� �������� ����������� ������
42
+ # o 0x200000 � ������ �������� ����������� �������� �������� ������
43
+ # o 0x400000 � ������ �������� ����������� ���������� ��������
44
+ # o 0x800000 � ������� �������� ������� ������ �� ������� �����-������
45
+ :action => :i1 # ��������� ��������, ������������ � �������:
46
+ # o 0 � ������ �������
47
+ # o 1 � ������ ���������
48
+ # o 2 � ������ ������� � ������
25
49
 
26
50
  def self.index_for rec
27
51
  rec.GetValAsLong('replID')
28
52
  end
29
53
 
30
54
  def index
31
- @repl_id
55
+ repl_id
32
56
  end
33
57
 
34
- def price= val
35
- val = val.to_f
36
- @price = val.round == val ? val.to_i : val
58
+ def to_s
59
+ "#{repl_id}:#{price_as_integer}>#{amount}#{dir == 1 ? '+' : '-'}"
37
60
  end
38
61
 
39
- def inspect
40
- "#{repl_id}:#{price}>#{volume}#{dir == 1 ? '+' : '-'}"
62
+ def price_as_integer
63
+ if price && price.round == price
64
+ price.to_i
65
+ else
66
+ price
67
+ end
41
68
  end
42
-
43
- alias to_s inspect
44
69
  end
45
70
  end
@@ -5,53 +5,30 @@ module Fin
5
5
  # Source table: FORTS_POS_REPL::position
6
6
  #
7
7
  class Position < Model
8
+ model_class_id 15
8
9
 
9
10
  # Properties as per P2ClientGate API
10
- prop_accessor [:repl_id, :id], [:repl_rev, :rev],
11
- [:isin_id, :isin],
12
- :client_code,
13
- :open_qty,
14
- :buys_qty,
15
- :sells_qty,
16
- :pos,
17
- :net_volume_rur,
18
- :last_deal_id
19
- # isin_id i4 ���������� �������� ������������� �����������
20
- # client_code c7 ��� �������
21
- # open_qty i4 ���������� ������� �� ������ ������
22
- # buys_qty i4 ���������� ��������� ���������� � ���� ������
23
- # sells_qty i4 ���������� ��������� ���������� � ���� ������
24
- # pos i4 ������� �������
25
- # net_volume_rur d26.2
26
- # H����-����� �����, � ������, �� ������� ���� ��������� ������.
27
- # ������������� ����� � ������ ��������, ������������� � ������ �������������
28
- # last_deal_id i8 ������������� ��������� ������
29
-
30
- def self.from_record rec
31
- new :isin_id => rec.GetValAsLong('isin_id'),
32
- :repl_id => rec.GetValAsString('replID').to_i,
33
- :repl_rev => rec.GetValAsString('replRev').to_i,
34
- :client_code => rec.GetValAsString('client_code'),
35
- :open_qty => rec.GetValAsLong('open_qty'),
36
- :buys_qty => rec.GetValAsLong('buys_qty'),
37
- :sells_qty => rec.GetValAsLong('sells_qty'),
38
- :pos => rec.GetValAsLong('pos'),
39
- :last_deal_id => rec.GetValAsString('replID').to_i,
40
- :net_volume_rur => rec.GetValAsString('net_volume_rur').to_f
41
- end
11
+ property :isin_id => :i4, # ���������� �������� ������������� �����������
12
+ :client_code => :c7, # ��� �������
13
+ :open_qty => :i4, # ���������� ������� �� ������ ������
14
+ :buys_qty => :i4, # ���������� ��������� ���������� � ���� ������
15
+ :sells_qty => :i4, # ���������� ��������� ���������� � ���� ������
16
+ :pos => :i4, # ������� �������
17
+ :net_volume_rur => :'d26.2',
18
+ # H����-����� �����, � ������, �� ������� ���� ��������� ������.
19
+ # ������������� ����� � ������ ��������, ������������� � ������ �������������
20
+ :last_deal_id => :i8 # ������������� ��������� ������
42
21
 
43
22
  def self.index_for rec
44
23
  rec.GetValAsLong('isin_id')
45
24
  end
46
25
 
47
26
  def index
48
- @isin_id
27
+ isin_id
49
28
  end
50
29
 
51
- def inspect
30
+ def to_s
52
31
  "#{repl_id}[#{isin_id}] #{pos}, open: #{open_qty}, buys: #{buys_qty}, sells: #{sells_qty}"
53
32
  end
54
-
55
- alias to_s inspect
56
33
  end
57
34
  end
@@ -0,0 +1,40 @@
1
+ require 'fin/models/model'
2
+
3
+ module Fin
4
+
5
+ # Represents Depth-of-Market Aggregate Order for a given security and price level.
6
+ # Source table: FORTS_OPTAGGR**_REPL::orders_aggr, where (**) is 5, 20, 50
7
+ #
8
+ class Quote < Model
9
+ model_class_id 16
10
+
11
+ # Properties as per P2ClientGate API
12
+ property :isin_id => :i8, # ���������� �������� ������������� �����������
13
+ :price => :'d16.5', # ���� ���������
14
+ :volume => :i8, # ����� �������������� ���������
15
+ [:dir, :buysell] => :i1, # ����������� ���������: ������� (1) /������� (2)
16
+ :moment => :t # ����� ���������� ���������� ���������
17
+
18
+ attr_accessor :book
19
+
20
+ def self.index_for rec
21
+ rec.GetValAsLong('replID')
22
+ end
23
+
24
+ def index
25
+ repl_id
26
+ end
27
+
28
+ def price_as_integer
29
+ if price && price.round == price
30
+ price.to_i
31
+ else
32
+ price
33
+ end
34
+ end
35
+
36
+ def to_s
37
+ "#{repl_id}:#{price_as_integer}>#{volume}#{dir == 1 ? '+' : '-'}"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ require 'fin/models/quote'
2
+ require 'fin/book_manager'
3
+
4
+ module Fin
5
+ # Represents list of ALL Quotes, indexed by repl_id
6
+ # Its @books is a set of QuoteBooks by isin_id. Each QuoteBook lists Quotes by price.
7
+ class QuoteList < ContainerList
8
+
9
+ include BookManager
10
+
11
+ def initialize
12
+ super :item_type => Fin::Quote
13
+ @book_index = proc { |item| item.price }
14
+ @book_condition = proc { |item| item.price > 0 }
15
+ end
16
+ end
17
+ end
@@ -2,7 +2,7 @@ require 'pathname'
2
2
 
3
3
  module Fin
4
4
 
5
- VERSION_FILE = Pathname.new(__FILE__).dirname + '../VERSION' # :nodoc:
5
+ VERSION_FILE = Pathname.new(__FILE__).dirname + '../VERSION' # :nodoc:
6
6
  VERSION = VERSION_FILE.exist? ? VERSION_FILE.read.strip : nil
7
7
 
8
8
  end
@@ -1,20 +1,20 @@
1
1
  require 'spec_helper'
2
2
  require 'fin/shared_examples.rb'
3
3
 
4
- describe Fin::Book, 'as a replacement for OrderBook' do
5
- subject { Fin::Book.new :item_type => Fin::Order,
6
- :book_index => proc { |item| item.price },
7
- :book_condition => proc { |item| item.price > 0},
8
- :isin_id => 123456 }
4
+ describe Fin::Book, 'as a replacement for QuoteBook' do
5
+ subject { Fin::Book.new :item_type => Fin::Quote,
6
+ :book_index => proc { |item| item.price },
7
+ :book_condition => proc { |item| item.price > 0 },
8
+ :isin_id => 123456 }
9
9
 
10
10
  let(:item_index) { @item.price }
11
11
 
12
12
  before(:each) do
13
- @item = Fin::Order.new :id => 0, :price => 20, :isin => 123456
14
- @item1 = Fin::Order.new :id => 1, :price => 15, :isin => 123456
15
- @item2 = Fin::Order.new :id => 2, :price => 10, :isin => 123456
16
- @zero_price_item = Fin::Order.new :id => 3, :price => 0, :isin => 123456
17
- @wrong_isin_item = Fin::Order.new :id => 4, :price => 50, :isin => 456123
13
+ @item = Fin::Quote.new :repl_id => 0, :price => 20, :isin_id => 123456
14
+ @item1 = Fin::Quote.new :repl_id => 1, :price => 15, :isin_id => 123456
15
+ @item2 = Fin::Quote.new :repl_id => 2, :price => 10, :isin_id => 123456
16
+ @zero_price_item = Fin::Quote.new :repl_id => 3, :price => 0, :isin_id => 123456
17
+ @wrong_isin_item = Fin::Quote.new :repl_id => 4, :price => 50, :isin_id => 456123
18
18
  end
19
19
 
20
20
  it_behaves_like 'changed_list'
@@ -34,7 +34,7 @@ describe Fin::Book, 'as a replacement for OrderBook' do
34
34
  end
35
35
 
36
36
  describe '#check' do
37
- it 'fails if item is not an Order' do
37
+ it 'fails if item is not an Quote' do
38
38
  subject.check(1).should == false
39
39
  end
40
40
 
@@ -123,15 +123,15 @@ end
123
123
 
124
124
  describe Fin::Book, 'as a replacement for DealBook' do
125
125
  subject { Fin::Book.new :item_type => Fin::Deal,
126
- :book_index => proc { |item| item.deal_id },
127
- :isin_id => 123456 }
126
+ :book_index => proc { |item| item.deal_id },
127
+ :isin_id => 123456 }
128
128
  let(:item_index) { @item.deal_id }
129
129
 
130
130
  before(:each) do
131
- @item = Fin::Deal.new :id => 0, :deal_id => 20, :isin => 123456
132
- @item1 = Fin::Deal.new :id => 1, :deal_id => 30, :isin => 123456
133
- @item2 = Fin::Deal.new :id => 2, :deal_id => 40, :isin => 123456
134
- @wrong_isin_item = Fin::Deal.new :id => 3, :deal_id => 50, :isin => 456123
131
+ @item = Fin::Deal.new :repl_id => 0, :deal_id => 20, :isin_id => 123456
132
+ @item1 = Fin::Deal.new :repl_id => 1, :deal_id => 30, :isin_id => 123456
133
+ @item2 = Fin::Deal.new :repl_id => 2, :deal_id => 40, :isin_id => 123456
134
+ @wrong_isin_item = Fin::Deal.new :repl_id => 3, :deal_id => 50, :isin_id => 456123
135
135
  end
136
136
 
137
137
  it_behaves_like 'changed_list'
@@ -30,13 +30,13 @@ describe Fin::DealList do
30
30
  describe 'adding item' do
31
31
  let(:expected_number_of_books) { 1 }
32
32
 
33
- context 'to empty OrderList' do
33
+ context 'to empty QuoteList' do
34
34
  let(:new_item) { @item }
35
35
 
36
36
  it_behaves_like 'adding_item_to_books'
37
37
  end
38
38
 
39
- context 'to non-empty OrderList' do
39
+ context 'to non-empty QuoteList' do
40
40
  before(:each) do
41
41
  subject.add(@item).size.should == 1
42
42
  end
@@ -73,7 +73,7 @@ describe Fin::DealList do
73
73
 
74
74
  it 'deletes item from the list' do
75
75
  subject.remove(unwanted_item)
76
- subject[unwanted_item.id].should == nil
76
+ subject[unwanted_item.deal_id].should == nil
77
77
  subject.size.should == expected_size
78
78
  end
79
79
 
@@ -2,139 +2,71 @@ require 'spec_helper'
2
2
  require 'fin/models/shared_examples'
3
3
 
4
4
  describe Fin::Deal do
5
+ let(:model_class_id) { 11 }
5
6
 
6
- it_behaves_like 'model'
7
+ shared_examples_for 'deal_with_set_properties' do
7
8
 
8
- describe '#new with empty initializer' do
9
- subject { Fin::Deal.new }
10
-
11
- its (:id) {should == nil} # replId
12
- its (:rev) {should == nil} # replRev
13
- its (:isin_id) {should == nil}
14
- its (:isin) {should == nil}
15
- its (:deal_id) {should == nil}
16
- its (:id_deal) {should == nil}
17
- its (:sess_id) {should == nil}
18
- its (:session_id) {should == nil}
19
- its (:price) {should == nil}
20
- its (:amount) {should == nil}
21
- its (:moment) {should == nil}
22
- its (:status_sell) {should == nil}
23
- its (:status_buy) {should == nil}
24
- its (:id_ord_sell) {should == nil}
25
- its (:id_ord_buy) {should == nil}
26
- its (:pos) {should == nil} # ���-�� ������� �� ����������� �� ����� ����� ������.
27
- its (:nosystem) {should == nil} # 1-������������ ������, 0-�������
28
- its (:id_repo) {should == nil} # ����� ������ ����� ������ ����
29
- its (:id_deal_multileg) {should == nil} # ����� ������ �� ������
30
-
31
- its (:book) {should == nil}
32
-
33
- # replID=6607871
34
- # replRev=6607876
35
- # replAct=0
36
- # id_deal=6608653
37
- # sess_id=3753
38
- # isin_id=154995
39
- # price=22194.00000
40
- # amount=3
41
- # moment=2011/03/23 15:30:04.746
42
- # id_ord_sell=2292952813
43
- # id_ord_buy=2292952838
44
- # status_sell=0
45
- # status_buy=0
46
- # pos=71148
47
- # nosystem=0
48
- # id_repo=0
49
- # id_deal_multileg=0
50
-
51
- # ���� code_sell, comment_sell, ext_id_sell, trust_sell, hedge_sell,
52
- # login_sell, code_rts_sell, fee_sell, code_buy, comment_buy, ext_id_buy,
53
- # trust_buy, hedge_buy, login_buy, code_rts_buy, fee_buy -
54
- # - ����������� ������ ��� ����� ������.
55
-
56
- # code_sell=
57
- # code_buy=
58
- # ext_id_sell=0
59
- # comment_sell=
60
- # trust_sell=0
61
- # ext_id_buy=0
62
- # comment_buy=
63
- # trust_buy=0
64
- # hedge_sell=0
65
- # hedge_buy=0
66
- # fee_sell=0.00
67
- # fee_buy=0.00
68
- # login_sell=
69
- # login_buy=
70
- # code_rts_sell=
71
- # code_rts_buy=
72
- end
73
-
74
-
75
- describe '#new with opts' do
76
- subject { Fin::Deal.new :isin => 1234567,
77
- :id => 12,
78
- :rev => 123,
79
- :price => 1234,
80
- :amount => 12345,
81
- :deal_id => 1212,
82
- :sess_id => 1213,
83
- :moment => 'time',
84
- :status_sell => 0,
85
- :status_buy => 0,
86
- :id_ord_sell => 123456,
87
- :id_ord_buy => 654321,
88
- :pos => 121212, # ���-�� ������� �� ����������� �� ����� ����� ������.
89
- :nosystem => 0, # 1-������������ ������, 0-�������
90
- :id_repo => 0, # ����� ������ ����� ������ ����
91
- :id_deal_multileg => 0, # ����� ������ �� ������
92
- :book=> 123456,
93
- }
94
-
95
- its (:isin_id) {should == 1234567}
96
- its (:isin) {should == 1234567}
97
- its (:id) {should == 12}
98
- its (:rev) {should == 123}
99
- its (:price) {should == 1234}
100
- its (:amount) {should == 12345}
101
-
102
- its (:deal_id) {should == 1212}
103
9
  its (:id_deal) {should == 1212}
104
- its (:sess_id) {should == 1213}
105
10
  its (:session_id) {should == 1213}
106
- its (:moment) {should == 'time'}
107
- its (:status_sell) {should == 0}
108
- its (:status_buy) {should == 0}
109
- its (:id_ord_sell) {should == 123456}
110
- its (:id_ord_buy) {should == 654321}
111
- its (:pos) {should == 121212} # ���-�� ������� �� ����������� �� ����� ����� ������.
112
- its (:nosystem) {should == 0} # 1-������������ ������, 0-�������
113
- its (:id_repo) {should == 0} # ����� ������ ����� ������ ����
114
- its (:id_deal_multileg) {should == 0} # ����� ������ �� ������
115
-
116
11
  its (:book) {should == 123456}
117
12
 
13
+ it_behaves_like 'model'
14
+ it_behaves_like 'price_as_integer'
15
+
118
16
  describe '#to_s, #inspect' do
119
- it 'is just right' do
120
- subject.to_s.should == "time:12[1234567] 1234>12345"
121
- subject.inspect.should == "time:12[1234567] 1234>12345"
17
+ it '#to_s reveals meaningful info' do
18
+ subject.to_s.should == "time:1212[1234567] 1234>12345"
122
19
  end
123
- end
124
20
 
125
- describe '#price=' do
126
- it 'converts given price to Integer if it is integer' do
127
- subject.price = 1313.0
128
- subject.price.should == 1313
129
- subject.price.should be_an Integer
21
+ it '#inspect lists ALL properties' do
22
+ subject.inspect.should == "replID=12,replRev=123,replAct=,isin_id=1234567,price=1234,amount=12345,id_deal=1212,sess_id=1213,moment=time,pos=121212,nosystem=0,id_deal_multileg=0,id_repo=0,code_sell=,id_ord_sell=123456,ext_id_sell=,comment_sell=,trust_sell=,status_sell=0,hedge_sell=,fee_sell=,login_sell=,code_rts_sell=,code_buy=,id_ord_buy=654321,ext_id_buy=,comment_buy=,trust_buy=,status_buy=0,hedge_buy=,fee_buy=,login_buy=,code_rts_buy="
130
23
  end
131
24
  end
132
25
 
133
26
  describe '#index' do
134
- it 'should be equal to isin_id' do
27
+ it 'should be equal to deal_id' do
135
28
  subject.index.should == subject.deal_id
136
29
  end
137
30
  end
138
31
  end
32
+
33
+ describe '#new with empty initializer' do
34
+ let(:property_hash) { {} }
35
+ subject { Fin::Deal.new }
36
+
37
+ it_behaves_like 'model'
38
+
39
+ it 'has all nil properties' do
40
+ subject.class.attribute_types.each { |prop, _| subject.send(prop).should == nil }
41
+ end
42
+
43
+ its (:book) {should == nil}
44
+ end
45
+
46
+ describe '#new with opts' do
47
+
48
+ let(:property_hash) do
49
+ {:isin_id => 1234567,
50
+ :repl_id => 12,
51
+ :rev => 123,
52
+ :price => 1234,
53
+ :amount => 12345,
54
+ :deal_id => 1212,
55
+ :sess_id => 1213,
56
+ :moment => 'time',
57
+ :status_sell => 0,
58
+ :status_buy => 0,
59
+ :id_ord_sell => 123456,
60
+ :id_ord_buy => 654321,
61
+ :pos => 121212, # ���-�� ������� �� ����������� �� ����� ����� ������.
62
+ :nosystem => 0, # 1-������������ ������, 0-�������
63
+ :id_repo => 0, # ����� ������ ����� ������ ����
64
+ :id_deal_multileg => 0, # ����� ������ �� ������
65
+ :book=> 123456,
66
+ }
67
+ end
68
+ subject { Fin::Deal.new property_hash }
69
+ it_behaves_like 'deal_with_set_properties'
70
+ end
139
71
  end
140
72