WebService::MtGox - access to's bitcoin trading API


Creating the client

  use WebService::MtGox;
  my $m = WebService::MtGox->new(
    user     => 'you',
    password => 'secret',

Getting Trade Data

  my $ticker = $m->get_ticker;
  my $depth  = $m->get_depth;

Placing Buy and Sell Orders

  my $r1 = $m->buy(amount => 24, price => 7.77);
  my $r2 = $m->sell(amount => 10, price => 8.12);

Make it AnyEvent+Coro-friendly

  use WebService::MtGox;
  use LWP::Protocol::Coro::http;

Finally, use the command line client, mg

  mg help
  mg ticker


WebService::MtGox gives you access to MtGox's bitcoin trading API. With this module, you can get current market data and initiate your buy and sell orders.

It's great for writing bitcoin trading bots.



WebService::MtGox->new(user => $user, password => $password)

This constructs a WebService::MtGox object. If user and password are not provided (or are invalid), you will only be able to get market information from the API. You will not be able to buy or sell bitcoins without a valid MtGox username and password.

Market Information

The following methods do not require authentication.


Get the daily lows and highs along with the current price in USD for BTC.


Get a list of the current buy and sell orders.


Get a list of recent trades.

Buying and Selling

The following methods require authentication.


Get your balance

$m->buy(amount => $n, price => $p)

Create a buy order.

$m->sell(amount => $n, price => $p)

Create a sell order.


List all of your open orders.

$m->cancel(oid => $oid, type => $t)

Cancel an order based on oid and type. Type may be 1 for buy or 2 for sell.

$m->send(bitcoin_address => $addr, amount => $n)

Use this method to withdraw money from mtgox.

NOTICE: As of 2011-05-30, this API function has not yet been implemented at


API Documentation

Catalyst::Model::Bitcoin, Finance::Bitcoin, Finance::MtGox

(Had I known about Finance::MtGox, I wouldn't have made this module.)

Command Line Client

Buy and sell bitcoins on from the command line.



John BEPPU <beppu {at}>


This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.