Bitcoin Forum
December 05, 2016, 02:34:06 AM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1] 2 »  All
  Print  
Author Topic: [code available] PHP & Perl Scripts to read mtgox .csv files!  (Read 2646 times)
2weiX
Legendary
*
Offline Offline

Activity: 1638


View Profile
July 23, 2012, 10:39:02 AM
 #1

I was looking for a script that would make it easy for my and my accountant to figure out what I had bought/sold/deposited/withdrawn/paidfees for a given time.

20BTC was bountied.

12.5 BTC went to the PHP script
7.5 BTC went to the Pearl scripts.

Please feel free to use them under the given license and consider tipping to contribute to my expenses.

Cheers
2weiX

The php code
Code:
<?php
/*
This code is available to you under CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/).

If you use this tool to analyze your mtgox trades or use this code to build your own project, consider
donating to 12weixK5ttMdjeoQgdGca9mKMKxkCxZkBG and consider adding your work to this thread:
https://bitcointalk.org/index.php?topic=94769

Thank you!
2weiX, Bitsky and jl2012
*/

if (isset($_FILES['csv'])) {
if ($_FILES['csv']['size']>1024000) { die('file too big'); }
if ($_FILES['csv']['error']!==0) { die('upload error'); }
if ($_FILES['csv']['name']=='history_EUR.csv') { $currency='€'; }
elseif ($_FILES['csv']['name']=='history_USD.csv') { $currency='$'; }
else { $currency=''; }
$csv=file($_FILES['csv']['tmp_name'], FILE_IGNORE_NEW_LINES);
$out=parsecsv($csv);
$tmp=makecsv($out$currency);
header('Content-type: text/plain');
header('Content-disposition: attachment; filename="converted_'.$_FILES['csv']['name'].'"');
echo $tmp;
}
else {
echo "<html>\n";
echo "<body>\n";
echo "<form method=\"post\" action=\"\" enctype=\"multipart/form-data\">\n";
echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"1024000\" />\n";
echo "<input type=\"file\" name=\"csv\" value=\"\" accept=\"text/*\" />\n";
echo "<input type=\"submit\" value=\"Convert\" />\n";
echo "</form>\n";
echo "</body>\n";
echo "</html>\n";
}

exit;

function 
parsecsv($csv) {
global $currency;
$regex=array();
$regex['$']='/\] ([\d\.]+).+BTC at \$([\d\.]+)/';
$regex['€']='/\] ([\d\.]+).+BTC at ([\d\.]+)/';
$out=array();
foreach ($csv as $tmp) {
$line=explode(','$tmp);
if (!is_numeric($line[0])) { continue; }
$line[1]=preg_replace('/"(.+) .*/''$1'$line[1]);
if (!isset($out[$line[1]])) {
$out[$line[1]]=array();
$out[$line[1]]['day']=$line[1];
$out[$line[1]]['deposit']=0;
$out[$line[1]]['withdraw']=0;
$out[$line[1]]['earned']=0;
$out[$line[1]]['earnedbtc']=0;
$out[$line[1]]['earnedcur']=0;
$out[$line[1]]['earnedrate']=0;
$out[$line[1]]['fee']=0;
$out[$line[1]]['spent']=0;
$out[$line[1]]['spentbtc']=0;
$out[$line[1]]['spentcur']=0;
$out[$line[1]]['spentrate']=0;
}
if ($line[2]=='deposit') { $out[$line[1]]['deposit']+=$line[4]; }
elseif ($line[2]=='withdraw') { $out[$line[1]]['withdraw']+=$line[4]; }
elseif ($line[2]=='fee') { $out[$line[1]]['fee']+=$line[4]; }
elseif ($line[2]=='earned') {
$out[$line[1]]['earned']+=$line[4];
if (preg_match($regex[$currency], $line[3], $tmp)) {
$out[$line[1]]['earnedbtc']+=$tmp[1];
$out[$line[1]]['earnedcur']+=$line[4];
}
}
elseif ($line[2]=='spent') {
$out[$line[1]]['spent']+=$line[4];
if (preg_match($regex[$currency], $line[3], $tmp)) {
$out[$line[1]]['spentbtc']+=$tmp[1];
$out[$line[1]]['spentcur']+=$line[4];
}
}
}
return($out);
}

