commuterjoy / betfairfree

Automatically exported from code.google.com/p/betfairfree

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Introduction 
===============

Firstly go and look through the Betfair Developer Program website, it's full of
useful stuff, including documentation on all the different API's and forums.

http://bdp.betfair.com/

This code currently supports version 5 of the Betfair Exchange API and contains
everything you need for a good start. From getting your account balance through
finding your market and getting the best prices to placing a bet.

Support for this code
=====================

This code is not supported and comes with no warranty. However there is a 
discussion group at http://groups.google.com/group/betfairfree for suggestions 
and questions about the code. New releases will also be announced there.

Code Layout 
===========

/lib contains the Betfair modules and xpath modules.

/conf contains some yaml files in various stages of development, including the 
default.yml where debug can be turned on and off and the connect URIs are set

/tmpl contains the soap templates for sending. These are processed by 
BetFair::Template using a HTML::Template to fill them in. 

See BetFair::Template for a list of what templates are available and therefore 
what commands are currently supported by betfairfree. If you write support for 
additional commands feel free to submit them back.

/_t contains various perl scripts that have been written to perform various 
functions and can be called on their own, like getAccountFunds.pl to return 
your balance.

/docs contains the example responses from Betfair.

Getting Started
================

The quickest way to check everything is working is to run the getAccountFunds.pl 
script that you'll find in _t . You'll need to run it from the main betfair
directory so it picks up the Betfair perl modules.

 perl -I./lib _t/getAccountFunds.pl -u username -p password

If this doesn't work or returns an error then you should turn on the debug mode 
which you'll find at the top of conf/default.yml and re-run the script

There is an example.pl file in the root which will give you a start on how the
system works but there are more scripts in _t. For example this script logs a 
market's best prices, every 10 seconds

 perl -I./lib _t/log_best_prices.pl -u username -p password -interval 10 -m marketid

There are several other one off scripts used to test various parts of the 
templates and to provide useful info. 

For example t_getMarket.pl which returns market info when given login details 
and a market id. you can then search that for a selection and combine that with 
getMarketPrices to track the prices for an individual selection.

An example is provided below on how to combine several template calls into an 
an application which maintains the session and is easy to process. You setup 
your betfair object at the start of the script and then you can make multiple 
submit_request calls and parse the response each time.

Example Code
============

# lets setup a new BetFair object - 82 is the free api product code

my $b = new BetFair({	username => 'foo',  
			password => 'bar',
			productId => 82 } );

# Several of the request types also have direct functions which parse the returned
# XML and some present the data is slightly more useful format.

# The Betfair calls return 0 on error and you should then print $b->{error}
die $b->{error} unless ($b->getMarket($marketid));

# response is the pure xml from Betfair;
my $returnedXML = $b->{response};

# You can also get an XML::Simple or XPATH object using $b->{_data};

# now parse the returned XML to get the selection id of the contender
# we want to bet on 
[code]

# so now we want prices on our selection 
# note that submit_request returns 0 if it got an error
unless ($b->submit_request( 'getMarketPrices', { marketId => $marketid } ) ) {
	die $b->{error};
} 

# parse the xml returned for our selection and check that we're happy with the 
# price returned 
$returnedXML = $b->{response};
[code]

# So lets place a back bet
$b->submit_request( 'placeBets', { marketId => $marketid, selectionid => 
$selectionid, price => $betprice, size => $stake ,  bettype => 'B' } );

# parse the XML and make sure we got the bet on
$returnedXML = $b->{response};
[code]

XML Types
=========

The bulk of the code is written for XML::XPath but XML::Simple is also supported.
If you pass set up the betfair object as 

my $b = new BetFair({	username => 'foo',  password => 'bar', productId => 82,  xmlsimple=>1 } );

Then perform your queries using submitRequest and you will have an XML::Simple
object available at $b->{_data}. 

If you don't pass this in then you will get an XML::XPath object at $b->{_data}

Supported API actions
================

The list of supported actions are in the Betfair::Template module. The Betfair 
API supports more than this but the betfairfree template has not been written 
yet. If you write support for a new action please consider submitting it back.

There are some combined actions supported by using the Betfair object. For 
example there is a $b->getAccountFunds action that needs no arguments and 
will return your balance. Please see Betfair.pm for more info.

Throttling
==========

The free betfair API is throttled by Betfair, there is a throttling engine 
within this API which reports if you run in debug mode. The numbers below are 
number of times per minute this function can be called.

# notes for throttle levels

generic 

y getActiveEventTypes	Unlimited	
y getEvents	Unlimited	
y getMarket	5	
y getMarketPrices	10	
y getMarketPricesCompressed	60	
y login	24	

personal 

y getAccountFunds	1	
  getAccountStatement	1	
y keepAlive	Unlimited

  getBetHistory	1	
  getCurrentBets	60	
  getMarketProfitAndLoss	60	
  getMarketTradedVolume	60	
  getSubscriptionInfo	1	
	
  placeBets	60	
  updateBets	60	
  cancelBets	60

About

Automatically exported from code.google.com/p/betfairfree


Languages

Language:Perl 89.9%Language:Perl 6 9.9%Language:Shell 0.3%