Finance::BitStamp::API - Perl extension for handling the BitStamp API and IPN calls.


  use Finance::BitStamp::API;

  # all the standard BitStamp API calls...

  my $bitstamp       = Finance::BitStamp::API->new(key => 'abc123');
  my $ticker         = $bitstamp->ticker;
  my $btc_address    = $bitstamp->bitcoin_address;
  my $btc_withdrawal = $bitstamp->bitcoin_withdrawal(amount => '1.0', address => $address);

  # The bitstamp object contains all the request data from the last request...

  my $user_agent = $bitstamp->user_agent;

  if ($bitstamp->success) {
      print 'SUCESS';
  else {
      print 'FAIL';
      my $error = $bitstamp->error;

  # A more useful example...
  my $bitstamp  = Finance::BitStamp::API->new(key => $key, secret => $secret, client_id => $client_id);
  my $buy = $bitstamp->buy(amount => '10.00');

  if ($buy) {
      printf "The BitStamp invoice ID is %s. You can see it here: %s\n", @{$buy}{qw(id url)};
  else {
      printf "An error occurred: %s\n", $bitstamp->error;


This API module provides a quick way to access the BitStamp API from perl without worrying about the connection, authenticatino and an errors in between.

You call these on the API object created like this:

  my $bitstamp = Finance::BitStamp::API->new(key => $key, secret => $secret, client_id => $client_id);

...Where those variable are provided to you by BitStamp through their merchant interface.

The primary PUBLIC methods are:

    ticker(), orderbook(), public_transactions(), conversion_rate()

The primary PRIVATE Information methods are:

    balance(), transactions(), withdrawals(), ripple_address(), bitcoin_address(), orders(), pending_deposits()

The primary PRIVATE Actions methods are:

    cancel(), buy(), sell(), bitcoin_withdrawal(), ripple_withdrawal()

The return value is a hash representing the BitStamp response.

  my $response_as_a_hash = $bitstamp->bitcoin_withdrawal(amount => $amount, address => $address);

The return value will be undefined when an error occurs...

  if ($bitstamp->is_success) {
      # the last primary method call worked!
  else {
      print "There was an error: " . $bitstamp->error;
      # more detail can be found in the bitstamp object using...
      my $ua           = $bitstamp->user_agent;
      my $raw_request  = $bitstamp->http_request;
      my $raw_response = $bitstamp->http_response;
      # further inspection could go here (like dumping the content of the useragent)



    my $bitstamp = Finance::BitStamp::API->new(key => $key, secret => $secret, client_id => $client_id);

Create a new Finance::BitStamp::API object. key, secret and client_id are required. These values are provided by Bitstamp through their online administration interface.


    my $ticker = $bitstamp->ticker;

Send a TICKER request to BitStamp.

Returns a hash reference of the ticker like this:

    $OrederBook = {
        asks => [
        bids => [
        timestamp => '1402308355'


    my $orderbook = $bitstamp->orderbook;


    my $public_transaction = $bitstamp->public_transaction;


    my $conversion_rate = $bitstamp->conversion_rate;


    my $balance = $bitstamp->balance;


    my $transactions = $bitstamp->transactions;


    my $withdrawals = $bitstamp->withdrawals;


    my $ripple_address = $bitstamp->ripple_address;


    my $bitcoin_address = $bitstamp->bitcoin_address;


    my $orders = $bitstamp->orders;


    my $cancel = $bitstamp->cancel;


    my $buy = $bitstamp->buy;


    my $sell = $bitstamp->sell;


    my $bitcoin_withdrawal = $bitstamp->bitcoin_withdrawal;


    my $pending_deposits = $bitstamp->pending_deposits;


    my $ripple_withdrawal = $bitstamp->ripple_withdrawal;


key(), secret(), client()

These are usually set during object instantiation. But you can set and retrieve them through these attributes. The last set values will always be used in the next action request. These values are obtained from BitStamp through your account.


Will return true if the request is set and all conditions are met. Will return false if: - the request object does not exist - the request object requires authentication and no key is provided - the request object does not have the manditory parameters set that BitStamp requires for that request.


If the request did not work, error() will contain a hash representing the problem. The hash contains the keys: 'type' and 'message'. These are strings. ie:

    print "The error type was: " . $bitstamp->error->{type};
    print "The error message was: " . $bitstamp->error->{message};


This will contain the user agent of the last request to BitStamp. Through this object, you may access both the HTTP Request and Response. This will allow you to do detailed inspection of exactly what was sent and the raw BitPay response.


This will contain the Request object of the last action called on the object. It is not a HTTP Request, but rather a config file for the request URL, params and other requirements for each post to bitstamp. You will find these modules using the naming Finance::BitStamp::API::Request::*


The design is such that the action methods (invoice_create(), invoice_get(), rates() and ledger()) will return false (0) on error. On success it will contain the hash of information from the BitStamp JSON response. Your code should just check whether or not the response exists to see if it worked. If the response does not exist, then then the module detected a problem. The simplest way to handle this is to print out $bitstamp->error. A coding example is provided above in the SYNOPSIS.


This module does not do accessive error checking on the request or the response. It will only check for "required" parameters prior to sending a request to BitStamp. This means that you provide a word for a 'amount' parameter, and this module will happily send that off to BitStamp for you. In these cases we are allowing BitStamp to decide what is and is not valid input. If the input values are invalid, we expect BitStamp to provide an appropriate response and that is the message we will return to the caller (through $bitstamp->error).

This module does not validate the response from BitStamp. In general it will return success when any json response is provided by Bitstamp without the 'error' key. The SSL certificate is verified automatically by LWP, so the response you will get is very likely from BitStamp itself. If there is an 'error' key in the json response, then that error is put into the $bitstamp->error attribute. If there is an 'error' parsing the response from BitStamp, then the decoding error from json is in the $bitstamp->error attribute. If there is a network error (not 200), then the error code and $response->error will contain the HTTP Response status_line() (a string response of what went wrong).


The BitStamp API documentation: This project on Github:


Jeff Anderson, <>


Copyright (C) 2014 by Jeff Anderson

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.