The sample application is intended to show how the API is used by showing how to call some ReadOnly and Secure methods. It is a window application made in C# (.NET 1.1).

In this sample application we use the following BETDAQ ReadOnly API Methods: GetTopLevelEvents, GetEventSubTreeNoSelections, GetMarketInformation, GetPrices.

And the following BETDAQ Secure API Methods: GetAccountBalances, PlaceOrdersNoReceipt, CancelAllOrders, CancelOrders, ListBootstrapOrders, ListOrdersChangedSince.

Click Here To Download The Sample Application

The sample application provides code demonstrating how to call most of the key web methods and use the data structures returned. The application is broken into two projects; the first (GBE_UserInterface) is concerned only with the user interface of the windows form application. The second project (GBE_Data) provides agents (e.g. ReadonlyServiceAgent) for wrapping all calls to the API and converters (e.g. EventConverter) to translate the API’s types (EventClassifierType) into local types (Event).

As you will quickly realise, this sample application demonstrates only a subset of method calls, requires fine-tuning, and is far too simple to be used in a real world situation, its goal is simply to demonstrate the intended approach to using version 2.0 of the Global Betting Exchange API.

Each API call follows the standard request/response pattern, as can be seen by looking at the WSDL for the API (Figure 1). For example, to use the web method ListSelectionsChangedSince you first construct a ListSelectionsChangedSinceRequest object, and set the SelectionSequenceNumber. The web method then returns a ListSelectionsChangedSinceResponse object, which in this case contains a collection called Selections of type ListSelectionsChangedSinceResponseItem.

It should also be noted that every response object derives from BaseResponse which contains a ReturnStatus object that contains meta data about the web method call, for example whether an error was encountered.

Details page functionality

The UI for the sample application is broken into three pages, however the Details page offers most of the functionality. In order to connect and use the Global Betting Exchange API v2.0 you will need to start by setting the connection details found in the first panel of the page. The Secure and Readonly fields should never need to be changed, and are both joined with the Base URL field to construct the full URL for the API. The Username, Password and Base URL fields should be provided to you in an email. Pressing the Connect button simply instantiates the SecureServiceAgent and ReadonlyServiceAgent objects, which in turn creates private instances of the SecureService and ReadOnlyService proxy objects as defined in the API’s WSDL. So now every API call must go through the two agents, which in turn calls the relevant method on their private instance of the proxy.

Because simply setting up the API proxies won’t necessarily tell us if we have a problem, the Connect button finishes off by calling a web method to test the connection, in this case by calling the Get Details button’s event handler. Note: the form’s load event sets up the proxies as well, so typically you will only need to actually press the Connect button if you change the connection settings and so need to establish a new connection.

The second panel (Account Details) provides the Get Details button that simply calls the GetAccountBalances web method. As is the usual pattern, the agent object is called which in turn makes the actual web method call and receives a GetAccountBalancesResponse object in reply. This is then used to populate the five fields in the panel.

The third panel contains an Events TreeView control for displaying the event hierarchy. This control is first populated by pressing the Get Top Level Events button, which uses the ListTopLevelEvents web method to get the high level events, e.g. Soccer, Horse Racing, etc. When the plus symbol beside an event is clicked, the agent calls the GetEventSubTreeNoSelections web method to fetch the full event tree for that sport. Once the event sub-tree is fetched it is then stored in memory, this means the first time the sub-tree is expanded a significant delay may be encountered, however all subsequent expansions will be quick. Clicking on a market within the tree uses the GetPrices web method to populate the Selections DataGrid below it. This grid displays the top three back and lay prices for each selection.

The fourth panel displays details about the selected event, market and selection. You may then specify the amount, odds and polarity for a bet then add it to the list of orders waiting to be placed by clicking the Add Bets button. The Clear List button obviously removes all pending Bets to place, while the Place Bet button results in the PlaceOrdersNoReceipt web method being called. The order ids for each of the placed bets are then displayed below in the Bet Id(s) listbox. A number of these bet ids can be selected from the list at the same time and the Cancel Bets button pressed, resulting in the CancelOrders web method being called.

My Bets Page Functionality

This page demonstrates the use of two web methods that work hand in hand, ListBootstrapOrders and ListOrdersChangedSince. The typical way to use these functions is by starting with a bootstrapping cycle, this will give you all the existing bets up to the current time. Both these methods return a set number of bets per call, which means that multiple calls may need to be made in order to get all the bets. The basic rule to follow is that you should keep calling the method until no bets are returned or the sequence number of the last returned bet is equal to the maximum sequence number.

Once you’ve finished the bootstrapping cycle you should make a call to the ListOrdersChangedSince web method, passing in the MaximumSequenceNumber as a parameter, just in case a bet may have changed since the time you started the bootstrapping cycle.

Typically, in a real world scenario you would set up a timer to call the ListOrdersChangedSince web method regularly, however in this sample application you must press the ListOrdersChangedSince button yourself to make the call. If you don’t pass in the maximum sequence number from the bootstrapping cycle when you call the ListOrdersChangedSince web method then you will get back the full bet history again. To test the application is working as expected, complete the bootstrapping cycle, place a new bet then press the ListOrdersChangedSince button, this should result in the new bet being listed in the second DataGrid control.

Log Page Functionality

The function of this page is pretty obvious, each call to the web service results in information being written to this page. Presently, the only information displayed is the name of the web method call and the time taken. As you’ll see this logging functionality is too simple for a real world situation, results simply disappear of the bottom of the list, however this could easily be extended to output to a file of your choice.