first commit

This commit is contained in:
2025-06-03 23:03:08 +02:00
commit d40894b155
49 changed files with 49341 additions and 0 deletions

206
NiceHash/nicehash.pl Normal file
View File

@@ -0,0 +1,206 @@
use lib '/home/steffen/scripte/nicehash';
use Nicehashapi;
use Data::Printer;
use File::Slurp;
use Mojo::UserAgent;
use Time::Piece;
# use Term::ANSIColor;
use File::Copy;
my $einsatzhenner = 150;
my $api = Nicehashapi->new(
key => '8bcbda58-5a26-4ce4-8e61-3a0fd894cfbb',
secret => '59dc1ee5-a0e6-4ba6-9a9c-a043c350b88b84266786-2d14-4b9f-9ae5-d168ed8376b7',
organisation_id => '4c615374-bf85-42fd-860d-b1bf4568c01f'
);
my $data = $api->get_payouts(0, 10_000);
my @trading = read_file('/home/steffen/scripte/nicehash/investment.csv');
my %washabich;
my %washabichwoanders;
my %avgineuro;
my %count4avgineuro;
# my %kleinstekurse = {
# ""
# }
for my $l ( @trading ) {
next if ( $l =~ /^buy/ );
chomp $l;
$l = $l =~ s/\s//gr;
my @sp = split(/;/, $l );
if ( $sp[0] eq 'BTC' && $sp[2] eq 'EUR' ) {
$washabich{'EUR'} += $sp[3] ;
$washabich{$sp[0]} += ($sp[1] * $sp[8] );
$avgineuro{$sp[0]} += $sp[8];
$count4avgineuro{$sp[0]} += 1;
} elsif ( $sp[0] eq 'BTC' && $sp[2] ne 'EUR' ) {
if ( $sp[8] eq 'sellout' ) {
$avgineuro{$sp[2]} = 0;
$count4avgineuro{$sp[2]} = 0;
$washabich{$sp[2]} = 0;
} else {
$washabich{$sp[2]} -= (($sp[1]- $sp[7] ) * $sp[8] );
}
} elsif ( $sp[0] eq 'EUR' ) {
$washabich{'EUR'} -= $sp[1];
$washabichwoanders{$sp[9]} += $sp[1];
} else {
$washabich{$sp[0]} += (($sp[1]- $sp[7] ) * $sp[8] );
$avgineuro{$sp[0]} += $sp[8];
$count4avgineuro{$sp[0]} += 1;
$washabich{'BTC'} -= (($sp[1]- $sp[7] ) * $sp[8] );
}
}
p $count4avgineuro{'FTM'};
p $washabich{'FTM'};
for my $k ( keys %avgineuro ) {
next if ( $count4avgineuro{$k} == 0 );
$avgineuro{$k} = $avgineuro{$k} / $count4avgineuro{$k};
}
$washabich{'EUR'} = $washabich{'EUR'} - $einsatzhenner;
my $get_accounts2 = $api->get_accounts2('true', 'EUR');
my %btcwerte;
my %curwerte;
for my $li (@{$get_accounts2->{currencies}}) {
if ( $li->{totalBalance} > 0 ) {
$btcwerte{$li->{currency}} = $li->{fiatRate};
$curwerte{$li->{currency}} = $li->{totalBalance};
}
}
my $othercurrbtc = $maxbtc - $btcwerte{'BTC'};
my $cur = $api->get_prices;
my $gesamtgebuehr = 0;
my $gesamt = 0;
# write_file('/mnt/h/Download/nicehashmining.csv', "Type,Buy Amount,Buy Currency,Sell Amount,Sell Currency,Fee,Fee Currency,Exchange,Trade-Group,Comment,Date\n");
my $min;
my $max;
# mining
for my $line (@{$data->{list}}) {
my $date = localtime($line->{created} / 1000);
if ( not defined $min ) {
$min = $line->{created};
}
if ( not defined $max ) {
$max = $line->{created};
}
if ( $min > $line->{created} ) {
$min = $line->{created};
}
if ( $max < $line->{created} ) {
$max = $line->{created};
}
my $datetime = $date->ymd .' ' . $date->hms;
my $currencies = $line->{currency}->{description};
my $feeamount = $line->{feeAmount};
my $amount = $line->{amount};
my $gebuehr = sprintf('%.8f', $feeamount );
$gesamtgebuehr += $gebuehr;
$gesamt += $amount;
#append_file('/mnt/h/Download/nicehashmining.csv', "Mining (kommerziell),$amount,$currencies,0,EUR,$gebuehr,$currencies,NiceHash,,,$datetime\n");
}
$min = localtime($min / 1000);
$max = localtime($max / 1000);
my $eur = $btcwerte{'BTC'};
my $btchenner = 0.00307542;
my $gesamteuro = sprintf('%.2f', ( $gesamt * $eur ) );
my $gebuehreuro = sprintf('%.2f', ( $gesamtgebuehr * $eur ) );
my $gesamtgebeuro = sprintf('%.2f', ( ($gesamt - $gesamtgebuehr) * $eur ) );
my $btchennereuro = sprintf('%.2f', ( $btchenner * $eur ) ); # Henner 150 Euro
my $btcsteffeneuro = sprintf('%.2f', ( ($curwerte{'BTC'} - $btchenner ) * $eur ) ); #
print 'von '.$min->ymd.' - '.$max->ymd."\n";
print "\n";
print "─── Mining ───────────────────────────────────────────────────────────────────────────────────\n";
print " BTC:\t$gesamt\t €: $gesamteuro\n";
print " Gebuehr:\t" . sprintf('%.8f', $gesamtgebuehr). "\t €: $gebuehreuro\n";
print "nach Gebuehr:\t". sprintf('%.8f',($gesamt - $gesamtgebuehr)). "\t €: $gesamtgebeuro\n";
print "─── Trading ────────────────────────────────────────────────────────────│\n";
print "BTC H:\t". sprintf('%.8f', $btchenner ). "\t €: $btchennereuro\t← 150\t→ ". _rotodergruen( _prozent(150,$btchennereuro)) ." %\t│───────────────│──────────────\n";
print "BTC S:\t". sprintf('%.8f', ($curwerte{'BTC'} - $btchenner - $gesamt) ). "\t €: $btcsteffeneuro". "\t← ".sprintf('%.2f', $washabich{'BTC'} - 150). "\t→ ". _rotodergruen(_prozent( $washabich{'BTC'} - 150,$btcsteffeneuro))." %\t│ ".sprintf('%.4f', $eur ). " €\t│ ".sprintf('%.2f',$avgineuro{'BTC'} ). " €\n";
my $maxsteffen = $btcsteffeneuro;
my $maxsteffenbtc = sprintf('%.8f', ($btcwerte{'BTC'} - $btchenner) );
for my $cu ( sort keys %btcwerte ) {
next if ( $cu eq 'BTC' );
$maxsteffen += sprintf('%.2f', ( $curwerte{$cu} * $btcwerte{$cu} ) );
$maxsteffenbtc += sprintf('%.8f', $curwerte{$cu} );
# print sprintf('%.8f', $btcwerte{$cu}). "\n";
my $pro = _prozent($curwerte{$cu} * $avgineuro{$cu}, $curwerte{$cu} * $btcwerte{$cu} );
print "$cu:\t".sprintf('%.8f', $curwerte{$cu} ). "\t €: ".sprintf('%.2f', ( $curwerte{$cu} * $btcwerte{$cu} ) ). "\t← ".sprintf('%.2f', $curwerte{$cu} * $avgineuro{$cu} ). "\t→ ". _rotodergruen($pro) . " %\t│ ".sprintf('%.4f',$btcwerte{$cu} )." €\t│ ".sprintf('%.4f',$avgineuro{$cu} ). " €\n";
}
print "─── result ─────────────────────────────────────────────────────────────│───────────────│──────────────\n";
my $totaleuro = $get_accounts2->{total}->{totalBalance} * $eur;
print "Umsatz NH:\t".sprintf('%.2f', $totaleuro)." €\n";
print "davon mining:\t$gesamtgebeuro €\n";
print "Rendite:\t". _rotodergruen( sprintf('%.2f', ($maxsteffen - $washabich{'EUR'}))) . " €\n";
print "ohne mining:\t". _rotodergruen(sprintf('%.2f', ($maxsteffen - $washabich{'EUR'} - $gesamtgebeuro))) . " €\n";
print "-=-=-=-=-=-=-=-=-=-=-=-=-=-\n";
print "Einsatz NH:\t$washabich{'EUR'} €\n";
my $su = 0;
for my $exch ( sort keys %washabichwoanders ) {
print "$exch:\t$washabichwoanders{$exch} €\n";
$su += $washabichwoanders{$exch};
}
$su += $washabich{'EUR'};
print "===========================\n";
print "Einsatz gesamt:\t$su €\n";
my @dateien = read_dir('./' );
for my $d ( @dateien ) {
copy( '/home/steffen/scripte/nicehash/'.$d, '/mnt/e/Programmierung/Perl/NiceHash' );
}
sub _prozent {
my ($ist, $soll) = @_;
if ( $ist ) {
my $result = sprintf('%.0f', ( ($soll * 100) / $ist - 100));
if ( $result !~ /-/ ) {
$result = " $result";
}
return $result;
} else {
return 0;
}
}
sub _rotodergruen {
my ($text) = @_;
if ( $text =~ /-/ ) {
return "\e[31m$text\e[0m";
} else {
return "\e[32m$text\e[0m";
}
}
1;