<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>Betfair Developers Program Forum - Blogs</title>
		<link>http://forum.bdp.betfair.com/blog.php</link>
		<description>Discussion forum. Betfair Developers Program - The Betfair Developers Program is dedicated to assisting Betfair customers with integrating their applications into the Betfair exchange platforms. Members can use the Betfair APIs to create custom applications</description>
		<language>en</language>
		<lastBuildDate>Sun, 22 Nov 2009 15:04:59 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://forum.bdp.betfair.com/images/styles/nature/misc/rss.jpg</url>
			<title>Betfair Developers Program Forum - Blogs</title>
			<link>http://forum.bdp.betfair.com/blog.php</link>
		</image>
		<item>
			<title>Greyhounds Form guide</title>
			<link>http://forum.bdp.betfair.com/blog.php?b=13</link>
			<pubDate>Mon, 14 Sep 2009 12:29:25 GMT</pubDate>
			<description><![CDATA[The "Dogs racing Forms Guide" at the following link http://form.greyhounds.betfair.com/racingform 
has all the form for the days dog meetings. 
What...]]></description>
			<content:encoded><![CDATA[<div>The &quot;Dogs racing Forms Guide&quot; at the following link <a href="http://form.greyhounds.betfair.com/racingform" target="_blank">http://form.greyhounds.betfair.com/racingform</a><br />
has all the form for the days dog meetings.<br />
What I woulld like to be able to do is to download this information, the problem I have is that every race has the same url address, does anyone know how I could automatically capture the form data for each race for the day?<br />
You can bring up each page seperately from a drop down menu and it then somehow tells the betfair server which race you have just selected, I would like to be able to reproduce this with a script?<br />
Any idea's out there?</div>

]]></content:encoded>
			<dc:creator>sir steel</dc:creator>
			<guid isPermaLink="true">http://forum.bdp.betfair.com/blog.php?b=13</guid>
		</item>
		<item>
			<title>Timers and the like</title>
			<link>http://forum.bdp.betfair.com/blog.php?b=12</link>
			<pubDate>Tue, 05 May 2009 15:21:53 GMT</pubDate>
			<description><![CDATA[Now, this may not be useful to all of you, except as an exercise in problem solving, but I've been having a problem sorting out the timings of my...]]></description>
			<content:encoded><![CDATA[<div>Now, this may not be useful to all of you, except as an exercise in problem solving, but I've been having a problem sorting out the timings of my GetMarketPrices calls.<br />
<br />
The way I'm working things is I use a ThreadPool implementation I was given by an extremely generous soul and I pass GetMarketPrices calls into it. Since I'm generally looping over a set number of markets and my computer runs a lot faster than the internet, its very easy for the threadpool to become overrun by requests, which means I had to find a way of slowing it down. Its not fun seeing thousands of requests bogging down your app and ultimately crashing it after all.<br />
<br />
So, there were a few ways of doing it. It was suggested I use one of the java.util.Timer() implementations to fire off requests at the time I wanted them, but to me, the java.util.Timer() seemed a little limiting, in that it seems to work on a clockwork system, meaning the task is carried out regardless of whether the previous call has finished executing or not.<br />
<br />
Thats fine and incredibly useful for some things, but for my getMarketPrices calls, I needed a little more flexibility. Unfortunately, my home network can best be described as an educated bodge job, which means I sometimes get some quite astonishing latencies from the network. However, while there are a few exceptions, I have found then when the network has decided to behave, I can get sub 100ms responses from the API. When its decided not to behave, It can take anything from 1500ms to 10000ms. Thats right, ten seconds for a price request to be sent and the result received. What I've wanted, was a way for the Thread.sleep() method to react to networking spasms and try to keep efficiency as high as possible. To settle any doubts, this is the code I use to determine timings.<br />
<br />
This is buried within the depths of the actual API call itself, so you will excuse me if I leave some of the out of context stuff out.<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 130px;
		text-align: left;
		overflow: auto">            APIRequestHeader theHeader = ExHeader.makeHeader();
            request.setHeader(theHeader);
            request.setMarketId(marketID);
            long sent = System.currentTimeMillis();
            com.betfair.publicapi.types.exchange.v5.GetMarketPricesResp result = port.getMarketPrices(request);
            long received = System.currentTimeMillis();
            long taken = received - sent;</pre>
</div>As you can see, its a fairly simple process. I get the time as a long when I send the request and again when I receive the response. Take one from the other and we have the elapsed time.<br />
<br />
Another thing I've been fiddling with recently is the concept of Simple Moving Averages, which give you an indication of trends. They are the stupid version of the Exponential Moving Average (which I encourage you to read up on later - very useful analysis tool) but they certainly have their uses. In this case, what I have done is take the elapsed time value from the code above and feed it into a class which generates an SMA based on a minutes worth of calls. My market prices loop then looks at this value and sleeps for that period before waking up and sending another request. The final result is, regardless of the networks variable lag, I have a system which so far seems to be adapting to its response time quite nicely.<br />
<br />
There are probably simpler solutions to this sort of thing, but with my networks....inconsistencies...I have found this one seems to do the trick quite nicely.<br />
<br />
Here is the code itself. It probably isn't completely bug free, but it works well enough for what it is. If its any good to you, have a play with it.<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 498px;
		text-align: left;
		overflow: auto">
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;

/**
 *
 * @author alan
 */
public class MarkPricesTimerSMA {
    /**
     * the sleeptime for the getMarketPrices() method
     */
    private long sleepLength;
    /**
     * the list holding the values of each operation time.
     * This value is defined as the the amount of time which passes 
     * between sending the market prices request and receiving the response.
     */
    private LinkedHashMap&lt;Long, Long&gt; operTimerMap;
    
    private final long oneMinute = 60000;

    public MarkPricesTimerSMA()
    {
        this.operTimerMap = new LinkedHashMap&lt;Long, Long&gt;();
        this.operTimerMap.put(System.currentTimeMillis(), this.sleepLength);
    }

    public long getSleepLength()
    {
        return sleepLength;
    }
    
    public void addTimeValue(long value)
    {
            long now = System.currentTimeMillis();
            this.operTimerMap.put(now, value);
            for (Iterator&lt;Long&gt; it = this.operTimerMap.keySet().iterator(); it.hasNext();)
            {
                if (it.next() &lt; (now - oneMinute))
                {
                    it.remove();
                }
            }
            Collection c = this.operTimerMap.values();
            Iterator itr = c.iterator();
            long temp = 0;
            int numVals = c.size();
            while (itr.hasNext())
            {
                temp = ((Long) itr.next()) + temp;
                numVals++;
            }
            long smaAvg = temp / numVals;
            this.sleepLength = smaAvg;
    }

    
}</pre>
</div></div>

]]></content:encoded>
			<dc:creator>ThanksFish</dc:creator>
			<guid isPermaLink="true">http://forum.bdp.betfair.com/blog.php?b=12</guid>
		</item>
		<item>
			<title><![CDATA[Logging out - it's the polite thing to do.]]></title>
			<link>http://forum.bdp.betfair.com/blog.php?b=11</link>
			<pubDate>Sun, 05 Apr 2009 15:31:44 GMT</pubDate>
			<description><![CDATA[Ok, what I'm doing here is a Logout class, so we can at the very least have a polite bot which logs in and logs out when we have finished. 
 
So,...]]></description>
			<content:encoded><![CDATA[<div>Ok, what I'm doing here is a Logout class, so we can at the very least have a polite bot which logs in and logs out when we have finished.<br />
<br />
So, using the project we have been working on, we will need to set up a few new classes. I'll say this again - the way I'm showing you may well not be the best way to do stuff, but it is a way which works. <br />
<br />
What I'm going to do here first is set up two new classes which will provide us with APIRequestHeader objects when we need them. <br />
<br />
Essentially, the classes are identical, however semantics within the API mean we have two of them, one for calls which are aimed at the Global WSDL and one for calls aimed at the Exchange WSDL.<br />
<br />
This is the global glass, which I've called GlobHeader:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 290px;
		text-align: left;
		overflow: auto">package wsops;

import com.betfair.publicapi.types.global.v3.APIRequestHeader;


public class GlobHeader {

    public static String sessionToken;
    
    public static APIRequestHeader makeHeader()
    {
        APIRequestHeader newHeader = new APIRequestHeader();
        newHeader.setSessionToken(sessionToken);
        return newHeader;
    }
    
}</pre>
</div>Pretty simple stuff really. Create a new class in the wsops package in the project and call it GlobHeader, then type or paste the code above into it, replacing the code Netbeans supplied.<br />
<br />
Do exactly the same for a class called ExHeader, except you will have to delete the import statement and import the APIRequestHeader from the Exchange web service client. Netbeans should give you a prompt, offering to import it for you. Don't forget to change the class name when you copy it over.<br />
<br />
With that done, we can get on with it.<br />
<br />
Create a new java class in the wsops package and call it Logout. We are going to do something slightly tricky here and introduce a new thread to perform the logout for us without locking up the UI.<br />
<br />
So, once netbeans has generated the new class for you, find the class declaration, which looks like this:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto">public class Logout {</pre>
</div>and add the words &quot;implements Runnable&quot; to it, so it looks like this:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto">public class Logout implements Runnable {</pre>
</div>Underneath that, we need to declare variable of type Thread. This variable <i>must</i> be a public variable, because we have to control it outside the class.<br />
<br />
So, <br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 66px;
		text-align: left;
		overflow: auto"> 
public Thread thread;
private boolean loggedOut;</pre>
</div>Now for the constructor. We can let netbeans generate this for us (if you really can't bear the idea of typing it) but it has to look like this:<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 98px;
		text-align: left;
		overflow: auto">public Logout()
{
    this.thread = new Thread(this);
    this.loggedOut = false;
}</pre>
</div>The reasoning behind that particular structure is as complicated as you want to make it. The upshot is that we want to associate the thread with a particular task and if we want to do that, the task has to implement the Runnable interface, which our class does. As I said though, there is a lot more to it than that.<br />
<br />
Now, when you typed the words &quot;implements Runnable&quot; into the class declaration, netbeans probably threw a lot of red lines at you. Click on the light bulb icon next to the class declaration and take the option of generating all abstract methods.<br />
<br />
This will create a public method called run(). This method is the magic of the Runnable interface. You put the code you want to perform it here and when you start the thread, the thread executes it. Because the code is running on a completely separate thread from the UI thread, our UI doesn't lock up when we run the code.<br />
<br />
Ordinarily, you would create a private logout method and call it from the run() method, but in this case, I'm just going to put the code in directly.<br />
<br />
So, open up some space in the run() method and right click somewhere between the braces. At the bottom of the popup menu, hover over the &quot;Web Service Client Resources&quot; entry and choose &quot;Call Web Service Operation&quot;. In the dialog which opens up, expand the Global Service JTree until you see all of the possible operations (accompanies by little red dots next to them) and click on the one labelled &quot;logout&quot;. Click &quot;Ok&quot; and the majority of the code is generated for you, within a try-catch block.<br />
<br />
Logging out of the API requires only one parameter, which is the APIRequestHeader. The classes we created earlier will provide us with one of those, so in the generated code, find the line which looks like this:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto">com.betfair.publicapi.types.global.v3.LogoutReq request = new com.betfair.publicapi.types.global.v3.LogoutReq();</pre>
</div>and underneath it, type this:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto">request.setHeader(GlobHeader.makeHeader());</pre>
</div>Underneath the closing brace of the run() method, right click choose &quot;Insert Code | Getter&quot; and generate a getter method for the boolean loggedOut variable.<br />
<br />
And with that, the logout class is finished. <br />
<br />
Now, in order to logout, we need to set up a logout button. Open up the UI class (called &quot;BlogTuteView.java&quot; in our project) and place a button and a checkbox onto the form. I've called the button btnLogout and the checkbox cbExitProgram.<br />
<br />
Switch to source view and locate the code we wrote for the login button. Within the braces of the if statement we have in there, add the following code:<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 50px;
		text-align: left;
		overflow: auto">GlobHeader.sessionToken = log.getLogin().getHeader().getSessionToken();
ExHeader.sessionToken = log.getLogin().getHeader().getSessionToken();</pre>
</div>Switch back to design view and right click the new logout button, choosing &quot;Events | Action | actionPerformed&quot; from the popup menu.<br />
<br />
Within the new method netbeans generated, add the following code:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 306px;
		text-align: left;
		overflow: auto">    Logout logout = new Logout();
    if (!this.cbExitProgram.isSelected())
    {
        logout.thread.start();
        this.txtPassword.setEnabled(true);
        this.txtUsername.setEnabled(true);
        this.btnLogin.setEnabled(true);
        this.btnLogout.setEnabled(false);
    }
    else
    {
        logout.thread.start();
        do
        {
        }
        while (logout.isLoggedOut() == false);
        this.getApplication().exit();
    }</pre>
</div>And with that, we are done!</div>


<!-- attachments -->
	<div style="margin-top:10px">

		
		
		
		
			<fieldset class="fieldset">
				<legend>Attached Files</legend>
				<table cellpadding="0" cellspacing="3" border="0">
				<tr>
	<td><img class="inlineimg" src="http://forum.bdp.betfair.com/images/styles/nature/attach/zip.gif" alt="File Type: zip" width="16" height="16" border="0" style="vertical-align:baseline" /></td>
	<td><a href="http://forum.bdp.betfair.com/blog_attachment.php?attachmentid=8&amp;d=1238945496">BlogTute.zip</a> (1.87 MB, 147 views)</td>
</tr>
				</table>
			</fieldset>
		

	</div>
<!-- / attachments -->
]]></content:encoded>
			<dc:creator>ThanksFish</dc:creator>
			<guid isPermaLink="true">http://forum.bdp.betfair.com/blog.php?b=11</guid>
		</item>
		<item>
			<title>Concurrently adding and removing components</title>
			<link>http://forum.bdp.betfair.com/blog.php?b=10</link>
			<pubDate>Sat, 07 Mar 2009 16:14:45 GMT</pubDate>
			<description><![CDATA[I've just managed to do something I'm fairly proud of. Its probably fairly small beans to a lot of folk, but it took me ages to figure out and I'm...]]></description>
			<content:encoded><![CDATA[<div>I've just managed to do something I'm fairly proud of. Its probably fairly small beans to a lot of folk, but it took me ages to figure out and I'm fairly chuffed with myself.<br />
<br />
I'm writing a bot (aren't we all!) and I've taken a bit of a leap into the unknown with some of the techniques I'm using. For example, I've created some custom components to show my data. Not all that groundbreaking really, but since the aim of my bot is for me to start it up and walk away from it, but still be able to show me real time information if I come back and look at it. So, I've been trying to figure out how to get it to add and remove the custom components as markets come and go. Again, not terribly groundbreaking <i>if you have done it before.</i><br />
<br />
This is what the main screen looks like, you can see a couple of the components in there.<br />
<br />
<img src="https://forum.bdp.betfair.com/blog_attachment.php?attachmentid=7&amp;d=1236442393" border="0" alt="" /><br />
<br />
Well I haven't done it before and I was finding it tricky, not least because at times, there can be multiple threads working with the data coming into the system.<br />
<br />
Yes, we are looking at concurrency - a subject which quite a lot of people - me included - find slightly weird and quite difficult to get a handle on.<br />
<br />
I can't say I am any good at it yet, but I'm still basking in the glow a lot of programmers get when they finally manage to get a challenging piece of code working. <br />
<br />
The idea behind the code is this. On my UI, I have created components which extend JPanel to hold the data I want to see. Each component holds a single market I think I want to monitor. Since I am working with the overs/unders and match odds markets, there can sometimes be a lot of them to monitor. However, some of those markets don't see any action, or are closed well before the match actually finishes. If the market doesn't look like getting much action, I want to be able to stop monitoring it by putting a tick in a box, which will prompt the application to remove the component the next time the loop comes its way. That has the effect of reducing the number of market IDs I will be calling for prices on, which means a) the remaining markets on the form are sorted more efficiently and b) my UI isn't cluttered up with dead markets.<br />
<br />
Here is the code. It may not be the most efficient, but it works. I'm going on the basis of 'get it working first, optimise it later'.<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 434px;
		text-align: left;
		overflow: auto">    private void removeMarketFromUI(TwoRunnerMarket pan)
    {
        synchronized (marketsOnForm)
        {
            int mid = pan.getMarketID();
            Iterator it = marketsOnForm.iterator();
            while (it.hasNext())
            {
                synchronized (this.ms.monForm.pnlAllMarkets)
                {
                    Object obj = it.next();
                    if (obj instanceof TwoRunnerMarket)
                    {
                        TwoRunnerMarket onForm = (TwoRunnerMarket) obj;
                        if (onForm.getMarketID() == mid)
                        {
                            this.ms.monForm.pnlAllMarkets.remove(pan);
                            this.ms.monForm.pnlAllMarkets.validate();
                            this.ms.monForm.pnlAllMarkets.notify();
                            marketsOnForm.notify();
                        }
                    }
                }
            }
        }
    }</pre>
</div>I'm still puzzling over whether the marketsOnForm variable needs to be synchronized and notified, but I've left it in there just in case. I have a feeling it doesn't, because it is simply a reference to the this.ms.monForm.pnlAllMarkets object, but I'm leaving it in there for the moment. As I said, I'll optimise it later, right now, I want to get it running - which it seems to be doing quite nicely.<br />
<br />
Now, maybe I can get on with the university work I have been putting off for ages - it is due in on Monday!</div>


<!-- attachments -->
	<div style="margin-top:10px">

		
			<fieldset class="fieldset">
				<legend>Attached Thumbnails</legend>
				<div style="padding:3px">
				<a href="http://forum.bdp.betfair.com/blog_attachment.php?attachmentid=7&amp;d=1236442393"><img class="thumbnail" src="http://forum.bdp.betfair.com/blog_attachment.php?attachmentid=7&amp;stc=1&amp;thumb=1&amp;d=1236442393" border="0" alt="Click image for larger version

Name:	Capture.JPG
Views:	354
Size:	97.9 KB
ID:	7" /></a>
&nbsp;
				</div>
			</fieldset>
		
		
		
		
			<fieldset class="fieldset">
				<legend>Attached Files</legend>
				<table cellpadding="0" cellspacing="3" border="0">
				
				</table>
			</fieldset>
		

	</div>
<!-- / attachments -->
]]></content:encoded>
			<dc:creator>ThanksFish</dc:creator>
			<guid isPermaLink="true">http://forum.bdp.betfair.com/blog.php?b=10</guid>
		</item>
		<item>
			<title>Using properties and settings in Java</title>
			<link>http://forum.bdp.betfair.com/blog.php?b=9</link>
			<pubDate>Wed, 18 Feb 2009 15:26:49 GMT</pubDate>
			<description>Right then, sliding a little way off the Betfair API track, but with something which is still germane to writing an app which will access the API,...</description>
			<content:encoded><![CDATA[<div>Right then, sliding a little way off the Betfair API track, but with something which is still germane to writing an app which will access the API, I'm going to talk about .properties files in Java.<br />
<br />
I know I said I generally wouldn't be talking too much about basic java stuff and I suppose to a lot of people, this stuff will seem fairly basic. However, while I was trying to find out how to do this, I visited I don't know how many web pages and got useful bits of information from each one, which was great. What I couldn't get was all of this information in one place.<br />
<br />
You might say &quot;have a look at the <a href="http://java.sun.com/docs/books/tutorial/essential/environment/properties.html" target="_blank">The Java Tutorials</a> pages, and you would be right to, they are an incredibly rich resource which contain just about everything you need in order to learn how to write programs using Java.  However, when you have a look at the page on that URL, you will see that in order to use the Properties class, you need to be able to write to and from files on your hard drive. This means using an object of type InputStream. Fair enough, whats one of them? <br />
<br />
Fortunately, I have been given just enough knowledge to be dangerous, so I already had half an idea what most of this stuff was, but putting it all together was becoming a frustration for me, particularly the stuff about making sure the properties file you are reading and writing to is in the classpath - a concept of which I had only a rough grasp of before this.<br />
<br />
A properties file is a file which generally contains key/value pairs. So a key might be &quot;username&quot; and the accompanying value will be &lt;your-username&gt;. In java, they can be used for lots of things, although the most common useage seems to be internationalisation of applications. However, the beauty of writing your own programs is that they can be used for just about anything at all.<br />
<br />
What I've spent the past few days working out is how I can change the behaviour of the program from within the actual program. I don't know about you, but quite a lot of the time, if I'm watching what my bot is doing, I see behaviour which I want to change, but because of the situation, I don't want to stop the application and dive into the source files in order to do it. So what I needed was a way to change certain behavious of the application while the application was still running.<br />
<br />
Which brings us back to the properties file. <br />
<br />
Mine for example, looks a bit like this:<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 162px;
		text-align: left;
		overflow: auto"># Betting Configuration
divisor=3
risk_percentage=10
stake_win_percentage=2.5
stop_loss_percentage=5
#timers
account_details_timer=30
market_prices_timer=200
unmatched_bet_timer=500</pre>
</div>What I've also done is design a form which has components related to all of those settings. For the timers, I've used JSliders, for the percentages and so on, I've used JTextFields. The idea being, that when I see something I want to alter, I can open the settings form, change the timing or percentage or whatever, write the changes to the file and have them implemented straight away. Perfect.<br />
<br />
Lets have a look at how its done. I'm not saying this is the best way, but this is how I've done it and so far, it works. You also have to keep in mind that the properties file works only with strings. There is a capacity for it to work with XML, but I haven't got that far with it. What that means is that the values you read into and out of the properties file are strings. If you want them to be doubles or longs, you have to convert them yourself, which isn't hard.<br />
<br />
In order to make getting and setting the settings as simple as possible, I decided to encapsulate it into a custom object, unimaginatively titled a ConfigObject.<br />
<br />
This is what it looks like:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 498px;
		text-align: left;
		overflow: auto">package me.ms.conf;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ConfigObject {
    
    private Properties conf;
    private InputStream in; 
    private int acctDetailsTimer;
    private int divisor;
    private int mPricesTimer;
    private int riskPercentage;
    private int stakeWinPercentage;
    private int stopLossPercentage;
    private int unmatchedBetTimer;
    private String username;
    private int sportID;
    private boolean valuesChanged;

    public ConfigObject()
    {
        this.conf = new Properties();
        this.in = getClass().getResourceAsStream(&quot;/me/ms/conf/MarkSmart.properties&quot;);
        try
        {
            this.conf.load(in);
        }
        catch (IOException ex)
        {
            Logger.getLogger(ConfigObject.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.readProperties();
    }

    public boolean isValuesChanged()
    {
        return valuesChanged;
    }

    public void writeProperties()
    {
        if (this.isValuesChanged())
        {
            this.conf.setProperty(&quot;account_details_timer&quot;, String.valueOf(this.acctDetailsTimer));
            this.conf.setProperty(&quot;divisor&quot;, String.valueOf(this.divisor));
            this.conf.setProperty(&quot;market_prices_timer&quot;, String.valueOf(this.mPricesTimer));
            this.conf.setProperty(&quot;risk_percentage&quot;, String.valueOf(this.riskPercentage));
            this.conf.setProperty(&quot;stake_win_percentage&quot;, String.valueOf(this.stakeWinPercentage));
            this.conf.setProperty(&quot;stop_loss_percentage&quot;, String.valueOf(this.stopLossPercentage));
            this.conf.setProperty(&quot;unmatched_bet_timer&quot;, String.valueOf(this.unmatchedBetTimer));
            this.conf.setProperty(&quot;username&quot;, this.username);
        }
    }

    private void readProperties()
    {
        this.acctDetailsTimer = Integer.parseInt(this.conf.getProperty(&quot;account_details_timer&quot;));
        this.divisor = Integer.parseInt(this.conf.getProperty(&quot;divisor&quot;));
        this.mPricesTimer = Integer.parseInt(this.conf.getProperty(&quot;market_prices_timer&quot;));
        this.riskPercentage = Integer.parseInt(this.conf.getProperty(&quot;risk_percentage&quot;));
        this.stakeWinPercentage = Integer.parseInt(this.conf.getProperty(&quot;stake_win_percentage&quot;));
        this.stopLossPercentage = Integer.parseInt(this.conf.getProperty(&quot;stop_loss_percentage&quot;));
        this.unmatchedBetTimer = Integer.parseInt(this.conf.getProperty(&quot;unmatched_bet_timer&quot;));
        this.username = this.conf.getProperty(&quot;username&quot;);
    }
    public int getAcctDetailsTimer()
    {
        return acctDetailsTimer;
    }

    public void setAcctDetailsTimer(int acctDetailsTimer)
    {
        this.acctDetailsTimer = acctDetailsTimer;
        this.valuesChanged = true;
    }

    public int getDivisor()
    {
        return divisor;
    }

    public void setDivisor(int divisor)
    {
        this.divisor = divisor;
        this.valuesChanged = true;
    }

    public int getMPricesTimer()
    {
        return mPricesTimer;
    }

    public void setMPricesTimer(int mPricesTimer)
    {
        this.mPricesTimer = mPricesTimer;
        this.valuesChanged = true;
    }

    public int getRiskPercentage()
    {
        return riskPercentage;
    }

    public void setRiskPercentage(int riskPercentage)
    {
        this.riskPercentage = riskPercentage;
        this.valuesChanged = true;
    }

    public int getSportID()
    {
        return sportID;
    }

    public void setSportID(int sportID)
    {
        this.sportID = sportID;
        this.valuesChanged = true;
    }

    public int getStakeWinPercentage()
    {
        return stakeWinPercentage;
    }

    public void setStakeWinPercentage(int stakeWinPercentage)
    {
        this.stakeWinPercentage = stakeWinPercentage;
        this.valuesChanged = true;
    }

    public int getStopLossPercentage()
    {
        return stopLossPercentage;
    }

    public void setStopLossPercentage(int stopLossPercentage)
    {
        this.stopLossPercentage = stopLossPercentage;
        this.valuesChanged = true;
    }

    public int getUnmatchedBetTimer()
    {
        return unmatchedBetTimer;
    }

    public void setUnmatchedBetTimer(int unmatchedBetTimer)
    {
        this.unmatchedBetTimer = unmatchedBetTimer;
        this.valuesChanged = true;
    }

    public String getUsername()
    {
        return username;
    }

    public void setUsername(String username)
    {
        this.username = username;
        this.valuesChanged = true;
    }
}</pre>
</div>You should be able to see what it is I have done here. In the constructor, I have created a new object of the class Properties(). I have then created an InputStream and set its path to the path within my package structure (classpath) which will lead it to my created properties file. (In netbeans, you can create and edit these files by accessing the File | New File | Other sets of menus and dialogs)<br />
<br />
Since we are performing IO, which can throw exceptions which must be caught, we have a try...catch block within the constructor, where we load the InputStream into the Properties object, allowing us to use the Properties API to access our settings.<br />
<br />
By creating the instance variables and their associated getters and setters, I can now treat the properties file as a plain old java object, or POJO as the in crowd would have you refer to it.<br />
<br />
Since I have created it as a custom object, I can access these settings anywhere within my code, by doing <br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 66px;
		text-align: left;
		overflow: auto">ConfigObject con = new ConfigObject();
con.getMPricesTimer();
&lt;etc, etc&gt;...</pre>
</div>Of course, this sort of thing may well be old hat to some of you guys, but it impressed the hell out of me when I got it working.<br />
<br />
Alan</div>

]]></content:encoded>
			<dc:creator>ThanksFish</dc:creator>
			<guid isPermaLink="true">http://forum.bdp.betfair.com/blog.php?b=9</guid>
		</item>
		<item>
			<title>Logging into Betfair using Netbeans pt II(c)</title>
			<link>http://forum.bdp.betfair.com/blog.php?b=8</link>
			<pubDate>Mon, 09 Feb 2009 19:37:46 GMT</pubDate>
			<description><![CDATA[Last one now - future blarticles should be less wordy, with any luck. 
 
Now we need a dialog to use it with. This won't take anywhere near as long...]]></description>
			<content:encoded><![CDATA[<div>Last one now - future blarticles should be less wordy, with any luck.<br />
<br />
Now we need a dialog to use it with. This won't take anywhere near as long as the login code took, so don't panic, we are nearly finished.<br />
<br />
Look in the package tree of your project for the package named whatever you called your project. Inside that package, you should find a file called '&lt;yourProjectName&gt;View.java'.<br />
<br />
Double click on that to open it up and we'll set up the login dialog.<br />
<br />
You will need: <br />
<br />
1 Panel;<br />
3 JLables;<br />
1 JTextField<br />
1 JPassword Field<br />
1 JButton.<br />
<br />
The reason for the panel is to put all of the other components in - keeps things a bit tidier than having them scattered all over the form.<br />
<br />
When you drag the panel onto the main form, size it up to what you think it should be, then right click it, choose 'Properties' from the menu and change the border style to something you like the look of. I used the Etched Border, but thats just me. <br />
<br />
Put the two JLabels in, following the guides netbeans provides when you are moving them around within the panel. For the moment, we won't worry about naming them, however we will change the text. Right click them in turn and choose 'Edit Text' from the menu. The first one should be 'Betfair Username', the second 'Betfair Password'.<br />
<br />
Drag a JTextField onto the panel, then use the right click menu to rename it to 'txtUsername'. Following that, drag a JPasswordField onto the panel and rename it to txtPassword. While you are at it, right click each of them to edit the text, then clear the text completely. They will probably jump back to be a ridiculous size, so just use the resizing handles to get them back to a reasonable size.<br />
<br />
Drag a JButton onto the panel, edit the text so it says 'Login' and rename it to 'btnLogin'. Finally, put another label underneath all that, rename it to lblLoginResult and change the text to 'Login: ' with an empty space at the end.<br />
<br />
Once all thats done, right click the JButton, find the 'Events' entry and follow it through to the 'Action | actionPerformed' entry. Click that and you will see the code for the form you are working on, with a method already created and ready for some code.<br />
<br />
Strictly speaking, what I'm going to show you isn't terribly good form for coding - we should be using ActionListeners and the ActionEvent generated when we click the button, however the way I am showing you will work perfectly well and I reckon I've blathered on here enough already.<br />
<br />
So within that method, which looks like this:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 66px;
		text-align: left;
		overflow: auto">private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}</pre>
</div>delete the '// TODO...' line and replace it with this:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 210px;
		text-align: left;
		overflow: auto">    String uName = this.txtUsername.getText();
    char[] pWord = this.txtPassword.getPassword();
    Login log = new Login(uName, pWord);
    if (log.isLoggedIn())
    {
        this.lblLoginResult.setText(&quot;Login: OK&quot;);
        this.txtPassword.setText(&quot;&quot;);
        this.txtUsername.setText(&quot;&quot;);
        this.txtPassword.setEnabled(false);
        this.txtUsername.setEnabled(false);
        this.btnLogin.setEnabled(false);
    }</pre>
</div>The reason we cleared the text and password boxes and set the buttons and textboxes to disabled is so we can't accidentally use them again after we are logged in. It wouldn't do any serious harm really, but it might set off an exception which is a pain in the backside. Also, the password is stored in a char array on the main form. While it is pretty unlikely, it is possible that some sort of internet nasty may grab it out of there and use it in a nefarious manner. Doing it this way just tidies things up.<br />
<br />
So there we have it, the login should work properly, provided you have a funded account which has seen some activity within the last three months. If it doesn't, leave a comment with the problem and We will see what we can do.<br />
<br />
I'll leave you with a couple of things to think about. Firstly, in order to make any other call on the API after you have logged in, you have to include an object called an APIRequestHeader(), which is simply an object you set in the request you are making and holds the sessionToken returned from each API call. You get the first one with the LoginResp. Have a think about how you are going to store the sessionToken you get back from the LoginReq so you can use it in your next API call.<br />
<br />
Secondly, there are a few ways to organise the data you are going to get back from the API when you start making calls to it. The obvious way to do it is to use JTables.  Start reading up on them - the Java Tutorial at the sun website is a good place to start.<br />
<br />
I've attached the project as it stands so far to this post, so you can have a look over what I've done. When you open it up, right click on each of the web service clients and choose 'Refresh Client'. From there, you should be good to go.<br />
<br />
Have fun with it - think about where you want to take it and start playing with it.<br />
<br />
I want to reiterate here that the vast majority of what I'm showing here is not necessarily my own work. It is stuff I've picked up from courses, stuff I've read in other articles online and most importantly, stuff from other people who have taken the time to answer the sometimes ridiculous questions I have been known to ask. If you have a system, thats great, play with it. But stuff like this, the basic stuff - it isn't made of gold and it doesn't hurt to let people know how to do it. So if you see someone posting a question in the forums and you think you know the answer to it, have a stab at it. The worst that can happen is that you will learn that you were doing it wrong, which can only be a good thing.<br />
<br />
<br />
--------<br />
<br />
“Microsoft has a new version out, Windows XP, which according to everybody is the ‘most reliable Windows ever.‘  To me, this is like saying that asparagus is ‘the most articulate vegetable ever.‘ “<br />
(Dave Barry)</div>


<!-- attachments -->
	<div style="margin-top:10px">

		
		
		
		
			<fieldset class="fieldset">
				<legend>Attached Files</legend>
				<table cellpadding="0" cellspacing="3" border="0">
				<tr>
	<td><img class="inlineimg" src="http://forum.bdp.betfair.com/images/styles/nature/attach/zip.gif" alt="File Type: zip" width="16" height="16" border="0" style="vertical-align:baseline" /></td>
	<td><a href="http://forum.bdp.betfair.com/blog_attachment.php?attachmentid=6&amp;d=1234208175">BlogTute.zip</a> (1.51 MB, 164 views)</td>
</tr>
				</table>
			</fieldset>
		

	</div>
<!-- / attachments -->
]]></content:encoded>
			<dc:creator>ThanksFish</dc:creator>
			<guid isPermaLink="true">http://forum.bdp.betfair.com/blog.php?b=8</guid>
		</item>
		<item>
			<title>Logging into Betfair using Netbeans pt II(b)</title>
			<link>http://forum.bdp.betfair.com/blog.php?b=7</link>
			<pubDate>Mon, 09 Feb 2009 19:29:54 GMT</pubDate>
			<description>Part two finishes the class off and shows the completed class at the end. 
 
______________________ 
 
In the code which has just been created for...</description>
			<content:encoded><![CDATA[<div>Part two finishes the class off and shows the completed class at the end.<br />
<br />
______________________<br />
<br />
In the code which has just been created for you, find the lines<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 50px;
		text-align: left;
		overflow: auto">com.betfair.publicapi.types.global.v3.LoginReq request = new com.betfair.publicapi.types.global.v3.LoginReq();
            // TODO process result here</pre>
</div>Highlight the '// TODO...' line and hit delete, we don't need that bit.<br />
<br />
Now, the request is what we are sending, the result is what we want. If you have spent any time looking at the API documentation, you will see there are parameters which we have to supply in the request in order to get logged in. So, hit return once and type the following:<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 66px;
		text-align: left;
		overflow: auto">request.setProductId(this.prodID);
 request.setPassword(String.valueOf(this.password));
 request.setUsername(this.username);</pre>
</div>What you will have noticed while you were doing that is that netbeans gives you really big hints as to what it thinks you are going to type next. This is incredibly useful, however sometimes it gets things wrong, so if you take its advice, make sure it puts the correct variable in place. For example, when I typed 'request.setPassword()' it tried to put the username in between the brackets. Obviously, this wouldn't have worked. Use the hinting, but keep an eye on it.<br />
<br />
Ok, the next line you should see is the one which actually does the work.<br />
<br />
What this line does is create the LoginResp object by placing the request object into the port object created earlier. Since the port object was made with the BFGlobalService_Service object, we have a clear process which shows us how the login works. The BFGlobalService_Service object is the object which actually handles the connection to the API. The port object opens a sort of window into the BFGlobalService_Service object, which will only accept objects of type LoginReq. When you are making other calls, like MarketPricesReq and so on, the port will be configured to only take objects shaped like those calls. Once you get yourself up and running properly, you will find yourself able to take advantage of this system, by creating an interface to the port object. Look up Java Interfaces if you don't know what I am talking about here - they are extremely useful things.<br />
<br />
Directly below the line <br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto">com.betfair.publicapi.types.global.v3.LoginResp result = port.login(request);</pre>
</div>you will see a line <br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto">System.out.println(&quot;Result = &quot; + result);</pre>
</div>which is useful for knowing whether or not you actually managed to connect to the API, but not terribly useful for anything else. So we will sort ourselves out with something else to let us know what has happened.<br />
<br />
In order to do that, we have to interrogate the LoginResp object. Directly underneath that last line of code, put the following in:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 162px;
		text-align: left;
		overflow: auto">            System.out.println(&quot;Logged in: &quot; + result.getErrorCode().value());
            System.out.println(&quot;Currency: &quot; + result.getCurrency());
            System.out.println(&quot;Time of request: &quot; + result.getHeader().getTimestamp().toString());
            System.out.println(&quot;SessionToken: &quot; + result.getHeader().getSessionToken());
            if (result.getErrorCode().value().equals(&quot;OK&quot;))
            {
                this.loggedIn = true;
            }
            log = result;</pre>
</div>Now, underneath all that, you should have a closing brace, followed by a little block of code which looks like this:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 82px;
		text-align: left;
		overflow: auto">        catch (Exception ex)
        {
            // TODO handle custom exceptions here
        }</pre>
</div>Highlight the '//TODO...' line and hit backspace, we don't need it right now. Replace it with the following:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto">ex.printStackTrace();</pre>
</div>Now, directly beneath that, type the following:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto">return log;</pre>
</div>Now, go back up to where the instance variables are (where it says 'private String username;' and so on) and add the following variable:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto">private LoginResp login;</pre>
</div>In the constructor - where we initialised the username and password variables - add the following line:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto">this.login = this.doLogin();</pre>
</div>Now, to finish off the Login class, we'll add some getters.<br />
<br />
Underneath the last closing brace of the doLogin() method but above the final closing brace of the class, hit enter a couple of times to get some blank space.<br />
<br />
Right click on one of those lines and choose 'Insert Code...'. This time, on the sub-menu, choose 'Getter...'. You will be presented with a dialog which shows the instance variables of the class. The ones we want to be able to get at are the boolean variable loggedIn and the LoginResp login. Put a tick in the boxes next to those variables and click the generate button.<br />
<br />
Two small blocks of code are generated, with public access modifiers rather than private ones.<br />
<br />
With that, the login class is finished. It should look a bit like this:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 498px;
		text-align: left;
		overflow: auto">/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wsops;

import com.betfair.publicapi.types.global.v3.LoginResp;

/**
 *
 * @author alan
 */
public class Login
{

    private String username;
    private char[] password;
    private final int prodID = 82;
    private boolean loggedIn;
    private LoginResp login;

    public Login(String username, char[] password)
    {
        this.username = username;
        this.password = password;
        this.login = this.doLogin();

    }

    private LoginResp doLogin()
    {
        LoginResp log = new LoginResp();


        try
        { 
            com.betfair.publicapi.v3.bfglobalservice.BFGlobalService_Service service = new com.betfair.publicapi.v3.bfglobalservice.BFGlobalService_Service();
            com.betfair.publicapi.v3.bfglobalservice.BFGlobalService port = service.getBFGlobalService();
            
            com.betfair.publicapi.types.global.v3.LoginReq request = new com.betfair.publicapi.types.global.v3.LoginReq();
            
            request.setProductId(this.prodID);
            request.setPassword(String.valueOf(this.password));
            request.setUsername(this.username);
            
            com.betfair.publicapi.types.global.v3.LoginResp result = port.login(request);
            
            System.out.println(&quot;Result = &quot; + result);
            System.out.println(&quot;Logged in: &quot; + result.getErrorCode().value());
            System.out.println(&quot;Currency: &quot; + result.getCurrency());
            System.out.println(&quot;Time of request: &quot; + result.getHeader().getTimestamp().toString());
            System.out.println(&quot;SessionToken: &quot; + result.getHeader().getSessionToken());
            if (result.getErrorCode().value().equals(&quot;OK&quot;))
            {
                this.loggedIn = true;
            }
            log = result;
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
        return log;
    }

    public boolean isLoggedIn()
    {
        return loggedIn;
    }

    public LoginResp getLogin()
    {
        return login;
    }
    
    
}</pre>
</div></div>

]]></content:encoded>
			<dc:creator>ThanksFish</dc:creator>
			<guid isPermaLink="true">http://forum.bdp.betfair.com/blog.php?b=7</guid>
		</item>
		<item>
			<title>Logging into Betfair using Netbeans pt II(a)</title>
			<link>http://forum.bdp.betfair.com/blog.php?b=6</link>
			<pubDate>Mon, 09 Feb 2009 19:26:47 GMT</pubDate>
			<description><![CDATA[Ok, I've rambled on a bit in this post, so I'm going to try to deliver this in three entries - I'll try to break them up fairly logically though. 
...]]></description>
			<content:encoded><![CDATA[<div>Ok, I've rambled on a bit in this post, so I'm going to try to deliver this in three entries - I'll try to break them up fairly logically though.<br />
<br />
_____________<br />
<br />
Ok, I promised I would set something up to help you guys get logged into the system, and thats exactly what I'm going to do right now.<br />
<br />
What I'm going to show you is two different ways of doing it. One is extremely simple, the other is not so simple, but has its own advantages. <br />
<br />
The first way of doing it is the direct method. We don't need to muck around with editing the WSDL, we can just do it with our setup as it is now, assuming you followed the instructions in the previous blog article (Blarticle? Artilog? Bloticle? I dunno).<br />
<br />
So, assuming you have everything in place, right click your project in the projects explorer and choose &quot;New|Java Class&quot;. In the wizard which opens up, name the class Login and put it into a sensible package. I would probable get into a lot of trouble at a professional coding house, because I have packages for lots of slightly different things. For instance, if the class is going to perform a web service call on the exchange WSDL, it goes into me.ms.wsops.exchange package, where me is a convenient starting point, ms is the abbreviated name of my app, wsops is web service operations and exchange is the WSDL I'm accessing. It sounds long winded, but it helps me keep organised. Figure out a system which works for you.<br />
<br />
When you have figured out which package to put it in, click finish and let netbeans do its stuff. Once the class has been created, you should end up with a blank netbeans class - we'll get to work on filling it up now.<br />
<br />
There are a few things you need to provide which you are logging in to Betfair. The two obvious ones are the username and the password. So just underneath the class declaration (where it says public class Login { ) type:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 50px;
		text-align: left;
		overflow: auto">private String username;
private char[] password;</pre>
</div>now you also need to supply the product ID in the login request as well, so we'll set that up here too:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto">private final int prodID = 82;</pre>
</div>While we are at it, we'll create a boolean field called 'loggedIn'.<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto">private boolean loggedIn;</pre>
</div>Now with those sorted out, lets get something generated for us.<br />
<br />
On a blank part of the screen, but between the two class braces, right click to get a popup menu and choose &quot;Insert Code...&quot;. In the secondary popup menu which comes up, choose &quot;Constructor&quot;. Again, another dialog comes up which gives you a few choices. Now the two fields we want to initialise with the constructor are the username and password, so put a tick in each of the boxes next to those two variables and click &quot;Generate&quot;.<br />
<br />
With that, netbeans will create the constructor and initialise the variables in one fell swoop. <br />
Inside the constructor, we want to set our boolean loggedIn to false, because when we are creating the object, we aren't logged in yet. We will set it to true later, when we are.<br />
<br />
Once thats done, we will create a method which will do our actual logging in for us.<br />
<br />
Below and outside the constructor, but still within the class braces, type:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto">private LoginResp doLogin()</pre>
</div>and hit enter. Type one opening brace and hit enter. Netbeans will generate the closing curly brace and place the cursor between them.<br />
<br />
What will also happen is you will get a curly red line underneath the word 'LoginResp' and a red icon with a yellow lightbulb on the left of the editing area. If you click the red and yellow icon and you have set up your WSDLs properly, netbeans will offer to import the class we are referring to. Accept that offer and at the top of your class, above the class declaration, you will find netbeans has put <br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto">import com.betfair.publicapi.types.global.v3.LoginResp;</pre>
</div> onto the page.<br />
<br />
Now, within the new method we just created, type the following:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto">LoginResp log = new LoginResp();</pre>
</div>Hit enter again and we'll get into the meat of the code. <br />
<br />
IDE's are great things, they can make coding very simple, especially when you see how they can take a lot of the drudgery out of coding. However, there is also a risk that because you are using an IDE like netbeans or eclipse, you don't actually have a full understanding of what it is you are doing. Thats no big deal in the short term, because you will learn this stuff almost by osmosis, but there will be times when you simply don't understand something and the IDE can't or won't tell you. When you get to that point, you can either curse and snarl or you can decide to figure it out. Cursing and snarling isn't terribly productive, so when you decide to figure it out, use the search engines, create lots of ittle projects which help you demonstrate to yourself what is going on and above all, don't think it is too hard. It isn't too hard, it is just something you haven't understood yet. You will see what I mean in this next step.<br />
<br />
You should have your cursor on a new line underneath the code you just typed. Right click so you get a context menu and right at the bottom of the menu, you should see an entry 'Web Service Client Resources' with an arrow beside it. Follow the arrow and click on the sub-menu which appears. In the dialog which appears, you should see the your project name and the two web service clients you created in the previous blarticle. One should be called BFGlobalService, the other, BFExchangeService.<br />
<br />
Expand the BFGlobalService tree until you can see all the different calls - they are marked with red icons. Find the login one and click on it, then click 'Ok'.<br />
<br />
Now, everything will probably look a little untidy, so right click anywhere on the page and choose 'Format' from the menu.<br />
<br />
If you look at what has been created here, you will get a sense of what I was talking about above. Just looking at it, unless you have a decent knowledge of what is happening, you are unlikely to know what it all means. However, if you remember the fact that Java is an Object Oriented language, you can start to puzzle it out. The first two lines are creating objects which are necessary to be able to use the object created in the third line. I won't go into it in too much detail - we want to use it at the moment, not talk about it.<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 5px;
		border: 1px inset;
		width: 640px;
		height: 242px;
		text-align: left;
		overflow: auto">        try
        { // Call Web Service Operation
            com.betfair.publicapi.v3.bfglobalservice.BFGlobalService_Service service = new com.betfair.publicapi.v3.bfglobalservice.BFGlobalService_Service();
            com.betfair.publicapi.v3.bfglobalservice.BFGlobalService port = service.getBFGlobalService();
            // TODO initialize WS operation arguments here
            com.betfair.publicapi.types.global.v3.LoginReq request = new com.betfair.publicapi.types.global.v3.LoginReq();
            // TODO process result here
            com.betfair.publicapi.types.global.v3.LoginResp result = port.login(request);
            System.out.println(&quot;Result = &quot; + result);
        }
        catch (Exception ex)
        {
            // TODO handle custom exceptions here
        }</pre>
</div>Looks a bit better now, so we'll start supplying parameters to the request.<br />
<br />
________________<br />
<br />
Two more to go, the last one will have the project as it is now attached to it.</div>

]]></content:encoded>
			<dc:creator>ThanksFish</dc:creator>
			<guid isPermaLink="true">http://forum.bdp.betfair.com/blog.php?b=6</guid>
		</item>
		<item>
			<title>Update soon</title>
			<link>http://forum.bdp.betfair.com/blog.php?b=5</link>
			<pubDate>Tue, 03 Feb 2009 13:35:42 GMT</pubDate>
			<description>Ok, I realise its been a while since I first started this little series of articles, but there will be an update very soon - within the next couple...</description>
			<content:encoded><![CDATA[<div>Ok, I realise its been a while since I first started this little series of articles, but there will be an update very soon - within the next couple of days. As you may have noticed from a couple of the threads in the forum, I've been struggling with a couple of things myself. Concurrency is hard, I'll happily say it again. However, I think it is starting to click.<br />
<br />
Alan</div>

]]></content:encoded>
			<dc:creator>ThanksFish</dc:creator>
			<guid isPermaLink="true">http://forum.bdp.betfair.com/blog.php?b=5</guid>
		</item>
		<item>
			<title>Getting started with Netbeans</title>
			<link>http://forum.bdp.betfair.com/blog.php?b=4</link>
			<pubDate>Mon, 19 Jan 2009 15:24:10 GMT</pubDate>
			<description><![CDATA[Ok, now if you look through both this forum and the old forum, you will see that I've been fairly active here, asking questions when I didn't know...]]></description>
			<content:encoded><![CDATA[<div>Ok, now if you look through both this forum and the old forum, you will see that I've been fairly active here, asking questions when I didn't know the answer and answering questions when I did, or even when I didn't, but thought I did.<br />
<br />
What that has meant though, apart from my cluttering up the forum with wordy posts, is that every now and then I get an email from someone who wants to learn how to do something interesting with the free Betfair API. I'm generally pretty happy to help out, because a lot of what I know about getting something done on the computer I picked up by applying a bit of thought and most importantly, reading how to do it on the internet. None of which cost me anything, so passing it on is something I feel I owe.<br />
<br />
All of that out of the way, lets have a look at the very first thing you generally want to do with the API. That would be to get programmatical access to the API itself.<br />
<br />
Before we get to stuff like that though, you need to have a development environment set up. I use netbeans 6.1 and all the code and instructions will be based around that, but if you are comfortable using something else and can work out a couple of the details which netbeans seems to make so easy, feel free.<br />
<br />
You need a couple of things first though. In order to even run netbeans, you need the latest Java Virtual Machine, which can be obtained from the <a href="http://www.java.com/en/download/manual.jsp" target="_blank">Sun website.</a> Once you have the version applicable to your computer, install it. Unless you really know what you are doing, just keep all the default settings during the install.<br />
<br />
With that done, go to <a href="http://www.netbeans.org" target="_blank">the netbeans website</a> and download the latest version of netbeans. These days netbeans is starting to get a bit like Eclipse, with so many different versions for different uses it's hard to choose. I just tend to get the complete edition and go through the install process. While you are installing it, the wizard will give you the option of installing a few different servers. Its up to you, but unless you are running desperately low on hard drive space, it does no harm to install them. They don't install themselves as services and they don't start up when your machine boots up. You can set them up that way, but as installed, they are mainly intended to be testing and development servers. <br />
<br />
In addition, something a lot of people find themselves doing is developing their betfair bots as web deployable bots, meaning the owner of the bot will rent a server of some description from an ISP and deploy their bots on the rented server. What that means is that because they aren't running their bot from their home broadband connection, but are using machines and connections owned by the ISP. Since an ISP by its very nature generally has a low latency/high bandwidth connection, those web deployed bots will have a significant advantage in speed - if they have been coded properly.<br />
<br />
Thats all pretty advanced stuff, so lets get on with logging in using our poxy (don't worry, its all I have too) home broadband connection.<br />
<br />
Assuming you have set up Java correctly and it all works and assuming you have set up Netbeans and have it open in front of you, start a new Java Desktop Application and in the next step, choose 'Basic Application' and give your project a name and somewhere to live on your hard drive. I generally go for something imaginative like 'Netbeans Projects' as the root directory and any created projects live in their own folders in there.<br />
<br />
Once netbeans has created the project for you, you should have two or three tabs open, with the various files created for the project. At the moment, we aren't going to be using the 'AboutBox' form or the Main class, so feel free to close them.<br />
<br />
On the left of the screen, you should see the project explorer, with your project showing. Right click the project and choose 'New/Web Service Client...'. If you don't see the option immediately, choose 'New/Other...' and in the dialog which appears, go into the 'Web Services' section and you should find it there. If you still can't find it, go to the 'Tools' menu at the top of the screen and choose 'Plugins'. <br />
<br />
What you need to do in there is make sure there is a 'Web Services' plugin installed and active. You have a few tabs there. The one you should initially see is 'Available'. If the 'Web Services' plugin appears there, put a tick in the box and let netbeans install it for you. If it isn't in the 'Available' section, have a look in the 'Installed' section. If it is in there, make sure it is active and try to create the client again.<br />
<br />
Once you have made it to creating the web service client, you will be confronted by a dialog box asking for a WSDL.<br />
<br />
Open up a web browser and go to the BDP website. Just under the Developers Program logo image, choose 'Sports' then 'Quick-Start' from the pop up menu.<br />
<br />
On the page which appears, scroll down till you see 'Sports API 6', you should see three links below that heading. Those links lead directly to the WSDL (Web Service Description Language) files operated by Betfair. If you click on them (which it is worth doing, even just the once) all you will see is an XML file. <br />
<br />
In the mean time, right click on the first link, which says 'Sports API(Global Services) WSDL and in Firefox, choose 'Copy Link Location'. If you are using Internet Explorer, shame on you, but choose 'Copy Shortcut' from the popup menu.<br />
<br />
Back in Netbeans at the 'New Web Serice Client' dialog, click in the radio button next to the words 'WSDL URL' and place the cursor into the textbox next to the radio button.<br />
<br />
In order to paste the URL into the textbox, use the keyboard shortcut 'CTRL-V'. For some reason right clicking in there doesn't bring up a context menu in Netbeans 6.1, so using the keyboard shortcut is the easiest way to do it.<br />
<br />
Once you have done all of that, make sure your project appears in the Location section of the dialog and click 'Finish'. Netbeans will start downloading and compiling the necessary classes for you. It won't take long and it may be that you need to accept a couple of security certificates during the process. When it is done, repeat the process for the next link, which is the UK Exchange Services WSDL.<br />
<br />
Once it is all done, you should have a new package in your project called 'Web Service References'. If you expand that package - its just a node on a JTree - you should see further references to the various parts of the API. In particular, expand the node named 'BFGlobalService' till you see the 'login' node. Thats the one we will be playing with in the next installment.<br />
<br />
Everything I've done here is all pretty simple stuff. I should also point out that while I'll be explaining some of the basic Java stuff, I'm going to be assuming a certain amount of knowledge already. If you don't have it, it isn't that big a deal. Google is your best friend. Another useful thing to have is the netbeans plugin named 'Java SE API Doc English Version', which allows you to right click on a word in Java and choose 'view Javadoc' from the context menu. A web browser opens and you are taken to the Javadoc for that word. <br />
<br />
If you have absolutely no idea about programming, it is still no big deal, you just need to do a bit of initial headwork. Head on over to the <a href="http://java.sun.com/docs/books/tutorial/index.html" target="_blank">Sun tutorial website</a> and start working your way through them. It might seem tiresome to start at the very beginning, but it really is worth doing. <br />
<br />
Another thing which is worth doing, is writing down exactly what it is you are trying to do. Once you have it written down, reduce it to steps and work out exactly what you need for each individual step to take place. Once you have that, start googling, you will come up with the answer eventually.<br />
<br />
Apart from that, have some fun!<br />
<br />
-----<br />
<br />
“First, solve the problem. Then, write the code.”<br />
(John Johnson)</div>


<!-- attachments -->
	<div style="margin-top:10px">

		
			<fieldset class="fieldset">
				<legend>Attached Thumbnails</legend>
				<div style="padding:3px">
				<a href="http://forum.bdp.betfair.com/blog_attachment.php?attachmentid=3&amp;d=1232378528"><img class="thumbnail" src="http://forum.bdp.betfair.com/blog_attachment.php?attachmentid=3&amp;stc=1&amp;thumb=1&amp;d=1232378528" border="0" alt="Click image for larger version

Name:	netbeans-new-webservice-client.jpg
Views:	265
Size:	18.5 KB
ID:	3" /></a>
&nbsp;
				</div>
			</fieldset>
		
		
		
		
			<fieldset class="fieldset">
				<legend>Attached Files</legend>
				<table cellpadding="0" cellspacing="3" border="0">
				
				</table>
			</fieldset>
		

	</div>
<!-- / attachments -->
]]></content:encoded>
			<dc:creator>ThanksFish</dc:creator>
			<guid isPermaLink="true">http://forum.bdp.betfair.com/blog.php?b=4</guid>
		</item>
		<item>
			<title>FROSTY P....done it again, sorry.</title>
			<link>http://forum.bdp.betfair.com/blog.php?b=3</link>
			<pubDate>Sun, 18 Jan 2009 14:40:37 GMT</pubDate>
			<description>Vossie suggested (https://forum.bdp.betfair.com/showthread.php?p=74#post74) that I start writing a blog on here in a reply to one of my posts, so...</description>
			<content:encoded><![CDATA[<div>Vossie <a href="https://forum.bdp.betfair.com/showthread.php?p=74#post74" target="_blank">suggested</a> that I start writing a blog on here in a reply to one of my posts, so I'll have a go at it - with the disclaimer that everyone keep in mind that I consider myself very much a beginner at both coding and working with the Betfair API.<br />
<br />
A bit of background first though. I'm an Australian living in the UK, having met the lady who is now my wife in a napster (remember napster? Before it was rubbish? I do) chatroom. After eighteen months and a combined total of £2000 of telephone bills, we decided it would be cheaper to talk to each other face to face. <br />
<br />
So, I dropped out of my degree in Journalism and came over to the UK for a six month visit in late 2002. In 2004 I came over here permanently and in early 2006, I started studying at the Open University, with the idea that I start with a subject which was out of my comfort zone, to get me back into the habit of studying. After I had finished that, I was going to move on into my real interest, which was computing and programming.<br />
<br />
Accordingly, having hated every second of my first subject (You and Your Money: Personal Finance in Perspective - as I said, totally out of my comfort zone, but useful nonetheless) but managing to get reasonable marks for it, I started in on Java programming courses and Cisco network engineering.<br />
<br />
Now the only programming I had ever done before was attempting to write a lottery number picker in VB6 and failing miserably (have you ever had visual studio tell you a module was too big? I have. Just over a megabyte uncompressed), I seemed to take to Java pretty well. <br />
<br />
About the same time I started that course, a friend introduced me to Betfair and it didn't take long for me to find the Betfair Developers Program and the free API.<br />
<br />
Now in Australia, soccer (or football as it is known in the UK) wasn't a terribly big sport until the 2006 world cup, which saw Australia in the finals for the first time in years. Being in the UK though, I've been watching it with more and more enthusiasm since I came over. Watching the matches in-play on Betfair gave me extra interest and before long, I was making manual bets using a system of my own devising.<br />
<br />
Putting two and two together, I started writing my first betfair bot with that system in mind and it was ready to start raking in the cash on the last day of the premier league season in 2007. Bit of a bummer that, but never mind.<br />
<br />
That bot, with the same basic theory is now in its third iteration (working on the fourth currently) and seems now to be working nicely. <br />
<br />
What I plan to do with this blog is go through some of the mechanics of getting the thing going. As I said at the top of this post, I am by no means a master coder, so if I say anything in my posts which is wrong, correct me. If you get anything useful from it, use it. Let me know if you do use it if you like, but if you couldn't be bothered, thats fine too. What I'm hoping to do is chunter away quietly to myself, talking myself through the problems I encounter and hopefully learning a bit along the way. Since programmers generally hate to have to reinvent the wheel, making the solutions I come up with available just might help other new API developers.<br />
<br />
These are the main areas I will be focusing on in the foreseeable future. Which is probably a good week or two.<br />
<ul><li>General Java Programming;</li>
<li>Cuncurrency/Multithreading;</li>
<li>Persistence;</li>
<li>The Betfair API;</li>
<li>General Babble.</li>
</ul><br />
So with all that out of the way, I will hopefully not be waxing rhetorical on my next post.<br />
<br />
-------<br />
<br />
“If debugging is the process of removing bugs, then programming must be the process of putting them in.”<br />
(Edsger W. Dijkstra)</div>

]]></content:encoded>
			<dc:creator>ThanksFish</dc:creator>
			<guid isPermaLink="true">http://forum.bdp.betfair.com/blog.php?b=3</guid>
		</item>
	</channel>
</rss>
