autotrade::Trader: Support expiring old orders in default beat(); LowHigh: Expire...
[autotrade.git] / autotrade.pl
blobb3b000fc1f8f36626530570bce7854a08d8bc9dc
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 my $time;
43 do {
44 $md = $m->market_data();
45 $time = time;
46 } while ($t->beat($md));
47 $rh->record($time, $md->rate_buybtc(), $md->rate_sellbtc());
48 print "... ".localtime." check finished.\n\n";
49 sleep $interval;