| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Protocol::FIX; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Financial Information eXchange (FIX) messages parser/serializer |
|
3
|
|
|
|
|
|
|
|
|
4
|
11
|
|
|
11
|
|
672532
|
use strict; |
|
|
11
|
|
|
|
|
73
|
|
|
|
11
|
|
|
|
|
342
|
|
|
5
|
11
|
|
|
11
|
|
59
|
use warnings; |
|
|
11
|
|
|
|
|
19
|
|
|
|
11
|
|
|
|
|
277
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
11
|
|
|
11
|
|
4867
|
use XML::Fast; |
|
|
11
|
|
|
|
|
130734
|
|
|
|
11
|
|
|
|
|
569
|
|
|
8
|
11
|
|
|
11
|
|
5462
|
use File::ShareDir qw/dist_dir/; |
|
|
11
|
|
|
|
|
310599
|
|
|
|
11
|
|
|
|
|
558
|
|
|
9
|
11
|
|
|
11
|
|
9972
|
use Path::Tiny; |
|
|
11
|
|
|
|
|
143005
|
|
|
|
11
|
|
|
|
|
566
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
11
|
|
|
11
|
|
4956
|
use Protocol::FIX::Component; |
|
|
11
|
|
|
|
|
30
|
|
|
|
11
|
|
|
|
|
327
|
|
|
12
|
11
|
|
|
11
|
|
3697
|
use Protocol::FIX::Field; |
|
|
11
|
|
|
|
|
32
|
|
|
|
11
|
|
|
|
|
363
|
|
|
13
|
11
|
|
|
11
|
|
4686
|
use Protocol::FIX::Group; |
|
|
11
|
|
|
|
|
26
|
|
|
|
11
|
|
|
|
|
311
|
|
|
14
|
11
|
|
|
11
|
|
83
|
use Protocol::FIX::BaseComposite; |
|
|
11
|
|
|
|
|
21
|
|
|
|
11
|
|
|
|
|
204
|
|
|
15
|
11
|
|
|
11
|
|
4512
|
use Protocol::FIX::Message; |
|
|
11
|
|
|
|
|
30
|
|
|
|
11
|
|
|
|
|
325
|
|
|
16
|
11
|
|
|
11
|
|
4772
|
use Protocol::FIX::Parser; |
|
|
11
|
|
|
|
|
28
|
|
|
|
11
|
|
|
|
|
392
|
|
|
17
|
11
|
|
|
11
|
|
79
|
use Exporter qw/import/; |
|
|
11
|
|
|
|
|
21
|
|
|
|
11
|
|
|
|
|
28326
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @EXPORT_OK = qw/humanize/; |
|
20
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Protocol::FIX - Financial Information eXchange (FIX) messages parser/serializer |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use Protocol::FIX; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $proto = Protocol::FIX->new('FIX44')->extension('t/data/extension-sample.xml'); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $serialized = $proto->serialize_message('IOI', [ |
|
33
|
|
|
|
|
|
|
SenderCompID => 'me', |
|
34
|
|
|
|
|
|
|
TargetCompID => 'you', |
|
35
|
|
|
|
|
|
|
MsgSeqNum => 1, |
|
36
|
|
|
|
|
|
|
SendingTime => '20090107-18:15:16', |
|
37
|
|
|
|
|
|
|
IOIID => 'abc', |
|
38
|
|
|
|
|
|
|
IOITransType => 'CANCEL', |
|
39
|
|
|
|
|
|
|
IOIQty => 'LARGE', |
|
40
|
|
|
|
|
|
|
Side => 'BORROW', |
|
41
|
|
|
|
|
|
|
Instrument => [ |
|
42
|
|
|
|
|
|
|
Symbol => 'EURUSD', |
|
43
|
|
|
|
|
|
|
EvntGrp => [ NoEvents => [ [EventType => 'PUT'], [EventType => 'CALL'], [EventType => 'OTHER'] ] ], |
|
44
|
|
|
|
|
|
|
], |
|
45
|
|
|
|
|
|
|
OrderQtyData => [ |
|
46
|
|
|
|
|
|
|
OrderQty => '499', |
|
47
|
|
|
|
|
|
|
], |
|
48
|
|
|
|
|
|
|
]); |
|
49
|
|
|
|
|
|
|
# managed fields (BeginString, MsgType, and CheckSum) are handled automatically, |
|
50
|
|
|
|
|
|
|
# no need to provide them |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my ($message_instance, $error) = $proto->parse_message(\$serialized); |
|
53
|
|
|
|
|
|
|
print("No error on parsing message"); |
|
54
|
|
|
|
|
|
|
print "Message, ", $message_instance->name, " / ", $message_instance->category, "\n"; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
print "Field 'SenderCompID' value: ", $message_instance->value('SenderCompID'), "\n"; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
print "Component 'OrderQtyData' access: ", |
|
59
|
|
|
|
|
|
|
$message_instance->value('OrderQtyData')->value('OrderQty'), "\n"; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $group = $message_instance->value('Instrument')->value('EvntGrp')->value('NoEvents'); |
|
62
|
|
|
|
|
|
|
print "0th group 'NoEvents' of component 'Instrument/EvntGrp' access: ", |
|
63
|
|
|
|
|
|
|
$group->[0]->value('EventType'), "\n"; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $buff = ''; |
|
66
|
|
|
|
|
|
|
($message_instance, $error) = $proto->parse_message(\$buff); |
|
67
|
|
|
|
|
|
|
# no error nor message_instance, as there is no enough data. |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
See also the "eg" folder for sample of FIX-server. |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
With this module you can easily create new FIX messages in human-readable way, i.e. use |
|
74
|
|
|
|
|
|
|
names like OrderQty => '499', instead of directly wring string like '39=499'; and vise |
|
75
|
|
|
|
|
|
|
versa, you can parse the gibberish FIX messages to access fields in human-readable way |
|
76
|
|
|
|
|
|
|
too. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The module checks that mandatory fields are present, and that field values bypass |
|
79
|
|
|
|
|
|
|
the validation. |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $distribution = 'Protocol-FIX'; |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my %MANAGED_COMPOSITES = map { $_ => 1 } qw/BeginString BodyLength MsgType CheckSum/; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my %specification_for = (fix44 => 'FIX44.xml'); |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
our $SEPARATOR = "\x{01}"; |
|
90
|
|
|
|
|
|
|
our $TAG_SEPARATOR = "="; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 METHODS |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head3 new |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
new($class, $version) |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Creates new protocol instance for the specified FIX protocol version. Currently |
|
99
|
|
|
|
|
|
|
shipped version is 'FIX44'. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The xml with protocol definition was taken at L. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub new { |
|
106
|
7
|
|
|
7
|
1
|
726
|
my ($class, $version) = @_; |
|
107
|
7
|
50
|
|
|
|
35
|
die("FIX protocol version should be specified") |
|
108
|
|
|
|
|
|
|
unless $version; |
|
109
|
|
|
|
|
|
|
|
|
110
|
7
|
|
|
|
|
45
|
my $file = $specification_for{lc $version}; |
|
111
|
7
|
50
|
|
|
|
27
|
die("Unsupported FIX protocol version: $version. Supported versions are: " . join(", ", sort { $a cmp $b } keys %specification_for)) |
|
|
0
|
|
|
|
|
0
|
|
|
112
|
|
|
|
|
|
|
unless $file; |
|
113
|
|
|
|
|
|
|
|
|
114
|
7
|
|
33
|
|
|
55
|
my $dir = $ENV{PROTOCOL_FIX_SHARE_DIR} // dist_dir($distribution); |
|
115
|
7
|
|
|
|
|
1099
|
my $xml = path("$dir/$file")->slurp; |
|
116
|
7
|
|
|
|
|
7003
|
my $protocol_definition = xml2hash $xml; |
|
117
|
7
|
|
|
|
|
117454
|
my $obj = { |
|
118
|
|
|
|
|
|
|
version => lc $version, |
|
119
|
|
|
|
|
|
|
}; |
|
120
|
7
|
|
|
|
|
38
|
bless $obj, $class; |
|
121
|
7
|
|
|
|
|
39
|
$obj->_construct_from_definition($protocol_definition); |
|
122
|
7
|
|
|
|
|
15102
|
return $obj; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head3 extension |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
extension($self, $extension_path) |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Modifies the protocol, by loading XML extension. |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
The extension might contain additional B or B. The |
|
132
|
|
|
|
|
|
|
extension XML should conform the format as the protocol definition itself, |
|
133
|
|
|
|
|
|
|
i.e.: |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub extension { |
|
154
|
2
|
|
|
2
|
1
|
16
|
my ($self, $extension_path) = @_; |
|
155
|
|
|
|
|
|
|
|
|
156
|
2
|
|
|
|
|
15
|
my $xml = path($extension_path)->slurp; |
|
157
|
2
|
|
|
|
|
2257
|
my $definition = xml2hash $xml; |
|
158
|
|
|
|
|
|
|
|
|
159
|
2
|
|
|
|
|
206
|
my ($type, $major, $minor) = @{$definition->{fix}}{qw/-type -major -minor/}; |
|
|
2
|
|
|
|
|
10
|
|
|
160
|
2
|
|
|
|
|
11
|
my $extension_id = join('.', $type, $major, $minor); |
|
161
|
2
|
|
|
|
|
5
|
my $protocol_id = $self->{id}; |
|
162
|
2
|
50
|
|
|
|
9
|
die("Extension ID ($extension_id) does not match Protocol ID ($protocol_id)") |
|
163
|
|
|
|
|
|
|
unless $extension_id eq $protocol_id; |
|
164
|
|
|
|
|
|
|
|
|
165
|
2
|
|
|
|
|
10
|
my $new_fields_lookup = $self->_construct_fields($definition); |
|
166
|
2
|
|
|
|
|
12
|
_merge_lookups($self->{fields_lookup}->{by_name}, $new_fields_lookup->{by_name}); |
|
167
|
2
|
|
|
|
|
9
|
_merge_lookups($self->{fields_lookup}->{by_number}, $new_fields_lookup->{by_number}); |
|
168
|
|
|
|
|
|
|
|
|
169
|
2
|
|
|
|
|
11
|
my $new_messsages_lookup = $self->_construct_messages($definition); |
|
170
|
2
|
|
|
|
|
11
|
_merge_lookups($self->{messages_lookup}->{by_name}, $new_messsages_lookup->{by_name}); |
|
171
|
2
|
|
|
|
|
10
|
_merge_lookups($self->{messages_lookup}->{by_number}, $new_messsages_lookup->{by_number}); |
|
172
|
|
|
|
|
|
|
|
|
173
|
2
|
|
|
|
|
24
|
return $self; |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head3 serialize_message |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
serialize_message($self, $message_name, $payload) |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Returns serialized string for the supplied C<$message_name> and C<$payload>. |
|
181
|
|
|
|
|
|
|
Dies in case of end-user (developer) error, e.g. if mandatory field is |
|
182
|
|
|
|
|
|
|
absent. |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub serialize_message { |
|
187
|
11
|
|
|
11
|
1
|
21526
|
my ($self, $message_name, $payload) = @_; |
|
188
|
11
|
|
|
|
|
30
|
my $message = $self->message_by_name($message_name); |
|
189
|
11
|
|
|
|
|
36
|
return $message->serialize($payload); |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head3 parse_message |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
parse_message($self, $buff_ref) |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
my ($message_instance, $error) = $protocol->parse($buff_ref); |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Tries to parse FIX message in the buffer refernce. |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
In the case of success it returns C and C<$error> is undef. |
|
201
|
|
|
|
|
|
|
The string in C<$buff_ref> will be consumed. |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
In the case of B, the C<$message_instance> will be undef, |
|
204
|
|
|
|
|
|
|
and C<$error> will contain the error description. The string in C<$buff_ref> |
|
205
|
|
|
|
|
|
|
will be kept untouched. |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
In the case, when there is no enough data in C<$buff_ref> both C<$error> |
|
208
|
|
|
|
|
|
|
and C<$message_instance> will be undef. The string in C<$buff_ref> |
|
209
|
|
|
|
|
|
|
will be kept untouched, i.e. waiting futher accumulation of bytes from |
|
210
|
|
|
|
|
|
|
network. |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
In other cases it dies; that indicates either end-user (developer) error |
|
213
|
|
|
|
|
|
|
or bug in the module. |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=cut |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
sub parse_message { |
|
218
|
124
|
|
|
124
|
1
|
205341
|
return Protocol::FIX::Parser::parse(@_); |
|
219
|
|
|
|
|
|
|
} |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub _construct_fields { |
|
222
|
9
|
|
|
9
|
|
28
|
my ($self, $definition) = @_; |
|
223
|
|
|
|
|
|
|
|
|
224
|
9
|
|
|
|
|
38
|
my $fields_lookup = { |
|
225
|
|
|
|
|
|
|
by_number => {}, |
|
226
|
|
|
|
|
|
|
by_name => {}, |
|
227
|
|
|
|
|
|
|
}; |
|
228
|
|
|
|
|
|
|
|
|
229
|
9
|
|
|
|
|
28
|
my $fields_arr = $definition->{fix}->{fields}->{field}; |
|
230
|
9
|
100
|
|
|
|
69
|
$fields_arr = [$fields_arr] if ref($fields_arr) ne 'ARRAY'; |
|
231
|
|
|
|
|
|
|
|
|
232
|
9
|
|
|
|
|
34
|
for my $field_descr (@$fields_arr) { |
|
233
|
6386
|
|
|
|
|
9216
|
my ($name, $number, $type) = map { $field_descr->{$_} } qw/-name -number -type/; |
|
|
19158
|
|
|
|
|
35618
|
|
|
234
|
6386
|
|
|
|
|
8538
|
my $values; |
|
235
|
6386
|
|
|
|
|
8413
|
my $values_arr = $field_descr->{value}; |
|
236
|
6386
|
100
|
|
|
|
10394
|
if ($values_arr) { |
|
237
|
1715
|
|
|
|
|
2888
|
for my $value_desc (@$values_arr) { |
|
238
|
11956
|
|
|
|
|
15753
|
my ($key, $description) = map { $value_desc->{$_} } qw/-enum -description/; |
|
|
23912
|
|
|
|
|
41475
|
|
|
239
|
11956
|
|
|
|
|
25481
|
$values->{$key} = $description; |
|
240
|
|
|
|
|
|
|
} |
|
241
|
|
|
|
|
|
|
} |
|
242
|
6386
|
|
|
|
|
12631
|
my $field = Protocol::FIX::Field->new($number, $name, $type, $values); |
|
243
|
6386
|
|
|
|
|
18881
|
$fields_lookup->{by_number}->{$number} = $field; |
|
244
|
6386
|
|
|
|
|
18337
|
$fields_lookup->{by_name}->{$name} = $field; |
|
245
|
|
|
|
|
|
|
} |
|
246
|
|
|
|
|
|
|
|
|
247
|
9
|
|
|
|
|
32
|
return $fields_lookup; |
|
248
|
|
|
|
|
|
|
} |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub _get_composites { |
|
251
|
4918
|
|
|
4918
|
|
9142
|
my ($values, $lookup) = @_; |
|
252
|
4918
|
100
|
|
|
|
9095
|
return () unless $values; |
|
253
|
|
|
|
|
|
|
|
|
254
|
2683
|
100
|
|
|
|
5770
|
my $array = ref($values) ne 'ARRAY' ? [$values] : $values; |
|
255
|
|
|
|
|
|
|
my @composites = map { |
|
256
|
2683
|
|
|
|
|
5428
|
my $ref = $_; |
|
|
22594
|
|
|
|
|
28188
|
|
|
257
|
22594
|
|
|
|
|
40812
|
my $name = $ref->{-name}; |
|
258
|
22594
|
|
|
|
|
34260
|
my $required = $ref->{-required} eq 'Y'; |
|
259
|
22594
|
|
|
|
|
42335
|
my $composite = $lookup->{by_name}->{$name}; |
|
260
|
|
|
|
|
|
|
|
|
261
|
22594
|
100
|
|
|
|
39151
|
die($name) unless $composite; |
|
262
|
|
|
|
|
|
|
|
|
263
|
22153
|
|
|
|
|
40257
|
($composite, $required); |
|
264
|
|
|
|
|
|
|
} @$array; |
|
265
|
2242
|
|
|
|
|
13374
|
return @composites; |
|
266
|
|
|
|
|
|
|
} |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
sub _construct_components { |
|
269
|
7
|
|
|
7
|
|
20
|
my ($self, $definition, $fields_lookup) = @_; |
|
270
|
|
|
|
|
|
|
|
|
271
|
7
|
|
|
|
|
22
|
my $components_lookup = { |
|
272
|
|
|
|
|
|
|
by_name => {}, |
|
273
|
|
|
|
|
|
|
}; |
|
274
|
|
|
|
|
|
|
|
|
275
|
7
|
|
|
|
|
16
|
my @components_queue = map { $_->{-type} = 'component'; $_; } @{$definition->{fix}->{components}->{component}}; |
|
|
728
|
|
|
|
|
1098
|
|
|
|
728
|
|
|
|
|
970
|
|
|
|
7
|
|
|
|
|
65
|
|
|
276
|
|
|
|
|
|
|
OUTER: |
|
277
|
7
|
|
|
|
|
75
|
while (my $component_descr = shift @components_queue) { |
|
278
|
1169
|
|
|
|
|
1572
|
my @composites; |
|
279
|
1169
|
|
|
|
|
1928
|
my $name = $component_descr->{-name}; |
|
280
|
|
|
|
|
|
|
|
|
281
|
1169
|
|
|
|
|
1485
|
my $fatal = 0; |
|
282
|
1169
|
|
|
|
|
1567
|
my $eval_result = eval { |
|
283
|
1169
|
|
|
|
|
2767
|
push @composites, _get_composites($component_descr->{component}, $components_lookup); |
|
284
|
|
|
|
|
|
|
|
|
285
|
1127
|
|
|
|
|
2498
|
my $group_descr = $component_descr->{group}; |
|
286
|
1127
|
100
|
|
|
|
1970
|
if ($group_descr) { |
|
287
|
1036
|
|
|
|
|
1312
|
my @group_composites; |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
# we might fail to construct group as dependent components might not be |
|
290
|
|
|
|
|
|
|
# constructed yet |
|
291
|
1036
|
|
|
|
|
1951
|
push @group_composites, _get_composites($group_descr->{component}, $components_lookup); |
|
292
|
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
# now we should be able to construct group |
|
294
|
637
|
|
|
|
|
999
|
$fatal = 1; |
|
295
|
637
|
|
|
|
|
1223
|
push @group_composites, _get_composites($group_descr->{field}, $fields_lookup); |
|
296
|
|
|
|
|
|
|
|
|
297
|
637
|
|
|
|
|
1293
|
my $group_name = $group_descr->{-name}; |
|
298
|
637
|
|
50
|
|
|
1689
|
my $base_field = $fields_lookup->{by_name}->{$group_name} |
|
299
|
|
|
|
|
|
|
// die("${group_name} refers field '${group_name}', which is not available"); |
|
300
|
637
|
|
|
|
|
1869
|
my $group = Protocol::FIX::Group->new($base_field, \@group_composites); |
|
301
|
|
|
|
|
|
|
|
|
302
|
637
|
|
|
|
|
1193
|
my $group_required = $group_descr->{-required} eq 'Y'; |
|
303
|
637
|
|
|
|
|
1870
|
push @composites, $group => $group_required; |
|
304
|
|
|
|
|
|
|
} |
|
305
|
728
|
|
|
|
|
1214
|
1; |
|
306
|
|
|
|
|
|
|
}; |
|
307
|
1169
|
100
|
|
|
|
2471
|
if (!$eval_result) { |
|
308
|
441
|
50
|
|
|
|
748
|
die("$@") if ($fatal); |
|
309
|
|
|
|
|
|
|
# not constructed yet, postpone current component construction |
|
310
|
441
|
|
|
|
|
648
|
push @components_queue, $component_descr; |
|
311
|
441
|
|
|
|
|
1062
|
next OUTER; |
|
312
|
|
|
|
|
|
|
} |
|
313
|
|
|
|
|
|
|
|
|
314
|
728
|
|
|
|
|
1010
|
$eval_result = eval { push @composites, _get_composites($component_descr->{field}, $fields_lookup); 1 }; |
|
|
728
|
|
|
|
|
1939
|
|
|
|
728
|
|
|
|
|
1445
|
|
|
315
|
728
|
50
|
|
|
|
1287
|
if (!$eval_result) { |
|
316
|
|
|
|
|
|
|
# make it human friendly |
|
317
|
0
|
|
|
|
|
0
|
die("Cannot find field '$@' referred by '$name'"); |
|
318
|
|
|
|
|
|
|
} |
|
319
|
|
|
|
|
|
|
|
|
320
|
728
|
|
|
|
|
1986
|
my $component = Protocol::FIX::Component->new($name, \@composites); |
|
321
|
728
|
|
|
|
|
3188
|
$components_lookup->{by_name}->{$name} = $component; |
|
322
|
|
|
|
|
|
|
} |
|
323
|
|
|
|
|
|
|
|
|
324
|
7
|
|
|
|
|
41
|
return $components_lookup; |
|
325
|
|
|
|
|
|
|
} |
|
326
|
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
sub _construct_composite { |
|
328
|
14
|
|
|
14
|
|
57
|
my ($self, $name, $descr, $fields_lookup, $components_lookup) = @_; |
|
329
|
|
|
|
|
|
|
|
|
330
|
14
|
|
|
|
|
33
|
my @composites; |
|
331
|
14
|
|
|
|
|
33
|
my $eval_result = eval { |
|
332
|
14
|
|
|
|
|
61
|
push @composites, _get_composites($descr->{field}, $fields_lookup); |
|
333
|
14
|
|
|
|
|
89
|
push @composites, _get_composites($descr->{component}, $components_lookup); |
|
334
|
14
|
|
|
|
|
44
|
1; |
|
335
|
|
|
|
|
|
|
}; |
|
336
|
14
|
50
|
|
|
|
57
|
if (!$eval_result) { |
|
337
|
0
|
|
|
|
|
0
|
die("Cannot find composite '$@', referred in '$name'"); |
|
338
|
|
|
|
|
|
|
} |
|
339
|
|
|
|
|
|
|
|
|
340
|
14
|
|
|
|
|
62
|
return Protocol::FIX::BaseComposite->new($name, $name, \@composites); |
|
341
|
|
|
|
|
|
|
} |
|
342
|
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
sub _construct_messages { |
|
344
|
9
|
|
|
9
|
|
33
|
my ($self, $definition) = @_; |
|
345
|
|
|
|
|
|
|
|
|
346
|
9
|
|
|
|
|
70
|
my $messages_lookup = { |
|
347
|
|
|
|
|
|
|
by_name => {}, |
|
348
|
|
|
|
|
|
|
by_number => {}, |
|
349
|
|
|
|
|
|
|
}; |
|
350
|
9
|
|
|
|
|
39
|
my $fields_lookup = $self->{fields_lookup}; |
|
351
|
9
|
|
|
|
|
19
|
my $components_lookup = $self->{components_lookup}; |
|
352
|
|
|
|
|
|
|
|
|
353
|
9
|
|
|
|
|
33
|
my $messages_arr = $definition->{fix}->{messages}->{message}; |
|
354
|
9
|
100
|
|
|
|
41
|
$messages_arr = [$messages_arr] unless ref($messages_arr) eq 'ARRAY'; |
|
355
|
|
|
|
|
|
|
|
|
356
|
9
|
|
|
|
|
143
|
my @messages_queue = @$messages_arr; |
|
357
|
9
|
|
|
|
|
41
|
while (my $message_descr = shift @messages_queue) { |
|
358
|
653
|
|
|
|
|
963
|
my @composites; |
|
359
|
653
|
|
|
|
|
1144
|
my ($name, $category, $message_type) = map { $message_descr->{$_} } qw/-name -msgcat -msgtype/; |
|
|
1959
|
|
|
|
|
5856
|
|
|
360
|
|
|
|
|
|
|
|
|
361
|
653
|
|
|
|
|
1209
|
my $eval_result = eval { |
|
362
|
653
|
|
|
|
|
1605
|
push @composites, _get_composites($message_descr->{field}, $fields_lookup); |
|
363
|
653
|
|
|
|
|
2174
|
push @composites, _get_composites($message_descr->{component}, $components_lookup); |
|
364
|
653
|
|
|
|
|
1322
|
1; |
|
365
|
|
|
|
|
|
|
}; |
|
366
|
653
|
50
|
|
|
|
1330
|
if (!$eval_result) { |
|
367
|
|
|
|
|
|
|
# make it human friendly |
|
368
|
0
|
|
|
|
|
0
|
die("Cannot find field '$@' referred by '$name'"); |
|
369
|
|
|
|
|
|
|
} |
|
370
|
|
|
|
|
|
|
|
|
371
|
653
|
|
|
|
|
1037
|
my $group_descr = $message_descr->{group}; |
|
372
|
|
|
|
|
|
|
# no need to protect with eval, as all fields/components should be availble. |
|
373
|
|
|
|
|
|
|
# if something is missing this is fatal |
|
374
|
653
|
100
|
|
|
|
1204
|
if ($group_descr) { |
|
375
|
7
|
|
|
|
|
20
|
my @group_composites; |
|
376
|
|
|
|
|
|
|
|
|
377
|
7
|
|
|
|
|
47
|
push @group_composites, _get_composites($group_descr->{component}, $components_lookup); |
|
378
|
7
|
|
|
|
|
36
|
push @group_composites, _get_composites($group_descr->{field}, $fields_lookup); |
|
379
|
|
|
|
|
|
|
|
|
380
|
7
|
|
|
|
|
36
|
my $group_name = $group_descr->{-name}; |
|
381
|
7
|
|
50
|
|
|
39
|
my $base_field = $fields_lookup->{by_name}->{$group_name} // die("${group_name} refers field '${group_name}', which is not available"); |
|
382
|
7
|
|
|
|
|
42
|
my $group = Protocol::FIX::Group->new($base_field, \@group_composites); |
|
383
|
|
|
|
|
|
|
|
|
384
|
7
|
|
|
|
|
34
|
my $group_required = $group_descr->{-required} eq 'Y'; |
|
385
|
7
|
|
|
|
|
24
|
push @composites, $group => $group_required; |
|
386
|
|
|
|
|
|
|
} |
|
387
|
|
|
|
|
|
|
|
|
388
|
653
|
|
|
|
|
2143
|
my $message = Protocol::FIX::Message->new($name, $category, $message_type, \@composites, $self); |
|
389
|
653
|
|
|
|
|
2322
|
$messages_lookup->{by_name}->{$name} = $message; |
|
390
|
653
|
|
|
|
|
4021
|
$messages_lookup->{by_number}->{$message_type} = $message; |
|
391
|
|
|
|
|
|
|
} |
|
392
|
|
|
|
|
|
|
|
|
393
|
9
|
|
|
|
|
55
|
return $messages_lookup; |
|
394
|
|
|
|
|
|
|
} |
|
395
|
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
sub _construct_from_definition { |
|
397
|
7
|
|
|
7
|
|
31
|
my ($self, $definition) = @_; |
|
398
|
|
|
|
|
|
|
|
|
399
|
7
|
|
|
|
|
19
|
my ($type, $major, $minor) = @{$definition->{fix}}{qw/-type -major -minor/}; |
|
|
7
|
|
|
|
|
39
|
|
|
400
|
7
|
|
|
|
|
31
|
my $protocol_id = join('.', $type, $major, $minor); |
|
401
|
|
|
|
|
|
|
|
|
402
|
7
|
|
|
|
|
29
|
my $fields_lookup = $self->_construct_fields($definition); |
|
403
|
7
|
|
|
|
|
53
|
my $components_lookup = $self->_construct_components($definition, $fields_lookup); |
|
404
|
|
|
|
|
|
|
|
|
405
|
7
|
|
|
|
|
53
|
my $header_descr = $definition->{fix}->{header}; |
|
406
|
7
|
|
|
|
|
21
|
my $trailer_descr = $definition->{fix}->{trailer}; |
|
407
|
7
|
|
|
|
|
38
|
my $header = $self->_construct_composite('header', $header_descr, $fields_lookup, $components_lookup); |
|
408
|
7
|
|
|
|
|
62
|
my $trailer = $self->_construct_composite('trailer', $trailer_descr, $fields_lookup, $components_lookup); |
|
409
|
|
|
|
|
|
|
|
|
410
|
7
|
|
|
|
|
56
|
my $serialized_begin_string = $fields_lookup->{by_name}->{BeginString}->serialize($protocol_id); |
|
411
|
|
|
|
|
|
|
|
|
412
|
7
|
|
|
|
|
70
|
$self->{id} = $protocol_id; |
|
413
|
7
|
|
|
|
|
32
|
$self->{header} = $header; |
|
414
|
7
|
|
|
|
|
18
|
$self->{trailer} = $trailer; |
|
415
|
7
|
|
|
|
|
22
|
$self->{fields_lookup} = $fields_lookup; |
|
416
|
7
|
|
|
|
|
30
|
$self->{components_lookup} = $components_lookup; |
|
417
|
7
|
|
|
|
|
18
|
$self->{begin_string} = $serialized_begin_string; |
|
418
|
|
|
|
|
|
|
|
|
419
|
7
|
|
|
|
|
30
|
my $messages_lookup = $self->_construct_messages($definition); |
|
420
|
7
|
|
|
|
|
47
|
$self->{messages_lookup} = $messages_lookup; |
|
421
|
|
|
|
|
|
|
|
|
422
|
7
|
|
|
|
|
30
|
return; |
|
423
|
|
|
|
|
|
|
} |
|
424
|
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
sub _merge_lookups { |
|
426
|
8
|
|
|
8
|
|
17
|
my ($old, $new) = @_; |
|
427
|
8
|
|
|
|
|
24
|
@{$old}{keys %$new} = values %$new; |
|
|
8
|
|
|
|
|
104
|
|
|
428
|
8
|
|
|
|
|
16
|
return; |
|
429
|
|
|
|
|
|
|
} |
|
430
|
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
=head1 METHODS (for protocol developers) |
|
432
|
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
=head3 humanize |
|
434
|
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
humanize ($buffer) |
|
436
|
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
Returns human-readable string for the buffer. I.e. is just substitutes |
|
438
|
|
|
|
|
|
|
L to " | ". |
|
439
|
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
This might be usable during development of own FIX-client/server. |
|
441
|
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
=cut |
|
443
|
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
sub humanize { |
|
445
|
25
|
|
|
25
|
1
|
148
|
my $s = shift; |
|
446
|
25
|
|
|
|
|
234
|
return $s =~ s/\x{01}/ | /gr; |
|
447
|
|
|
|
|
|
|
} |
|
448
|
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
=head3 is_composite |
|
450
|
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
is_composite($object) |
|
452
|
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
Checks whether the supplied C<$object> conforms "composte" concept. |
|
454
|
|
|
|
|
|
|
I.e. is it is L, L, L or L. |
|
455
|
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
=cut |
|
457
|
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
sub is_composite { |
|
459
|
39737
|
|
|
39737
|
1
|
51056
|
my $obj = shift; |
|
460
|
|
|
|
|
|
|
return |
|
461
|
|
|
|
|
|
|
defined($obj) |
|
462
|
|
|
|
|
|
|
&& UNIVERSAL::can($obj, 'serialize') |
|
463
|
|
|
|
|
|
|
&& exists $obj->{name} |
|
464
|
39737
|
|
33
|
|
|
242329
|
&& exists $obj->{type}; |
|
465
|
|
|
|
|
|
|
} |
|
466
|
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
=head3 field_by_name |
|
468
|
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
field_by_name($self, $field_name) |
|
470
|
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
Returns Field object by it's name or dies with error. |
|
472
|
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
=cut |
|
474
|
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
sub field_by_name { |
|
476
|
1988
|
|
|
1988
|
1
|
10303
|
my ($self, $field_name) = @_; |
|
477
|
1988
|
|
|
|
|
3815
|
my $field = $self->{fields_lookup}->{by_name}->{$field_name}; |
|
478
|
1988
|
50
|
|
|
|
3598
|
if (!$field) { |
|
479
|
0
|
|
|
|
|
0
|
die("Field '$field_name' is not available in protocol " . $self->{version}); |
|
480
|
|
|
|
|
|
|
} |
|
481
|
1988
|
|
|
|
|
4951
|
return $field; |
|
482
|
|
|
|
|
|
|
} |
|
483
|
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
=head3 field_by_number |
|
485
|
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
field_by_number($self, $field_number) |
|
487
|
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
Returns Field object by it's number or dies with error. |
|
489
|
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
=cut |
|
491
|
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
sub field_by_number { |
|
493
|
2
|
|
|
2
|
1
|
720
|
my ($self, $field_number) = @_; |
|
494
|
2
|
|
|
|
|
5
|
my $field = $self->{fields_lookup}->{by_number}->{$field_number}; |
|
495
|
2
|
50
|
|
|
|
7
|
if (!$field) { |
|
496
|
0
|
|
|
|
|
0
|
die("Field $field_number is not available in protocol " . $self->{version}); |
|
497
|
|
|
|
|
|
|
} |
|
498
|
2
|
|
|
|
|
6
|
return $field; |
|
499
|
|
|
|
|
|
|
} |
|
500
|
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
=head3 component_by_name |
|
502
|
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
component_by_name($self, $name) |
|
504
|
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
Returns Component object by it's name or dies with error. |
|
506
|
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
=cut |
|
508
|
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
sub component_by_name { |
|
510
|
11
|
|
|
11
|
1
|
3999
|
my ($self, $name) = @_; |
|
511
|
11
|
|
|
|
|
39
|
my $component = $self->{components_lookup}->{by_name}->{$name}; |
|
512
|
11
|
50
|
|
|
|
28
|
if (!$component) { |
|
513
|
0
|
|
|
|
|
0
|
die("Component '$name' is not available in protocol " . $self->{version}); |
|
514
|
|
|
|
|
|
|
} |
|
515
|
11
|
|
|
|
|
34
|
return $component; |
|
516
|
|
|
|
|
|
|
} |
|
517
|
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
=head3 message_by_name |
|
519
|
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
message_by_name($self, $name) |
|
521
|
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
Returns Message object by it's name or dies with error. |
|
523
|
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
=cut |
|
525
|
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
sub message_by_name { |
|
527
|
20
|
|
|
20
|
1
|
11823
|
my ($self, $name) = @_; |
|
528
|
20
|
|
|
|
|
61
|
my $message = $self->{messages_lookup}->{by_name}->{$name}; |
|
529
|
20
|
50
|
|
|
|
59
|
if (!$message) { |
|
530
|
0
|
|
|
|
|
0
|
die("Message '$name' is not available in protocol " . $self->{version}); |
|
531
|
|
|
|
|
|
|
} |
|
532
|
20
|
|
|
|
|
59
|
return $message; |
|
533
|
|
|
|
|
|
|
} |
|
534
|
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
=head3 header |
|
536
|
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
header($self) |
|
538
|
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
Returns Message's header |
|
540
|
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
=cut |
|
542
|
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
sub header { |
|
544
|
656
|
|
|
656
|
1
|
5327
|
return shift->{header}; |
|
545
|
|
|
|
|
|
|
} |
|
546
|
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
=head3 trailer |
|
548
|
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
trailer($self) |
|
550
|
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
Returns Message's trailer |
|
552
|
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
=cut |
|
554
|
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
sub trailer { |
|
556
|
656
|
|
|
656
|
1
|
7754
|
return shift->{trailer}; |
|
557
|
|
|
|
|
|
|
} |
|
558
|
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
=head3 id |
|
560
|
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
id($self) |
|
562
|
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
Returns Protocol's ID string, as it appears in FIX message (BeginString field). |
|
564
|
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
=cut |
|
566
|
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
sub id { |
|
568
|
1
|
|
|
1
|
1
|
1348
|
return shift->{id}; |
|
569
|
|
|
|
|
|
|
} |
|
570
|
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
=head3 managed_composites |
|
572
|
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
managed_composites() |
|
574
|
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
Returns list of fields, managed by protocol. Currently the list consists of |
|
576
|
|
|
|
|
|
|
fields: BeginString, MsgType, and CheckSum |
|
577
|
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
=cut |
|
579
|
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
sub managed_composites { |
|
581
|
34596
|
|
|
34596
|
1
|
93793
|
return \%MANAGED_COMPOSITES; |
|
582
|
|
|
|
|
|
|
} |
|
583
|
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
1; |