use Zaif; #MONA/JPY の取引履歴をCSV化 my $z; $z = Zaif->new('KEY' => 'Your API key', 'SECRET' => 'Your SECRET key'); my $FILENAME = 'HISTORY.csv'; my $history = $z->history( 'currency_pair' => 'mona_jpy', 'count' => 50, 'order' => 'DESC'); if(!$history){ die $z->{'ERROR'}."\n"; } print $z->{'JSON'}."\n"; #列名 my @pn = ( "order_id","currency_pair","action","your_action","amount","price","fee","fee_amount","bonus","timestamp" ); #CSV出力 open OF,'>'.$FILENAME or die 'Cannot open file.'; $_ = shift(@pn); print OF '"'.$_.'"'; foreach $_ (@pn){ print OF ',"'.$_.'"'; } print OF "\n"; my ($c); foreach $_ (sort {$b <=> $a || $history->{$b}{'timestamp'} <=> $history->{$a}{'timestamp'}} keys(%$history)){ print OF '"'.$_.'"'; for($c = 0;$c < scalar(@pn);++$c){ if($pn[$c] eq 'timestamp'){ my @t = localtime(0+$history->{$_}{$pn[$c]}); printf OF (',"%4d/%02d/%02d %02d:%02d:%02d"',1900+$t[5],$t[4]+1,@t[3,2,1,0]); }else{ print OF ',"'.$history->{$_}{$pn[$c]}.'"'; } } print OF "\n"; } close OF; print "Success!\n"; sleep 5;