autotrade::Market::MtGox::dummy: New flag for easier debugging
[autotrade.git] / autotrade.pl
blob4137ce214ef33c495a572daccff9fe71ed6ae290
1 #!/usr/bin/perl
3 # Automated Bitcoin Trader - Low-High
4 # (c) Petr Baudis <pasky@ucw.cz> 2011
6 # The automated trader maintains no persistent data except in MtGox
7 # order book. We still expect periodical user inspections; if you want
8 # to withdraw k USD, place a buy order on k BTC @ 1 USD.
10 use warnings;
11 use strict;
14 use autotrade::MarketTools;
16 use Getopt::Std;
17 our ($opt_b, $opt_r, $opt_i);
18 getopt('b:r:i:');
20 my $interval = $opt_i; # [s] trade cycle period
21 $interval ||= 15;
23 my %mtgox_opts = ();
24 defined $opt_b and $mtgox_opts{minbal_rwm} = str_curr($opt_b);
25 defined $opt_r and $mtgox_opts{rcfile} = $opt_r;
28 use autotrade::SQL;
29 use autotrade::RateHistory;
30 use autotrade::Market::MtGox;
31 use autotrade::Trader::LowHigh;
33 my $dbh = autotrade::SQL::db_connect();
34 my $rh = autotrade::RateHistory->new(dbh => $dbh);
35 my $m = autotrade::Market::MtGox->new(%mtgox_opts);
36 my $t = autotrade::Trader::LowHigh->new(m => $m);
39 while (1) {
40 print "... ".localtime." check\n";
41 my $md;
42 do {
43 $md = $m->market_data();
44 $rh->record(time, $md->rate_buybtc(), $md->rate_sellbtc());
45 } while ($t->beat($md));
46 print "... ".localtime." check finished.\n\n";
47 sleep $interval;