function 
makecsv($out$currency) {
$tmp='';
global $currency;
foreach ($out as $i) {
if ($i['spentcur']>0) { $i['spentrate']=$i['spentcur']/$i['spentbtc']; }
if ($i['earnedbtc']>0) { $i['earnedrate']=$i['earnedcur']/$i['earnedbtc']; }
$i['day']=preg_replace('/(\d\d\d\d)\-(\d\d)\-(\d\d)/''$3.$2.$1'$i['day']);
$tmp.=$i['day'].";DEPOSIT;".number_format($i['deposit'], 2',''').$currency."\n";
$tmp.=$i['day'].";BUY;".number_format($i['spentbtc'], 8',''')."BTC;".number_format($i['spentrate'], 8',''').$currency."/BTC\n";
$tmp.=$i['day'].";SELL;".number_format($i['earnedbtc'], 8',''')."BTC;".number_format($i['earnedrate'], 8',''').$currency."/BTC\n";
$tmp.=$i['day'].";FEES;".number_format($i['fee'], 2',''').$currency."\n";
$tmp.=$i['day'].";WITHDRAW;-".number_format($i['withdraw'], 2',''').$currency."\n";
$tmp.="\n\n";
}
$tmp.="This code is available to you under CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/).\n\n";
$tmp.="If you use this tool to analyze your mtgox trades or use this code to build your own project, consider\n";
$tmp.="donating to 12weixK5ttMdjeoQgdGca9mKMKxkCxZkBG and consider adding your work to this thread:\n";
$tmp.="https://bitcointalk.org/index.php?topic=94769\n\n";
$tmp.="Thank you!\n";
$tmp.="2weiX, Bitsky and jl2012\n";
return($tmp);
}

?>


