File Coverage

blib/lib/WebService/MtGox.pm
Criterion Covered Total %
statement 15 56 26.7
branch n/a
condition n/a
subroutine 5 14 35.7
pod 9 9 100.0
total 29 79 36.7


line stmt bran cond sub pod time code
1             package WebService::MtGox;
2 1     1   25195 use 5.008;
  1         4  
  1         53  
3 1     1   2741 use Moo;
  1         18907  
  1         5  
4 1     1   2419 use Ouch;
  1         4947  
  1         53  
5 1     1   907 use JSON;
  1         13039  
  1         6  
6 1     1   3220 use LWP::UserAgent;
  1         99334  
  1         832  
7              
8             our $VERSION = '0.05';
9             our $BASE_URL = 'https://mtgox.com/code';
10              
11             has user => (is => 'ro');
12             has password => (is => 'ro');
13             has base_url => (is => 'rw', lazy => 1, default => sub { $BASE_URL });
14             has ua => (
15             is => 'ro',
16             lazy => 1,
17             default => sub {
18             my $ua = LWP::UserAgent->new();
19             push @{ $ua->requests_redirectable }, 'POST';
20             $ua;
21             }
22             );
23              
24             sub get_ticker {
25 0     0 1   my $self = shift;
26 0           my $url = $self->base_url . "/data/ticker.php";
27 0           my $json = $self->ua->get($url)->content();
28 0           decode_json($json);
29             }
30              
31             sub get_depth {
32 0     0 1   my $self = shift;
33 0           my $url = $self->base_url . "/data/getDepth.php";
34 0           my $json = $self->ua->get($url)->content();
35 0           decode_json($json);
36             }
37              
38             sub get_trades {
39 0     0 1   my $self = shift;
40 0           my $url = $self->base_url . "/data/getTrades.php";
41 0           my $json = $self->ua->get($url)->content();
42 0           decode_json($json);
43             }
44              
45             sub get_balance {
46 0     0 1   my $self = shift;
47 0           my $url = $self->base_url . "/getFunds.php";
48 0           my $json = $self->ua->post($url, { name => $self->user, pass => $self->password })->content();
49 0           decode_json($json);
50             }
51              
52             sub buy {
53 0     0 1   my $self = shift;
54 0           my %params = @_;
55 0           my $url = $self->base_url . "/buyBTC.php";
56 0           my $json = $self->ua->post($url, {
57             name => $self->user,
58             pass => $self->password,
59             amount => $params{amount},
60             price => $params{price},
61             })->content();
62 0           decode_json($json);
63             }
64              
65             sub sell {
66 0     0 1   my $self = shift;
67 0           my %params = @_;
68 0           my $url = $self->base_url . "/sellBTC.php";
69 0           my $json = $self->ua->post($url, {
70             name => $self->user,
71             pass => $self->password,
72             amount => $params{amount},
73             price => $params{price},
74             })->content();
75 0           decode_json($json);
76             }
77              
78             sub list {
79 0     0 1   my $self = shift;
80 0           my %params = @_;
81 0           my $url = $self->base_url . "/getOrders.php";
82 0           my $json = $self->ua->post($url, {
83             name => $self->user,
84             pass => $self->password,
85             })->content();
86 0           decode_json($json);
87             }
88              
89             sub cancel {
90 0     0 1   my $self = shift;
91 0           my %params = @_;
92 0           my $url = $self->base_url . "/cancelOrder.php";
93 0           my $json = $self->ua->post($url, {
94             name => $self->user,
95             pass => $self->password,
96             oid => $params{oid},
97             type => $params{type},
98             })->content();
99 0           decode_json($json);
100             }
101              
102             sub send {
103 0     0 1   my $self = shift;
104 0           my %params = @_;
105 0           my $url = $self->base_url . "/withdraw.php";
106 0           my $json = $self->ua->post($url, {
107             name => $self->user,
108             pass => $self->password,
109             group1 => 'BTC',
110             btca => $params{bitcoin_address},
111             amount => $params{amount}
112             })->content();
113 0           decode_json($json);
114             }
115              
116             1;
117              
118             __END__