| 1 | package FIX::Parser::FIX44; | ||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | sub new { | ||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | my ($class) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 9 | 2 | return bless {_buf => ''}, $class; | |||||||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | sub add { | ||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | my ($self, $data) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=7 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 14 | 3 | $self->{_buf} .= $data; | |||||||||||||||||||||||||||||||||
| 15 | 3 | my @msgs; | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | if ($self->{_len}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | return if $self->{_len} > length $self->{_buf}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 19 | 0 | push @msgs, parse_message(substr $self->{_buf}, 0, $self->{_len}, ''); | |||||||||||||||||||||||||||||||||
| 20 | 0 | delete $self->{_len}; | |||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | 3 | my $cnt = 0; | |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | 3 | ▶ | while ($self->{_buf} =~ s/^8=FIX.4.4\x{01}9=([0-9]+)\x{01}//) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 26 | 4 | $self->{_len} = $1 + 7; | |||||||||||||||||||||||||||||||||
| 27 | 4 | ▶ | return @msgs if $self->{_len} > length $self->{_buf}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 28 | 3 | push @msgs, parse_message(substr $self->{_buf}, 0, $self->{_len}, ''); | |||||||||||||||||||||||||||||||||
| 29 | 3 | delete $self->{_len}; | |||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | if (length $self->{_buf} > 14 | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
length $self->{"_buf"} > 14 and not $self->{"_buf"} =~ /^8=FIX.4.4\x{01}9=[0-9]/
MC/DC0%0/2
length $self->{"_buf"} > 14 and not $self->{"_buf"} =~ /^8=FIX.4.4\x{01}9=[0-9]/
length $self->{"_buf"} > 14
not $self->{"_buf"} =~ /^8=FIX.4.4\x{01}9=[0-9]/
Truth table33%1/3
A and not(B)
A= length $self->{"_buf"} > 14B= not $self->{"_buf"} =~ /^8=FIX.4.4\x{01}9=[0-9]/
| |||||||||||||||||||||||||||||||||||
| 33 | and $self->{_buf} !~ /^8=FIX.4.4\x{01}9=[0-9]/) | ||||||||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||||||||
| 35 | 0 | die "Invalid FIX message header: $self->{_buf}"; | |||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | 2 | return @msgs; | |||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | sub parse_message { | ||||||||||||||||||||||||||||||||||
| 42 | 3 | ▶ | my ($fix) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
parse_message: called CC=46 SCAR=61.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 43 | 3 | my @tags = map { [split /=/] } split /\x{01}/, $fix; | |||||||||||||||||||||||||||||||||
| 44 | 3 | ▶ | die "Message doesn't start with MsgType tag: $fix" unless $tags[0][0] == 35; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | 3 | my $message; | |||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | if ($tags[0][1] eq 'W') { | ||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||
| 48 | 3 | $message->{msg_type} = 'W'; | |||||||||||||||||||||||||||||||||
| 49 | 3 | ▶ | while (@tags and $tags[0][0] != 10) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@tags and $tags[0][0] != 10
MC/DC50%1/2
@tags and $tags[0][0] != 10
@tags
$tags[0][0] != 10
Truth table66%2/3
A and B
A= @tagsB= $tags[0][0] != 10
| |||||||||||||||||||||||||||||||||||
| 50 | 21 | my $tag = shift @tags; | |||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | 21 | my $symbol; | |||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | 21 | ▶ | if ($tag->[0] == 52) { | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 55 | 3 | $message->{msg_datetime} = $tag->[1]; | |||||||||||||||||||||||||||||||||
| 56 | } elsif ($tag->[0] == 55) { | ||||||||||||||||||||||||||||||||||
| 57 | 3 | $message->{symbol} = $tag->[1]; | |||||||||||||||||||||||||||||||||
| 58 | #$symbol = $tag->[1]; | ||||||||||||||||||||||||||||||||||
| 59 | } elsif ($tag->[0] == 268) { | ||||||||||||||||||||||||||||||||||
| 60 | 3 | my ($date, $time); | |||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | 3 | for (1 .. $tag->[1]) { | |||||||||||||||||||||||||||||||||
| 63 | 3 | my ($price, $bprice, $aprice, $type); | |||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | 3 | while (1) { | |||||||||||||||||||||||||||||||||
| 66 | 15 | my $tag = shift @tags; | |||||||||||||||||||||||||||||||||
| 67 | 15 | ▶ | if ($tag->[0] == 269) { | ||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||
| 68 | 6 | ▶ | $type = | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 69 | $tag->[1] eq '0' ? 'bid' | ||||||||||||||||||||||||||||||||||
| 70 | : $tag->[1] eq '1' ? 'ask' | ||||||||||||||||||||||||||||||||||
| 71 | : $tag->[1] eq 'H' ? 'mid' | ||||||||||||||||||||||||||||||||||
| 72 | : $tag->[1]; | ||||||||||||||||||||||||||||||||||
| 73 | } elsif ($tag->[0] == 55) { | ||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | die "symbols in different MDEntries do not match: $fix" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$symbol and $symbol ne $tag->[1]
MC/DC0%0/2
$symbol and $symbol ne $tag->[1]
$symbol
$symbol ne $tag->[1]
Truth table0%0/3
A and B
A= $symbolB= $symbol ne $tag->[1]
| |||||||||||||||||||||||||||||||||||
| 75 | if $symbol and $symbol ne $tag->[1]; | ||||||||||||||||||||||||||||||||||
| 76 | 0 | $symbol = $tag->[1]; | |||||||||||||||||||||||||||||||||
| 77 | } elsif ($tag->[0] == 270) { | ||||||||||||||||||||||||||||||||||
| 78 | 6 | $price = $tag->[1]; | |||||||||||||||||||||||||||||||||
| 79 | 6 | ▶ | if ($type eq 'bid') { $bprice = $price; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 80 | 6 | ▶ | if ($type eq 'ask') { $aprice = $price; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 81 | } elsif ($tag->[0] == 272) { | ||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | die "dates in differend MDEntries do not match: $fix" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$date and $date ne $tag->[1]
MC/DC0%0/2
$date and $date ne $tag->[1]
$date
$date ne $tag->[1]
Truth table0%0/3
A and B
A= $dateB= $date ne $tag->[1]
| |||||||||||||||||||||||||||||||||||
| 83 | if $date and $date ne $tag->[1]; | ||||||||||||||||||||||||||||||||||
| 84 | 0 | $date = $tag->[1]; | |||||||||||||||||||||||||||||||||
| 85 | } elsif ($tag->[0] == 273) { | ||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | die "times in differend MDEntries do not match: $fix" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$time and $time ne $tag->[1]
MC/DC0%0/2
$time and $time ne $tag->[1]
$time
$time ne $tag->[1]
Truth table0%0/3
A and B
A= $timeB= $time ne $tag->[1]
| |||||||||||||||||||||||||||||||||||
| 87 | if $time and $time ne $tag->[1]; | ||||||||||||||||||||||||||||||||||
| 88 | 0 | $time = $tag->[1]; | |||||||||||||||||||||||||||||||||
| 89 | ▶ | } elsif ($tag->[0] == 167 and $tag->[1] ne 'FXSPOT') { | |||||||||||||||||||||||||||||||||
|
Condition33%1/3
$tag->[0] == 167 and $tag->[1] ne "FXSPOT"
MC/DC0%0/2
$tag->[0] == 167 and $tag->[1] ne "FXSPOT"
$tag->[0] == 167
$tag->[1] ne "FXSPOT"
Truth table33%1/3
A and B
A= $tag->[0] == 167B= $tag->[1] ne "FXSPOT"
| |||||||||||||||||||||||||||||||||||
| 90 | 0 | die "expected FXSPOT in MDEntries but found $tag->[1]: $fix"; | |||||||||||||||||||||||||||||||||
| 91 | ▶ | } elsif ($tag->[0] == 279 or $tag->[0] == 10) { | |||||||||||||||||||||||||||||||||
|
Condition33%1/3
$tag->[0] == 279 or $tag->[0] == 10
MC/DC0%0/2
$tag->[0] == 279 or $tag->[0] == 10
$tag->[0] == 279
$tag->[0] == 10
Truth table33%1/3
A or B
A= $tag->[0] == 279B= $tag->[0] == 10
| |||||||||||||||||||||||||||||||||||
| 92 | 3 | last; | |||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||
| 95 | #end of while loop | ||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | 3 | ▶ | die "MDEntry doesn't have price or type: $fix" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $price and $type
MC/DC0%0/2
defined $price and $type
defined $price
$type
Truth table33%1/3
A and B
A= defined $priceB= $type
| |||||||||||||||||||||||||||||||||||
| 99 | unless defined $price and $type; | ||||||||||||||||||||||||||||||||||
| 100 | 3 | $message->{bid} = $bprice; | |||||||||||||||||||||||||||||||||
| 101 | 3 | $message->{ask} = $aprice; | |||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||
| 103 | 3 | last; | |||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | 3 | $message->{datetime} = $message->{msg_datetime}; | |||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||
| 112 | } elsif ($tags[0][1] eq '0') { | ||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||
| 114 | # Heartbeat | ||||||||||||||||||||||||||||||||||
| 115 | 0 | $message->{msg_type} = '0'; | |||||||||||||||||||||||||||||||||
| 116 | } elsif ($tags[0][1] eq '1') { | ||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||
| 118 | # Test request | ||||||||||||||||||||||||||||||||||
| 119 | 0 | $message->{msg_type} = '1'; | |||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | while (@tags and $tags[0][0] != 10) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@tags and $tags[0][0] != 10
MC/DC0%0/2
@tags and $tags[0][0] != 10
@tags
$tags[0][0] != 10
Truth table0%0/3
A and B
A= @tagsB= $tags[0][0] != 10
| |||||||||||||||||||||||||||||||||||
| 121 | 0 | my $tag = shift @tags; | |||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ($tag->[0] == 112) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 123 | 0 | $message->{test_req_id} = $tag->[1]; | |||||||||||||||||||||||||||||||||
| 124 | 0 | last; | |||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||
| 127 | } elsif ($tags[0][1] eq '2') { | ||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||
| 129 | # Resend request | ||||||||||||||||||||||||||||||||||
| 130 | 0 | $message->{msg_type} = '2'; | |||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | while (@tags and $tags[0][0] != 10) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@tags and $tags[0][0] != 10
MC/DC0%0/2
@tags and $tags[0][0] != 10
@tags
$tags[0][0] != 10
Truth table0%0/3
A and B
A= @tagsB= $tags[0][0] != 10
| |||||||||||||||||||||||||||||||||||
| 132 | 0 | my $tag = shift @tags; | |||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if ($tag->[0] == 7) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 134 | 0 | $message->{begin_seq_no} = $tag->[1]; | |||||||||||||||||||||||||||||||||
| 135 | } elsif ($tag->[0] == 16) { | ||||||||||||||||||||||||||||||||||
| 136 | 0 | $message->{end_seq_no} = $tag->[1]; | |||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||
| 139 | } elsif ($tags[0][1] eq 'A') { | ||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||
| 141 | # Logon message | ||||||||||||||||||||||||||||||||||
| 142 | 0 | $message->{msg_type} = 'A'; | |||||||||||||||||||||||||||||||||
| 143 | } elsif ($tags[0][1] eq '5') { | ||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||
| 145 | # Logout message | ||||||||||||||||||||||||||||||||||
| 146 | 0 | $message->{msg_type} = '5'; | |||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | while (@tags and $tags[0][0] != 10) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@tags and $tags[0][0] != 10
MC/DC0%0/2
@tags and $tags[0][0] != 10
@tags
$tags[0][0] != 10
Truth table0%0/3
A and B
A= @tagsB= $tags[0][0] != 10
| |||||||||||||||||||||||||||||||||||
| 148 | 0 | my $tag = shift @tags; | |||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if ($tag->[0] == 58) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 150 | 0 | $message->{logout_message} = $tag->[1]; | |||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||
| 153 | } else { | ||||||||||||||||||||||||||||||||||
| 154 | 0 | die "Don't know how to parse message of type $tags[0][1]: $fix"; | |||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||
| 157 | 3 | return $message; | |||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||
| 160 | sub make_message { | ||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | my ($self, $type, $sender_id, $target_id, @tags) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
make_message: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 162 | 0 | $self->{_seq}++; | |||||||||||||||||||||||||||||||||
| 163 | 0 | my $ts = strftime("%Y%m%d-%H:%M:%S.000", gmtime); | |||||||||||||||||||||||||||||||||
| 164 | 0 | my $msg = join "\x{01}", "35=$type", "49=$sender_id", "52=$ts", "56=$target_id", "34=$self->{_seq}", @tags, ''; | |||||||||||||||||||||||||||||||||
| 165 | 0 | my $len = length $msg; | |||||||||||||||||||||||||||||||||
| 166 | 0 | $msg = join "\x{01}", '8=FIX.4.4', "9=$len", $msg; | |||||||||||||||||||||||||||||||||
| 167 | 0 | my $sum = 0; | |||||||||||||||||||||||||||||||||
| 168 | 0 | $sum += ord $_ for split //, $msg; | |||||||||||||||||||||||||||||||||
| 169 | 0 | $sum %= 256; | |||||||||||||||||||||||||||||||||
| 170 | 0 | $msg .= '10=' . sprintf("%03d\x{01}", $sum); | |||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||
| 172 | 0 | return $msg; | |||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||
| 175 | 2 | 1; | |||||||||||||||||||||||||||||||||