Pearl code for EUR
Code:
#!/usr/bin/perl
use strict;
open USD, "history_EUR.csv";
open OUTCSV, ">goxeur.csv";
open OUTCSVE, ">goxeur_e.csv";
my %array;
#my @type = ("deposit", "withdraw", "earned", "spent", "fee");
while (<USD>) {
my ($date, $type, $info, $value, $balance) = ($_ =~ /^\d+,\"(\d{4}-\d{2}-\d{2}) .+?\",(.+?),(.+?),(.+?),(.+)/);
$date || next;
if (my ($x, $y) = $value =~ /(.*)E(.*)/) {
$value = $x * (10 ** $y);
}
$array{$date}{$type} += $value;
$array{$date}{balance} = $balance;
if ($type eq "spent") {
my ($btc, $price) = ($info =~ /(\d+\.\d+).*?BTC at \$?(\d+\.\d+)/);
$array{$date}{totalspent} += $value;
$array{$date}{totalboughtbtc} += $btc;
}
elsif ($type eq "earned") {
my ($btc, $price) = ($info =~ /(\d+\.\d+).*?BTC at \$?(\d+\.\d+)/);
                $array{$date}{totalreceive} += $value;
$array{$date}{totalsoldbtc} += $btc;
        }
}
foreach (sort keys %array) {

if ($array{$_}{deposit} > 0) {
print OUTCSV "\"$_\",\"DEPOSIT\",\"". sprintf("%.8f", $array{$_}{deposit}) . " EUR\"\n";
}
        if ($array{$_}{withdraw} > 0) {
                print OUTCSV "\"$_\",\"WITHDRAW\",\"". sprintf("%.8f", $array{$_}{withdraw}) . " EUR\"\n";
        }
        if ($array{$_}{fee} > 0) {
                print OUTCSV "\"$_\",\"FEES\",\"". sprintf("%.8f", $array{$_}{fee}) . " EUR\"\n";
        }
        if ($array{$_}{totalboughtbtc} > 0) {
                print OUTCSV "\"$_\",\"BUY\",\"". sprintf("%.8f", $array{$_}{totalboughtbtc}) . " BTC\",\"". $array{$_}{totalspent}/$array{$_}{totalboughtbtc} ." EUR\"\n";
        }
        if ($array{$_}{totalsoldbtc} > 0) {
                print OUTCSV "\"$_\",\"SELL\",\"". sprintf("%.8f", $array{$_}{totalsoldbtc}) . " BTC\",\"". $array{$_}{totalreceive}/$array{$_}{totalsoldbtc} ." EUR\"\n";
        }
}
close OUTCSV;
open OUTCSV, "goxeur.csv";
while (<OUTCSV>) {
s/\./,/g;
print OUTCSVE;
}

Parl code for USD
Code:
#!/usr/bin/perl
use strict;
open USD, "history_USD.csv";
open OUTCSV, ">goxusd.csv";
open OUTCSVE, ">goxusd_e.csv";
my %array;
#my @type = ("deposit", "withdraw", "earned", "spent", "fee");
while (<USD>) {
my ($date, $type, $info, $value, $balance) = ($_ =~ /^\d+,\"(\d{4}-\d{2}-\d{2}) .+?\",(.+?),(.+?),(.+?),(.+)/);
$date || next;
if (my ($x, $y) = $value =~ /(.*)E(.*)/) {
$value = $x * (10 ** $y);
}
$array{$date}{$type} += $value;
$array{$date}{balance} = $balance;
if ($type eq "spent") {
my ($btc, $price) = ($info =~ /(\d+\.\d+).*?BTC at \$?(\d+\.\d+)/);
$array{$date}{totalspent} += $value;
$array{$date}{totalboughtbtc} += $btc;
}
elsif ($type eq "earned") {
my ($btc, $price) = ($info =~ /(\d+\.\d+).*?BTC at \$?(\d+\.\d+)/);
                $array{$date}{totalreceive} += $value;
$array{$date}{totalsoldbtc} += $btc;
        }
}
foreach (sort keys %array) {

if ($array{$_}{deposit} > 0) {
print OUTCSV "\"$_\",\"DEPOSIT\",\"". sprintf("%.8f", $array{$_}{deposit}) . " USD\"\n";
}
        if ($array{$_}{withdraw} > 0) {
                print OUTCSV "\"$_\",\"WITHDRAW\",\"". sprintf("%.8f", $array{$_}{withdraw}) . " USD\"\n";
        }
        if ($array{$_}{fee} > 0) {
                print OUTCSV "\"$_\",\"FEES\",\"". sprintf("%.8f", $array{$_}{fee}) . " USD\"\n";
        }
        if ($array{$_}{totalboughtbtc} > 0) {
                print OUTCSV "\"$_\",\"BUY\",\"". sprintf("%.8f", $array{$_}{totalboughtbtc}) . " BTC\",\"". $array{$_}{totalspent}/$array{$_}{totalboughtbtc} ." USD\"\n";
        }
        if ($array{$_}{totalsoldbtc} > 0) {
                print OUTCSV "\"$_\",\"SELL\",\"". sprintf("%.8f", $array{$_}{totalsoldbtc}) . " BTC\",\"". $array{$_}{totalreceive}/$array{$_}{totalsoldbtc} ." USD\"\n";
        }
}
close OUTCSV;
open OUTCSV, "goxusd.csv";
while (<OUTCSV>) {
s/\./,/g;
print OUTCSVE;
}
1480905246
Hero Member
*
Offline Offline

Posts: 1480905246

View Profile Personal Message (Offline)

Ignore
1480905246
Reply with quote  #2

1480905246
Report to moderator
1480905246
Hero Member
*
Offline Offline

Posts: 1480905246

View Profile Personal Message (Offline)

Ignore
1480905246
Reply with quote  #2

1480905246
Report to moderator
Once a transaction has 6 confirmations, it is extremely unlikely that an attacker without at least 50% of the network's computation power would be able to reverse it.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1480905246
Hero Member
*
Offline Offline

Posts: 1480905246

View Profile Personal Message (Offline)

Ignore
1480905246
Reply with quote  #2

1480905246
Report to moderator
jl2012
Legendary
*
Offline Offline

Activity: 1484


View Profile
July 23, 2012, 10:46:31 AM
 #2

I can do a perl script for you. You can host it like a php, with upload and export feature you want

Donation address: 1CiZPrEJdN4FJcqdLdgVLzT8tgCXxT5ion
PGP: D3CC 1772 8600 5BB8 FF67 3294 C524 2A1A B393 6517
Bitcoin Wizards Wiki: https://8333.info/
2weiX
Legendary
*
Offline Offline

Activity: 1638


View Profile
July 23, 2012, 10:49:43 AM
 #3

I can do a perl script for you. You can host it like a php, with upload and export feature you want

so i can up a .csv and it will export a .csv for me to download?
how much time (BTC in bounty) will this take?


kinda need it to calculate profit/losses for tax reasons.

oh, and the fees paid need to be in it.
2weiX
Legendary
*
Offline Offline

Activity: 1638


View Profile
July 23, 2012, 10:54:52 AM
 #4

http://daiber.net/mtgox.rar

three example file

EUR
USD
BTC
Rugatu
Full Member
***
Offline Offline

Activity: 182



View Profile WWW
July 23, 2012, 12:27:15 PM
 #5

the files that i can export from my mtgox account that are supposed to give me a clear image of what I have traded, deposited, withdrawn and paid as fees are close to unusable to me. not only do i use a different format for my 1000 and decimals (1.200,75 instead of 1,200.75), but also there's no way I am manually adding all those millibitcoins that i traded to make total for the day




i am looking for the following:

a script that takes the .csv as-is and automatically

- detects the currency
- makes a total for EACH DAY displaying
-- bought @ average price
-- sold @ average price
-- fees paid
-- deposited
-- withdrawn
-- 24avg bitcoin price


Code:
01/01/2012, +5000, 7,25€
01/01/2012, withdraw, 1000  BTC
01/01/2012, deposit, 10000 €
02/05/2012, -2000, 8,58€
....

...this is the best i can describe it. any questions?
also I am undecided as to how high the bounty should be.

if its a php script and you would include an upload and export feature, i would gladly host it.

Hi, you can try making a new bounty on Rugatu and see what you get.

Have any questions? Q&A with BTCitcoins on Rugatu
gweedo
Legendary
*
Offline Offline

Activity: 1246


Java, PHP, HTML/CSS Programmer for Hire!


View Profile WWW
July 23, 2012, 08:40:31 PM
 #6

I can do this in php as a command line or web script

Want to earn 2500 SATOSHIS per hour? Come Chat and Chill in https://goseemybits.com/lobby
2weiX
Legendary
*
Offline Offline

Activity: 1638


View Profile
July 24, 2012, 05:39:09 AM
 #7

i did get a first reply, will test the result now.
if i like it, i will publish the script for anyone to work on it.
2weiX
Legendary
*
Offline Offline

Activity: 1638


View Profile
July 24, 2012, 06:18:41 AM
 #8

So far I have gotten a number of responses.
None have gotten "it" right so far, so there is still a chance :-D
2weiX
Legendary
*
Offline Offline

Activity: 1638


View Profile
July 24, 2012, 07:20:18 AM
 #9

here's a script user gweedo kindly sent to me. he allowed me to post it - if it leads to the solution, he says, he'd like to have half the bounty :-D


Code:
#!/usr/bin/php
<?php
$file_handle 
fopen($argv[1], "r");
$array= array();
$replace = array("$",".",",");
while(!
feof($file_handle)) {
$line_of_text fgetcsv($file_handle1024);
if(
$line_of_text[0]!="Index"){
$temparray=explode(' ',$line_of_text[1]);
$date=$temparray[0];
if(!in_array($date$temparray)){
$array[$date]=array();
}
if($array[$date][$line_of_text[2]]!==null){
$temp=$array[$date][$line_of_text[2]];
$array[$date][$line_of_text[2]]=$temp+floatval(str_replace($replace,"",trim($line_of_text[4])));
}else{
$array[$date][$line_of_text[2]]=floatval(str_replace($replace,"",trim($line_of_text[4])));
}
}
}
fclose($file_handle);
foreach (
$array as $key=>$value){
if($key==null){
break;
}
$total=0.00;
$total=+$value['despoit']-$value['withdraw']+$value['in']-$value['out'];
echo $key.' Total: '.$total."\n";
if($value['despoit']!==null){
echo $key.' Despoit '.$value['despoit']."\n";
}
if($value['withdraw']!==null){
echo $key.' Withdrew '.$value['withdraw']."\n";
}
}
?>
2weiX
Legendary
*
Offline Offline

Activity: 1638


View Profile
July 24, 2012, 09:06:10 AM
 #10

after much deliberation, i need the file for each currency to read


DATE; depositedCurreny
DATE; boughtBTC; avgPrice
DATE; soldBTC; avgPrice
DATE; feesPAID
DATE; withdrawnCurrency

whereas
"boughtBTC" should be positive
"soldBTC" is a negative number

2weiX
Legendary
*
Offline Offline

Activity: 1638


View Profile
July 24, 2012, 09:53:58 AM
 #11

obv the above makes no sense when working with headers, so here:

DATE;DEPOSIT;amountdepositCurrency
DATE;BUY;boughtBTC;avgPriceCurrency
DATE;SELL;soldBTC;avgPriceCurrency
DATE;FEES;feespaid
DATE;WITHDRAW;amountwithdrawnCurrency


2weiX
Legendary
*
Offline Offline

Activity: 1638


View Profile
July 24, 2012, 10:43:56 AM
 #12

two people pretty much nailed it.
i'd say that some modifications pending both are eligible for the reward.


i'd like to host both in a html file on my server so i can make them publicly available.
if both of you could provide upload and export functionality so i everyone can use this?

aside: i dunno if my webspace (bitcoinsinberlin.com) runs perl, actually.
2weiX
Legendary
*
Offline Offline

Activity: 1638


View Profile
July 25, 2012, 02:15:33 PM
 #13

task done, bounty awarded.
Bitsky
Hero Member
*****
Offline Offline

Activity: 542


View Profile
July 26, 2012, 03:05:50 PM
 #14

Bounty received.
Nice guy to work with and he paid promptly too.

Bounty: Earn up to 68.7 BTC
Like my post? Feel free to drop a tip to 1BitskyZbfR4irjyXDaGAM2wYKQknwX36Y
paraipan
Legendary
*
Offline Offline

Activity: 924


Firstbits: 1pirata


View Profile WWW
July 26, 2012, 03:51:25 PM
 #15

Bounty received.
Nice guy to work with and he paid promptly too.

Witnessed

BTCitcoin: An Idea Worth Saving - Q&A with bitcoins on rugatu.com - Check my rep
jl2012
Legendary
*
Offline Offline

Activity: 1484


View Profile
July 27, 2012, 08:54:59 AM
 #16

Bounty received. Thanks! I'll continue to develop the web interface for it

Donation address: 1CiZPrEJdN4FJcqdLdgVLzT8tgCXxT5ion
PGP: D3CC 1772 8600 5BB8 FF67 3294 C524 2A1A B393 6517
Bitcoin Wizards Wiki: https://8333.info/
paraipan
Legendary
*
Offline Offline

Activity: 924


Firstbits: 1pirata


View Profile WWW
July 27, 2012, 09:55:23 AM
 #17

Bounty received. Thanks! I'll continue to develop the web interface for it

Quoted for posterity...

BTCitcoin: An Idea Worth Saving - Q&A with bitcoins on rugatu.com - Check my rep
2weiX
Legendary
*
Offline Offline

Activity: 1638


View Profile
July 30, 2012, 08:38:12 AM
 #18

codes posted
2weiX
Legendary
*
Offline Offline

Activity: 1638


View Profile
December 13, 2012, 07:52:40 AM
 #19

Bounty received. Thanks! I'll continue to develop the web interface for it

how's that goin' ? :-D
2weiX
Legendary
*
Offline Offline

Activity: 1638


View Profile
December 13, 2012, 02:05:36 PM
 #20



if someone was willing to host this (it's a perl script), i'd be awesomely happy.


Code:
#!/usr/bin/perl
use strict;
use CGI;
open BTC, "history_BTC.csv";
my %array;
#my @type = ("deposit", "withdraw", "in", "out", "fee");
if ($ENV{'REQUEST_METHOD'} eq "GET") {
        print "Content-Type: text/html\n\n<HTML><BODY><FORM method=\"post\" enctype=\"multipart/form-data\">Choose File To Upload (Total Max: 2M):<BR>BTC:<INPUT type=\"file\" name=\"btc\"><BR>USD:<INPUT type=\"file\" name=\"usd\"><BR>EUR:<INPUT type=\"file\" name=\"eur\"><BR><input type=\"submit\" value=\"Upload\"></form></body></html>";
}
else{
$CGI::POST_MAX = 1024 * 2048;
my $query = new CGI;
my $btc = $query->upload("btc");
my $usd = $query->upload("usd");
my $eur = $query->upload("eur");
print "Content-Type: text/html\n\n<HTML><BODY>BTC:<BR>";
while (<$btc>) {
        my ($date, $type, $info, $value, $balance) = ($_ =~ /^\d+,\"(\d{4}-\d{2}-\d{2}) .+?\",(.+?),(.+?),(.+?),(.+)/);
        $date || next;
        if (my ($x, $y) = $value =~ /(.*)E(.*)/) {
                $value = $x * (10 ** $y);
        }
        $array{$date}{$type} += $value;
        $array{$date}{balance} = $balance;
        if ($type eq "in") {
                my ($price) = ($info =~ /at \$?(\d+\.\d+)/);
                if ($info =~ /\$/) {
                        $array{$date}{totalspentusd} += ($price * $value);
                        $array{$date}{totalboughtwithusd} += $value;
                }
                else {
                        $array{$date}{totalspenteur} += ($price * $value);
                        $array{$date}{totalboughtwitheur} += $value;
                }
        }
        elsif ($type eq "out") {
                my ($price) = ($info =~ /at \$?(\d+\.\d+)/);
                if ($info =~ /\$/) {
                        $array{$date}{totalreceiveusd} += ($price * $value);
                        $array{$date}{totalsoldforusd} += $value;
                }
                else {
                        $array{$date}{totalreceiveeur} += ($price * $value);
                        $array{$date}{totalsoldforeur} += $value;
                }
        }
}


foreach (sort keys %array) {
        if ($array{$_}{deposit} > 0) {
                print "\"$_\",\"DEPOSIT\",\"". sprintf("%.8f", $array{$_}{deposit})."\"<BR>\n";
        }
        if ($array{$_}{withdraw} > 0) {
                print "\"$_\",\"WITHDRAW\",\"". sprintf("%.8f", $array{$_}{withdraw})."\"<BR>\n";
        }
        if ($array{$_}{fee} > 0) {
                print "\"$_\",\"FEES\",\"". sprintf("%.8f", $array{$_}{fee})."\"<BR>\n";
        }
        if ($array{$_}{totalboughtwithusd} > 0) {
                print "\"$_\",\"BUY\",\"". sprintf("%.8f", $array{$_}{totalboughtwithusd})."\",\"". $array{$_}{totalspentusd}/$array{$_}{totalboughtwithusd} ." USD\"<BR>\n";
        }
        if ($array{$_}{totalboughtwitheur} > 0) {
                print "\"$_\",\"BUY\",\"". sprintf("%.8f", $array{$_}{totalboughtwitheur})."\",\"". $array{$_}{totalspenteur}/$array{$_}{totalboughtwitheur} ." EUR\"<BR>\n";
        }
        if ($array{$_}{totalsoldforusd} > 0) {
                print "\"$_\",\"SELL\",\"". sprintf("%.8f", $array{$_}{totalsoldforusd})."\",\"". $array{$_}{totalreceiveusd}/$array{$_}{totalsoldforusd} ." USD\"<BR>\n";
        }
        if ($array{$_}{totalsoldforeur} > 0) {
                print "\"$_\",\"SELL\",\"". sprintf("%.8f", $array{$_}{totalsoldforeur})."\",\"". $array{$_}{totalreceiveeur}/$array{$_}{totalsoldforeur} ." EUR\"<BR>\n";
        }
}
for (keys %array)
    {
        delete $array{$_};
    }
print "<BR><BR>USD:<BR>";
while (<$usd>) {
        my ($date, $type, $info, $value, $balance) = ($_ =~ /^\d+,\"(\d{4}-\d{2}-\d{2}) .+?\",(.+?),(.+?),(.+?),(.+)/);
        $date || next;
        if (my ($x, $y) = $value =~ /(.*)E(.*)/) {
                $value = $x * (10 ** $y);
        }
        $array{$date}{$type} += $value;
        $array{$date}{balance} = $balance;
        if ($type eq "spent") {
                my ($btc, $price) = ($info =~ /(\d+\.\d+).*?BTC at \$?(\d+\.\d+)/);
                $array{$date}{totalspent} += $value;
                $array{$date}{totalboughtbtc} += $btc;
        }
        elsif ($type eq "earned") {
                my ($btc, $price) = ($info =~ /(\d+\.\d+).*?BTC at \$?(\d+\.\d+)/);
                $array{$date}{totalreceive} += $value;
                $array{$date}{totalsoldbtc} += $btc;
        }
}
foreach (sort keys %array) {

        if ($array{$_}{deposit} > 0) {
                print "\"$_\",\"DEPOSIT\",\"". sprintf("%.8f", $array{$_}{deposit}) . " USD\"<BR>\n";
        }
        if ($array{$_}{withdraw} > 0) {
                print "\"$_\",\"WITHDRAW\",\"". sprintf("%.8f", $array{$_}{withdraw}) . " USD\"<BR>\n";
        }
        if ($array{$_}{fee} > 0) {
                print "\"$_\",\"FEES\",\"". sprintf("%.8f", $array{$_}{fee}) . " USD\"<BR>\n";
        }
        if ($array{$_}{totalboughtbtc} > 0) {
                print "\"$_\",\"BUY\",\"". sprintf("%.8f", $array{$_}{totalboughtbtc}) . " BTC\",\"". $array{$_}{totalspent}/$array{$_}{totalboughtbtc} ." USD\"<BR>\n";
        }
        if ($array{$_}{totalsoldbtc} > 0) {
                print "\"$_\",\"SELL\",\"". sprintf("%.8f", $array{$_}{totalsoldbtc}) . " BTC\",\"". $array{$_}{totalreceive}/$array{$_}{totalsoldbtc} ." USD\"<BR>\n";
        }
}
for (keys %array)
    {
        delete $array{$_};
    }
print "<BR><BR>EUR:<BR>";
while (<$eur>) {
        my ($date, $type, $info, $value, $balance) = ($_ =~ /^\d+,\"(\d{4}-\d{2}-\d{2}) .+?\",(.+?),(.+?),(.+?),(.+)/);
        $date || next;
        if (my ($x, $y) = $value =~ /(.*)E(.*)/) {
                $value = $x * (10 ** $y);
        }
        $array{$date}{$type} += $value;
        $array{$date}{balance} = $balance;
        if ($type eq "spent") {
                my ($btc, $price) = ($info =~ /(\d+\.\d+).*?BTC at \$?(\d+\.\d+)/);
                $array{$date}{totalspent} += $value;
                $array{$date}{totalboughtbtc} += $btc;
        }
        elsif ($type eq "earned") {
                my ($btc, $price) = ($info =~ /(\d+\.\d+).*?BTC at \$?(\d+\.\d+)/);
                $array{$date}{totalreceive} += $value;
                $array{$date}{totalsoldbtc} += $btc;
        }
}
foreach (sort keys %array) {

        if ($array{$_}{deposit} > 0) {
                print "\"$_\",\"DEPOSIT\",\"". sprintf("%.8f", $array{$_}{deposit}) . " EUR\"<BR>\n";
        }
        if ($array{$_}{withdraw} > 0) {
                print "\"$_\",\"WITHDRAW\",\"". sprintf("%.8f", $array{$_}{withdraw}) . " EUR\"<BR>\n";
        }
        if ($array{$_}{fee} > 0) {
                print "\"$_\",\"FEES\",\"". sprintf("%.8f", $array{$_}{fee}) . " EUR\"<BR>\n";
        }
        if ($array{$_}{totalboughtbtc} > 0) {
                print "\"$_\",\"BUY\",\"". sprintf("%.8f", $array{$_}{totalboughtbtc}) . " BTC\",\"". $array{$_}{totalspent}/$array{$_}{totalboughtbtc} ." EUR\"<BR>\n";
        }
        if ($array{$_}{totalsoldbtc} > 0) {
                print "\"$_\",\"SELL\",\"". sprintf("%.8f", $array{$_}{totalsoldbtc}) . " BTC\",\"". $array{$_}{totalreceive}/$array{$_}{totalsoldbtc} ." EUR\"<BR>\n";
        }
}


print "</BODY></HTML>";
}
Pages: [1] 2 »  All
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!