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