From: Ian Jackson Date: Sun, 7 Jun 2009 21:58:19 +0000 (+0100) Subject: Better arbitrage display X-Git-Tag: 1.9.2~142 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.web-live.git;a=commitdiff_plain;h=01ec5abd4e3a712ddfc58e37e4bbc01a9b8493f5;ds=sidebyside Better arbitrage display --- diff --git a/pctb/yppsc-commod-processor b/pctb/yppsc-commod-processor index 92dbb0c..5e4e03d 100755 --- a/pctb/yppsc-commod-processor +++ b/pctb/yppsc-commod-processor @@ -91,8 +91,87 @@ sub bs_p_bestprice ($) { our $arbitrage_only= 0; sub main__arbitrage () { - $arbitrage_only= 1; - main__bestprices(); + my @arbs= (); + foreach $commod (sort keys %commod) { + $current= $commod{$commod}; + my @buys= @{ bs_p($commod,Buy, -1) }; + my @sells= @{ bs_p($commod,Sell,+1) }; + my $profit= 0; + my $cqty= 0; + my $info= ''; + my $arbs= []; + for (;;) { +#print Dumper($commod,\@buys,\@sells); + last unless @buys; + last unless @sells; + my $pricediff= $buys[0]{Price} - $sells[0]{Price}; + last unless $pricediff > 0; + our $qty= 1000; + sub arb_check_qty (\@) { + my ($verbs) = @_; + my $vqty= $verbs->[0]{Qty}; + return if $vqty =~ m/^\>/; + $qty= $vqty if $qty > $vqty; + return if $vqty; + my $verb= shift @$verbs; + } + arb_check_qty(@buys); + arb_check_qty(@sells); + next unless $qty; + my $tprofit= $qty*$pricediff; + $profit += $tprofit; + $cqty += $qty; + + $info.= + sprintf("%-13.13s| %-19.19s %4d| %-19.19s %4d|%3d x%3d =%3d\n", + $commod, + $buys[0]{Stall},$buys[0]{Price}, + $sells[0]{Stall},$sells[0]{Price}, + $qty, $pricediff, $tprofit); + sub arb_subtract_qty (\@) { + my ($verbs) = @_; + my $verb= shift @$verbs; + unshift @$verbs, { + Stall => $verb->{Stall}, + Price => $verb->{Price}, + Qty => $verb->{Qty} - $qty + }; + } + arb_subtract_qty(@buys); + arb_subtract_qty(@sells); + } + next unless $profit; + $info.= + sprintf("%-13.13s| %19s %4s| %19s %4s|%3d %4d\n", + $commod, '','', '','', $cqty, $profit); + push @arbs, { Profit => $profit, Info => $info }; + } + my $allprofit; + + return unless @arbs; + my $bigdiv= <{Profit} <=> $a->{Profit}; + } @arbs) { + print $div,$arb->{Info} or die $1; + $div= <{Profit}; + } + print $bigdiv or die $!; + printf("%-13.13s %19s %4s %19s %4s %-5s %7d\n", + '', '','', '','', 'TOTAL', $allprofit) + or die $!; } sub main__bestprices () { @@ -101,8 +180,6 @@ sub main__bestprices () { my $buys= bs_p($commod,Buy, -1); my $sells= bs_p($commod,Sell,+1); if ($arbitrage_only) { - next unless @$buys and @$sells; - next unless $buys->[0]{Price} > $sells->[0]{Price}; } printf("%-15.15s", $commod) or die $!; bs_p_bestprice($buys);