C# API6 Example Aplication (Async)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vossie
    BDP Team
    • Sep 2008
    • 40

    #1

    C# API6 Example Aplication (Async)

    The following application has been created to assist developers getting started with C# and API6 using the asynchronous methods.

    If you make improvements to this library please post them here so we can include these into the project.

    TODO:
    1) Error handling

    Change Log:
    2009/02/25
    • GetMarketPricesCompressed added (Thanks TalentedMaverick)
    • Cleaned up the delegate and seperated display from API actions
    Attached Files
    "Why don't you just fix your little problem and light this candle?" - Alan B. Shepard, Jr

  • The Geeks Toy
    Junior Member
    • Jan 2009
    • 6

    #2
    Originally posted by vossie View Post
    2) Use GetMarketPricesCompressed
    Vossie

    I've sent you something that decompresses the price calls. It should be a simple plug in.

    I'll let you integrate it, as I reckon you will do it in less time than it will take me to upgrade to 2008 & work out where the hell to plug it in to.

    TM

    Comment

    • vossie
      BDP Team
      • Sep 2008
      • 40

      #3
      Thanks maverick, that is a nice class. I have added it to the project (very little testing) but it appears to work.
      "Why don't you just fix your little problem and light this candle?" - Alan B. Shepard, Jr

      Comment

      • tagorac
        Junior Member
        • Jan 2009
        • 3

        #4
        For the benefit of international users, I think line 227 in BetfairSportsDataTypes.cs could to with some globalisation. Otherwise a price of evens gets converted to 200.

        Code:
        if (data != "NaN" && data != "")
            return Convert.ToDouble(data,
                System.Globalization.CultureInfo.InvariantCulture) ;
        Stephan

        Comment

        • The Geeks Toy
          Junior Member
          • Jan 2009
          • 6

          #5
          OK This has turned up on multiple threads, so I'll put my answers in here.


          To address 3 issues raised.

          Re AsianLineId -- The classes I provided are stripped back versions of those in my system which do complete price & traded volume decompression too. When taking out functionality, I forgot to remove this member, as it doesn't exist in this call. You can uniquely identify a selection for handicap markets in the call by using SelectionId & Handicap.

          Re Readability & '\' handling. -- Poster is correct it doesn’t handle these. In my application it doesn't need to. The only field this occurs in doesn't have a backslash & then the delimiter in them. {Doesn’t mean this will always be the case though.}

          Re International users, return Convert.ToDouble(data, System.Globalization.CultureInfo.InvariantCulture) ; Excellent tip. I’m just an English nerd who forgets about the rest of the world.


          Long and short, the classes suit my purpose, and whilst everyone may not agree with my style, they work well for me and have been doing so without issue for over a year now. They were donated to the wider community as an example from a working system, so you can either use them as is, make them better or adapt them for your own needs. My system was born from vossies old c# example application, and that's exactly what I did.

          For all of you who think you can do better, make them better, test them thoroughly & give them to vossie so that the next newbie that comes along doesn’t have to re-invent the wheel once again. If enough of you do this, who knows what you could achieve between you!
          Last edited by The Geeks Toy; 02-03-2009, 03:31 PM.

          Comment

          • flougr
            Junior Member
            • Jan 2009
            • 1

            #6
            Regarding the International users and the problem with dot and comma :

            A simpler solution would be to set CurrentCulture Once (just before InitializeComponents)

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            Comment

            • elmariachi
              Junior Member
              • Feb 2009
              • 16

              #7
              Originally posted by flougr View Post
              Regarding the International users and the problem with dot and comma :

              A simpler solution would be to set CurrentCulture Once (just before InitializeComponents)

              Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
              The problem with that is that when your app uses a multi lingual interface based on localization you will loose all localization functionality.
              There should be a seperation on data retrieval and the actualy app. The data retrieval part should be explicitly handled with some ToDouble etc. methods (as described above). These methods are needed anyway since the "NaN" and empty string issue have to be resloved as well. I think all of that code should reside in one place.

              E

              Comment

              • Betbobber
                Junior Member
                • Apr 2009
                • 1

                #8
                Hi all,

                I try to get started with the C# example. I downloaded the zip-file and unzipped it to a folder. I opened the project in the visual studio 2005.

                But sample code cannot be complied if I try it with the visual studio 2005. I get about 40 errors. The included exe-File starts up correctly and I can log in on betfair.

                I get errors saying an using directive is missing. The error is reported on the line "var async = ...." in the frmMain.Cs in the methode MakeSession();

                Has anyone an idea, what I am doing wrong?

                Comment

                • elmariachi
                  Junior Member
                  • Feb 2009
                  • 16

                  #9
                  Originally posted by Betbobber View Post
                  Hi all,

                  I try to get started with the C# example. I downloaded the zip-file and unzipped it to a folder. I opened the project in the visual studio 2005.

                  But sample code cannot be complied if I try it with the visual studio 2005. I get about 40 errors. The included exe-File starts up correctly and I can log in on betfair.

                  I get errors saying an using directive is missing. The error is reported on the line "var async = ...." in the frmMain.Cs in the methode MakeSession();

                  Has anyone an idea, what I am doing wrong?
                  The sample code is written in C# 3.0. Im not sure if its possible to use VisualStudio 2005 to complie C# 3.0 code ... I pretty sure its not though.

                  If you can't get your hands on the full VS2008 try the VS2008 Express edition at:
                  http://www.microsoft.com/Express/

                  E

                  Comment

                  • KilburnKen
                    Junior Member
                    • Apr 2009
                    • 1

                    #10
                    displaying compressed prices

                    Fix for displaying getMarketPricesCompressed



                    In the following procedure

                    private void DisplayGetMarketPricesCompressed


                    zeroise the prices and amounts outside of the loop


                    int count = 0;

                    while (count <= 5)
                    {
                    Price[count] = 0;
                    Size[count] = 0;

                    count++;
                    }

                    count = 0;





                    Within the loop
                    Put available to back in 0,1, and 2
                    Put available to lay in 3,4 and 5


                    foreach
                    (Betfair.DataTypes.Sports.MarketPricesInfoDemo.Sel ectionPricesInfo.OddsAvailablePriceInfo odds in runnerPrices.PriceInfo.Values)
                    {


                    if (odds.LayAmountAvailable > 0)
                    {
                    if (count < 3)
                    {
                    count = 3;
                    }
                    }

                    Price[count] = odds.Odds;

                    // Size[count] = 0;







                    Just after exiting from the loop
                    Check the available to backs
                    And move the prices and amounts up if less than 3 columns

                    count++;
                    }






                    if (Price[2] == 0)
                    {
                    Price[2] = Price[1];
                    Size[2] = Size[1];
                    Price[1] = Price[0];
                    Size[1] = Size[0];
                    Price[0] = 0;
                    Size[0] = 0;
                    }


                    if (Price[2] == 0)
                    {
                    Price[2] = Price[1];
                    Size[2] = Size[1];
                    Price[1] = 0;
                    Size[1] = 0;
                    }




                    In the procedure private void timer1_Tick(

                    The following code

                    if (simpleAPIWrapper.marketResp.market.marketId > 0)
                    {
                    if (this.simpleAPIWrapper.useCompressedPrices)
                    {
                    GetMarketPricesCompressedAsyncRequest();
                    }
                    else
                    GetMarketPricesAsyncRequest();

                    Could do to be wrapped within a try/catch block

                    Comment

                    • gup
                      Junior Member
                      • Feb 2009
                      • 2

                      #11
                      Hello

                      I just started to "play" with it (I am totally begginer) & I get the following message

                      An unhandled exception of type 'System.NullReferenceException' occurred in System.Windows.Forms.dll

                      Additional information: Object reference not set to an instance of an object.


                      Can someone help please?
                      (I am trying to connect with the free api (82))

                      Comment

                      • MrChameleon
                        Junior Member
                        • Apr 2009
                        • 7

                        #12
                        An unhandled exception of type 'System.NullReferenceException' occurred in System.Windows.Forms.dll

                        Additional information: Object reference not set to an instance of an object.
                        A .NET exception has been thrown.

                        You are trying to reference an object that you have not yet instantiated.

                        Nothing to do with the BFAPI.

                        Here's a simple C# example ...

                        Code:
                        // First define the object.
                        MyClass myClass;
                        // Now you need to instantiate the object here ...
                        myClass = new MyClass();
                        // Before you do this ...
                        myClass.MyVar = 42;
                        Hth

                        Chris

                        Comment

                        • gup
                          Junior Member
                          • Feb 2009
                          • 2

                          #13
                          Well as I already mention I am a totally beginer (I just know a little excel vba - and I am charmed by this) so I decided (for hobbie) to learn something more via the betfair "experience"... The problem is that I don't know even the basics, it took me 2 days (I am working & new parent also) just to find which excactly programm should download and where to find the design form,so I think I need to ask for a little help.

                          Can someone point out some directions for the following?
                          1) If I would like to change something in the design mode, just add a bar at the top of the application (after the file) what should I do? From the properties menu if I trie to change the doc properties in order to move them down it says its an invalid...

                          2) Can someone provide the code for example, to show the account balance with somekind of instractions of how to aplly it?

                          3) Finnaly this is my "dream" lets say of what I would like to do (after some years ) and it is a theoritical question, can I programm the application to select let's say a market for example "horses win" and in all races actually place back or lay bets in my given prices?

                          Thanks in advance for any kind of help
                          Last edited by gup; 19-06-2009, 11:24 AM.

                          Comment

                          • MrChameleon
                            Junior Member
                            • Apr 2009
                            • 7

                            #14
                            Download Visual Basic Express 2008 from Microsoft http://www.microsoft.com/express/windowsdevelopment/ and go through some of the basic tutorials to understand how Windows Forms development works. Then go through the excellent examples in this forum relating to VB 2008 for Betfair API.

                            Don't expect to understand everything in a few days; I've been programming for 20 years and I'm still learning

                            Comment

                            • dlinder
                              Junior Member
                              • Feb 2009
                              • 2

                              #15
                              Hi all,

                              I've just downloaded the code examples, and must say I'm very grateful for them however, I'm having a problem with the populating of market data. When the market is opened, the program generates the following error:

                              System.FormatException: Indata has error in format.
                              at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info,

                              Boolean parseDecimal)
                              at System.Number.ParseSingle(String value, NumberStyles options, NumberFormatInfo numfmt)
                              at System.Single.Parse(String s, NumberStyles style, NumberFormatInfo info) at System.Convert.ToSingle(String value)
                              at Betfair.DataTypes.Sports.MarketPricesInfoDemo..cto r(GetMarketPricesCompressedResp resp)
                              at CSharpAPI6.frmMain.GetMarketPricesCompressedAsyncC allback(IAsyncResult result)
                              (Short parts of error message translated from Swedish)

                              Any idea what might be the problem? I'm pretty new to .NET

                              Cheers,
                              David


                              EDIT: Unchecking "Use Compressed Prices" solved the problem, although I still don't quite get why I got it in the first place
                              Last edited by dlinder; 26-08-2009, 10:30 PM.

                              Comment

                              Working...
                              X