Permalink
Browse files

finish responses

  • Loading branch information...
1 parent 5007ea6 commit d72c8405075a540b27ce04ed68956fd4065a45eb @uwe committed May 5, 2012
View
3 TODO
@@ -0,0 +1,3 @@
+- consume $data
+- validation
+
View
1 ids.pl
@@ -9,6 +9,7 @@
list_ids('Request');
+print "\n";
list_ids('Response');
@@ -47,12 +47,7 @@ sub _lines {
sub _minimum_version { 1 }
sub _parse {
- my ($class, $version, $data) = @_;
-
- # check lines
- if (@$data < $class->_lines) {
- die \($class->_lines);
- }
+ my ($class, $version, $data, $lines) = @_;
my @meta = $class->_meta;
@@ -5,6 +5,8 @@ use warnings;
use base 'Protocol::TWS::Response';
+use Protocol::TWS::Util::Lines;
+
sub _id { 18 }
@@ -22,6 +24,11 @@ sub _lines { 30 }
sub _parse {
my ($class, $version, $data) = @_;
+ my $lines = Protocol::TWS::Util::Lines->new(
+ data => $data,
+ lines => $class->_lines,
+ );
+
my %data = (
id => $data->[0],
);
@@ -63,9 +70,7 @@ sub _parse {
my $sec_id_count = $data->[29];
if ($sec_id_count > 0) {
- if (@$data < 30 + 2 * $sec_id_count) {
- die \(2 * $sec_id_count);
- }
+ $lines->add(2 * $sec_id_count);
my %sec_id = ();
my $i = 30;
@@ -5,6 +5,8 @@ use warnings;
use base 'Protocol::TWS::Response';
+use Protocol::TWS::Util::Lines;
+
sub _id { 10 }
@@ -22,6 +24,11 @@ sub _lines { 30 }
sub _parse {
my ($class, $version, $data) = @_;
+ my $lines = Protocol::TWS::Util::Lines->new(
+ data => $data,
+ lines => $class->_lines,
+ );
+
my %data = (
id => $data->[0],
);
@@ -62,9 +69,7 @@ sub _parse {
my $sec_id_count = $data->[29];
if ($sec_id_count > 0) {
- if (@$data < 30 + 2 * $sec_id_count) {
- die \(2 * $sec_id_count);
- }
+ $lines->add(2 * $sec_id_count);
my %sec_id = ();
my $i = 30;
@@ -10,7 +10,7 @@ sub _id { 52 }
sub _meta {
return (
- reqId => 'int',
+ id => {alias => 'reqId'},
);
}
@@ -18,7 +18,7 @@ sub _meta {
sub _minimum_version { 9 }
-sub _lines { 22 }
+sub _lines { 27 }
sub _parse {
my ($class, $version, $data) = @_;
@@ -41,17 +41,22 @@ sub _parse {
);
my %execution = (
- orderId => $data->[1],
- execId => $data->[12],
- time => $data->[13],
- acctNumber => $data->[14],
- exchange => $data->[15],
- side => $data->[16],
- shares => $data->[17],
- price => $data->[18],
- permId => $data->[19],
- clientId => $data->[20],
- liquidation => $data->[21],
+ orderId => $data->[1],
+ execId => $data->[12],
+ time => $data->[13],
+ acctNumber => $data->[14],
+ exchange => $data->[15],
+ side => $data->[16],
+ shares => $data->[17],
+ price => $data->[18],
+ permId => $data->[19],
+ clientId => $data->[20],
+ liquidation => $data->[21],
+ cumQty => $data->[22],
+ avgPrice => $data->[23],
+ orderRef => $data->[24],
+ evRule => $data->[25],
+ evMultiplier => $data->[26],
);
$data{contract} = Protocol::TWS::Struct::Contract->new(%contract);
@@ -10,23 +10,52 @@ sub _id { 17 }
sub _meta {
return (
- reqId => 'tickerId',
- date => {},
- open => 'double',
- high => 'double',
- low => 'double',
- close => 'double',
- volume => 'int',
- barCount => 'int',
- WAP => 'double',
- hasGaps => 'int',
+ id => {alias => 'reqId'},
+ startDate => {},
+ endDate => {},
+ bars => {type => 'array', subtype => 'BarData'},
);
}
sub _lines { 4 }
sub _parse {
- die
+ my ($class, $version, $data) = @_;
+
+ my $lines = Protocol::TWS::Util::Lines->new(
+ data => $data,
+ lines => $class->_lines,
+ );
+
+ my %data = (
+ id => $data->[0],
+ startDate => $data->[1],
+ endDate => $data->[2],
+ );
+
+ if (my $bar_count = $data->[3]) {
+ $lines->add(9 * $bar_count);
+
+ my $i = 4;
+ my @bars = ();
+ foreach (1 .. $bar_count) {
+ my %bar_data = (
+ date => $data->[$i++],
+ open => $data->[$i++],
+ high => $data->[$i++],
+ low => $data->[$i++],
+ close => $data->[$i++],
+ volume => $data->[$i++],
+ average => $data->[$i++],
+ hasGaps => $data->[$i++],
+ barCount => $data->[$i++],
+ );
+ push @bars, Protocol::TWS::Struct::BarData->new(%bar_data);
+ }
+ $data{bars} = \@bars;
+ }
+
+ return $class->new(%data);
}
Oops, something went wrong.

0 comments on commit d72c840

Please sign in to comment.