Go Back   Developer Program Forum > Sports API > .NET

.NET Discussion about the .NET Framework (C#/VB), Microsoft's platform for building applications that have visually stunning user experiences, seamless and secure communication, and the ability to model a range of business processes.

Post Reply
 
Thread Tools Display Modes
  #271  
Old 11-04-2009, 12:14 PM
supunsilva. supunsilva. is offline
Member
 
Join Date: Aug 2009
Posts: 36
Default

Im sorry. It is not available in Free API. Thanks for your support

Thank you,
Supun Silva
  #272  
Old 11-17-2009, 12:26 PM
Mumbles0's Avatar
Mumbles0 Mumbles0 is offline
Senior Member
 
Join Date: Jan 2009
Posts: 318
Default Step 25. Accessing Australian Markets.

To access the Australian exchange you can add another web reference (as described in the note at the bottom of Step 5). This creates the BFAU namespace which contains an identical set of classes to BFUK. This is fine if you want to access the Australian exchange only. You simply create a BFAU web reference and use this (instead of BFUK) throughout your code.

But an app may want access to both UK and AU exchanges. Because BFAU and BFUK are namespaces, not objects, they cannot be simply assigned to variables. This leads to much code duplication. To illustrate this, consider a sub which calls getAllMarkets on either exchange using the separate web references:

Code:
Sub GetAllMarkets(ByVal Ex As Boolean)  'Ex = True for AU, False for UK

  If Ex Then  'AU exchange

    Dim ReqAU As New BFAU.GetAllMarketsReq
    Dim RespAU As BFAU.GetAllMarketsResp
    With ReqAU
      .header = oHeaderAU()
      'Set request parameters here
    End With
    RespAU = BetfairAU.getAllMarkets(ReqAU) 'Call AU exchange
    With RespAU
      CheckHeader(.header)
      If .errorCode = BFAU.GetAllMarketsErrorEnum.OK Then
        'Process response from AU exchange here
      Else
        Print("ErrorCode = " & .errorCode.ToString)
      End If
    End With

  Else   'UK exchange

    Dim ReqUK As New BFUK.GetAllMarketsReq
    Dim RespUK As BFUK.GetAllMarketsResp
    With ReqUK
      .header = oHeaderUK()
      'Set request parameters here
    End With
    RespUK = BetfairUK.getAllMarkets(ReqUK) 'Call UK exchange
    With RespUK
      CheckHeader(.header)
      If .errorCode = BFUK.GetAllMarketsErrorEnum.OK Then
        'Process response from UK exchange here
      Else
        Print("ErrorCode = " & .errorCode.ToString)
      End If
    End With
  End If

End Sub
Here you can see that much of the code is duplicated. You also need the additional BetfairAU service object, the oHeaderAU function and another CheckHeader sub. Problems can also arise when you try to process the response from the two servers. Even though the class BFAU.GetAllMarketsResp is identical to BFUK.GetAllMarketsResp the compiler assumes they are different. This can give rise to all sorts of problems and your code can become very messy. Perhaps some OOP guru can show us a better way of handling the two namespaces.

However, there is another way we can do this. I doubt that this is “best practice” but it works.

What we can do is write the code as if we are accessing the UK exchange only. Only one web reference (BFUK) is required. If we examine the service object BetfairUK we see that it has a .Url property. This property holds the web address (URL) of the server that it will access. By default this is set to the UK exchange server. If we change this, we can “trick” this service object into accessing the AU exchange server.

Code:
Sub GetAllMarkets(ByVal Ex As Boolean)   'Ex = True for AU, False for UK

  SelectExchange(Ex)    'Select the desired exchange URL

  Dim ReqUK As New BFUK.GetAllMarketsReq
  Dim RespUK As BFUK.GetAllMarketsResp
  With ReqUK
    .header = oHeaderUK()
    'Set request parameters here
  End With
  RespUK = BetfairUK.getAllMarkets(ReqUK)    'Call the exchange (AU or UK)
  With RespUK
    CheckHeader(.header)
    If .errorCode = BFUK.GetAllMarketsErrorEnum.OK Then
      'Process response here
    Else
      Print("ErrorCode = " & .errorCode.ToString)
    End If
  End With
End Sub

Sub SelectExchange(ByVal Ex As Boolean)   'Ex = True for AU, False for UK
  If Ex Then  'AU exchange
    BetfairUK.Url = "https://api-au.betfair.com/exchange/v5/BFExchangeService"   'URL of AU exchange
  Else        'UK exchange
    BetfairUK.Url = "https://api.betfair.com/exchange/v5/BFExchangeService"    'URL of UK exchange
  End If
End Sub
Sub SelectExchange selects either the AU or UK exchange by changing the value of the Betfair.Url property. Depending on the value of the parameter Ex the subsequent call to getAllMarkets returns data from the desired exchange.

This "trick" should work for all API exchange calls (although I have not fully tested this).

Last edited by Mumbles0; 11-23-2009 at 09:36 AM
  #273  
Old 01-13-2010, 02:44 PM
Aitor Aitor is offline
Junior Member
 
Join Date: Nov 2009
Posts: 19
Default

Hi good afternoon! I have problems when viewing shares on the Australian market, it gained from the tree visualization of events, but I can not see the market share. Thank you for your atentción and manejais any information here seems very interesting. I have the following error

Error 1 Value of type 'Betfair2._0.BFAU.GetMarketPricesReq' can not be converted to '1-dimensional array Betfair2._0.BFAU.GetMarketPricesReq '. C: \ Documents and Settings \ AITOR \ My Documents \ Visual Studio 2008 \ Projects \ Betfair2.0 \ Betfair2.0 \ TestForm.vb 158 16 Betfair2.0

because I created the following function

CuotasFavorContraToolStripMenuItem_Click Private Sub (ByVal sender As Object, ByVal e As System.EventArgs) Handles CuotasFavorContraToolStripMenuItem.Click
Print ("*** shares for and against in Fractions ")
ShowMprices (BetFairAU.getMarketPrices (MpricesReqAU))
End Sub

MpricesReqAU Function () As BFAU.GetMarketPricesReq ()
OMPReq Dim As New BFAU.GetMarketPricesReq ()
With oMPReq
. oHeaderAU header = ()
. market = ID '100985049 'titles from madrid to 3991990
End With
Return oMPReq
End Function

any solution?
  #274  
Old 01-13-2010, 10:51 PM
Mumbles0's Avatar
Mumbles0 Mumbles0 is offline
Senior Member
 
Join Date: Jan 2009
Posts: 318
Default Reply to Aitor

I don’t know what version of VB you are using but mine won’t accept names before keywords as shown in the code you have posted. I have re-arranged your code to that it compiles OK:

Code:
Private Sub CuotasFavorContraToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CuotasFavorContraToolStripMenuItem.Click
    Print("*** shares for and against in Fractions ")
    ShowMprices(BetFairAU.getMarketPrices(MpricesReqAU))
  End Sub

  Function MpricesReqAU() As BFAU.GetMarketPricesReq  '<<< Dont put brackets () at end
    Dim oMPReq As New BFAU.GetMarketPricesReq
    With oMPReq
      .header = oHeaderAU()
      .marketId = 100146716   '<<< Use a current AU marketId
    End With
    Return oMPReq
  End Function
If you add the brackets () at the end of the function statement:
Function MpricesReqAU() As BFAU.GetMarketPricesReq()
you are asking the function to return an array of objects of type GetMarketPricesReq, but you only require a single object of type GetMarketPricesReq. This causes the error “Value of type 'BetfairX.BFAU.GetMarketPricesReq' cannot be converted to '1-dimensional array of BetfairX.BFAU.GetMarketPricesReq”.
  #275  
Old 01-14-2010, 12:53 AM
MichaelRNye MichaelRNye is offline
Member
 
Join Date: Aug 2009
Posts: 88
Default

Quote:
Originally Posted by Mumbles0 View Post
However, there is another way we can do this. I doubt that this is “best practice” but it works.

What we can do is write the code as if we are accessing the UK exchange only. Only one web reference (BFUK) is required. If we examine the service object BetfairUK we see that it has a .Url property. This property holds the web address (URL) of the server that it will access. By default this is set to the UK exchange server. If we change this, we can “trick” this service object into accessing the AU exchange server.
I would suggest maintaining two exchange objects (BFUK & BFAU in your example) and using a function to select the exchange which returns a BFServiceExchange.

I program in C# so am not sure how the betfair api looks in VB, but my C# code looks like:

Code:
private BFExchangeService GetService(Exchange exchange)
    {
      BFExchangeService service = null;
        switch (exchange)
        {
          case Exchange.AU:
            service = _ExchangeServiceAU;
            break;
          case Exchange.UK:
            service = _ExchangeServiceUK;
            break;
        }        
      return service;
    }
With Exchange being a simple Enum I created with two values (AU and UK). The advantage this has over your method is it can handle parallel queries to both the AU and UK exchanges if you wanted to do that. It also is more fault tolerant, as if you are in the middle of querying something on the AU exchange then start a query on the UK exchange it will work fine. In your example it will change the UK's url and possibly break stuff.

And, by using an Enum rather than true/false, if a 3rd exchange comes along it is dead simple to add it in without breaking existing applications.

That's how I do it anyway.
  #276  
Old 01-14-2010, 03:35 AM
Mumbles0's Avatar
Mumbles0 Mumbles0 is offline
Senior Member
 
Join Date: Jan 2009
Posts: 318
Default UK & AU Exchange changeover

Michael,

I agree there must be a better way. You've got me scratching my head again. I should learn a bit more C#.

A question: Where is Class BFExchangeService defined?


Re: Exchange Enum: I used the Boolean parameter "to keep things simple". Your enum is a far more satisfactory way of doing it.
  #277  
Old 01-14-2010, 06:08 AM
MichaelRNye MichaelRNye is offline
Member
 
Join Date: Aug 2009
Posts: 88
Default

Quote:
Originally Posted by Mumbles0 View Post
Michael,

I agree there must be a better way. You've got me scratching my head again. I should learn a bit more C#.

A question: Where is Class BFExchangeService defined?


Re: Exchange Enum: I used the Boolean parameter "to keep things simple". Your enum is a far more satisfactory way of doing it.
It's defined by the betfair WSDL file @ https://api.betfair.com/exchange/v5/...geService.wsdl. Add it as a web reference to the project (in C# at least) and then it (among other betfair-defined classes/types) are available for use.

I don't believe there is a neater way to do it over a method similar to mine. Ultimately neatness is a personal thing and I find my method neat and easy to understand.
  #278  
Old 01-14-2010, 07:58 AM
Mumbles0's Avatar
Mumbles0 Mumbles0 is offline
Senior Member
 
Join Date: Jan 2009
Posts: 318
Default

Understood. BFExchangeService is a class defined by the WSDL for the UK Exchange.

Another question: How are _ExchangeServiceAU and _ExchangeServiceUK defined?
  #279  
Old 01-15-2010, 03:11 AM
MichaelRNye MichaelRNye is offline
Member
 
Join Date: Aug 2009
Posts: 88
Default

Quote:
Originally Posted by Mumbles0 View Post
Understood. BFExchangeService is a class defined by the WSDL for the UK Exchange.
Um, I don't believe it's specific to the UK exchange. betfair.api.exchange.BFExchangeService is the reference (no mention of UK there) and none of the functions are UK specific. I believe that's the entire idea - a single exchange service object which can be used for either UK or AU exchanges depending on how it is initialised

Quote:
Originally Posted by Mumbles0 View Post
Another question: How are _ExchangeServiceAU and _ExchangeServiceUK defined?
These are my own private variables. I have these defined in the class:

Code:
    public const string UKENDPOINT = "https://api.betfair.com/exchange/v5/BFExchangeService";
    public const string AUENDPOINT = "https://api-au.betfair.com/exchange/v5/BFExchangeService";

    private BFExchangeService _ExchangeServiceUK;
    private BFExchangeService _ExchangeServiceAU;
and then in the constructor:

Code:
      _ExchangeServiceUK = new BFExchangeService();
      _ExchangeServiceAU = new BFExchangeService();

      _ExchangeServiceUK.Url = UKENDPOINT;

      _ExchangeServiceAU.Url = AUENDPOINT;
  #280  
Old 01-15-2010, 12:13 PM
Mumbles0's Avatar
Mumbles0 Mumbles0 is offline
Senior Member
 
Join Date: Jan 2009
Posts: 318
Default

I see what you are doing now.

We assume the Australian WSDL is identical to the UK WSDL in all respects (except for the endpoint URL). This implies the Australian WSDL is redundant.

(I am going on holiday for a week or so. I will consider this further when I return.)
Post Reply

Tags
.net, tutorial, vb2008

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
vb2008 exchange games how? rotter .NET 0 11-14-2009 11:14 AM
Is there a tutorial ? pazgal PHP 11 10-31-2009 08:54 PM
Using VB2008 to acccess the Betfair API: Questions Tam's Loup .NET 5 05-04-2009 02:14 AM


All times are GMT. The time now is 11:15 PM.


BETFAIR® and the BETFAIR LOGO are registered trade marks of The Sporting Exchange Limited. Data on Betfair website(s) (including pricing data) is protected by © and database rights. It may not be used for any purpose without a licence. © The Sporting Exchange Limited. All rights reserved.