autotrade::Market::Simulated, autotrade-sim.pl: Support for strategy simulation on...
[autotrade.git] / autotrade.pl
blobebf430f7ef6e3de39ec73408bb8736e0c4b8b1bc
1 #!/usr/bin/perl
3 # Automated Bitcoin Trader
4 # (c) Petr Baudis <pasky@ucw.cz> 2011
6 use warnings;
7 use strict;
10 use autotrade::MarketTools;
12 use Getopt::Std;
13 our ($opt_b, $opt_r, $opt_i);
14 getopt('b:r:i:');
16 my $interval = $opt_i; # [s] trade cycle period
17 $interval ||= 10;
19 my %mtgox_opts = ();
20 defined $opt_b and $mtgox_opts{minbal_rwm} = str_curr($opt_b);
21 defined $opt_r and $mtgox_opts{rcfile} = $opt_r;
24 use autotrade::SQL;
25 use autotrade::RateHistory;
26 use autotrade::Market::MtGox;
27 use autotrade::Trader::LowHigh;
28 use autotrade::Trader::Slope;
30 my $dbh = autotrade::SQL::db_connect();
31 my $rh = autotrade::RateHistory->new(dbh => $dbh);
32 my $m = autotrade::Market::MtGox->new(%mtgox_opts);
33 my $t = autotrade::Trader::Slope->new(dbh => $dbh, rh => $rh, m => $m);
36 while (1) {
37 print "... ".localtime." check\n";
38 my $md;
39 do {
40 $md = $m->market_data();
41 $rh->record(time, $md->rate_buybtc(), $md->rate_sellbtc());
42 } while ($t->beat($md));
43 print "... ".localtime." check finished.\n\n";
44 sleep $interval;