Announcement

Collapse
No announcement yet.

Help Converting old API to new one!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help Converting old API to new one!

    Hi

    I am writing a C# .NET 4 BOT (runs as a service on my PC, connects to my DB, gets runners to bet on, saves info in the DB and so on)

    It's all automatic and works fine in the old API (SOAP).

    I am trying to convert my old code to the new code with the help of the C# example > https://github.com/betfair/API-NG-sa.../master/cSharp

    I have managed to handle the logging in, getting a new session, saving it, re-using it, getting runners, markets and the placing of bets.

    However I am trying to find examples of methods (or examples that call methods) that I can convert for things like:

    -Cancelling Bets
    -Getting the current status of a bet
    -Getting the accounts current available funds

    I maybe just looking in the wrong place or being a numpty but I'm stuck here. I have managed to get a core project working that can fill my markets, store runners and their metadata, place bets and so on.

    I just need some examples of C# code (preferably) that shows me how to cancel a bet, get the status of a bet or get the account funds.

    From looking at the classes in the API-ING C# project I cannot seem to find anything relevant to use and the example program code is pretty basic (logs in, sets the event to horse racing, finds the first market then places a bet it knows will fail)

    Any help on this would be much appreciated.

    And if possible code examples in C# or VB.NET so I can convert it over easily please.

    Thanks

  • #2
    Is this the solution?

    As I cannot find any examples only some documentation on > https://api.developer.betfair.com/se...celInstruction

    I thought this "might" be a solution to the C# API-ING example codebase.

    Seeing there is a class in the TO project for PlaceInstruction (to place a bet) I have basically used the documentation and added a new class called CancelInstruction.cs to the project which looks like this.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Newtonsoft.Json;
    
    namespace Api_ng_sample_code.TO
    {
        public class CancelInstruction
        {
            [JsonProperty(PropertyName = "betId")]
            public string BetID { get; set; }
    
            [JsonProperty(PropertyName = "sizeReduction")]
            public double SizeReduction { get; set; }
    
            public override string ToString()
            {
                var sb = new StringBuilder()
                    .AppendFormat("BetID={0}", BetID)
                    .AppendFormat(" : SizeReduction={0}", SizeReduction);
    
                return sb.ToString();
            }
        }
    }

    And then as I am not too clear whether the SizeReduction property means the amount to REDUCE the bet by OR the amount to try and RESET the price to be. I have done the former. So if an unmatched bet was £5 and I wanted to set it to £2 I would set SizeReduction to £3 (don't know if this is right or wrong though!)

    Then I have created a method in my main BetfairAPI class which sets up the CancelInstruction variable and passes it to the placeInstructions object. This then goes to my PlaceOrder method which will run the instructions and return a new Bet object (this is my own object that contains my unique ID for the Bet, the BetID, matchedAmount, price, size etc)


    Code:
    public Bet CancelBet(Bet bet, double SizeReducton = 0)
    {
        // set up the cancel instructions and pass them to the PlaceOrder method
       
        CancelInstruction cancel = new CancelInstruction();
        
        // set the bet ID from my Bet object
        cancel.BetID = Convert.ToString(bet.BetID);
    
        // only set the size reduction if its above 0 otherwise if we
        // only want to cancel a little bit not the whole bet we
        // supply the size of the bet I want to cancel so if the bet was £5 and I want to cancel £2 I supply 3.00???
        if (SizeReducton > 0)
        {
    	// work out from original bet how much the new size should be
    	// only should work on unmatched bets
    	if (bet.BetAmount > 0 && bet.BetStatus == "")
    	{
    	    // try and set new size of bet by deducting the reduction amount from original bet amount
    	    cancel.SizeReduction = (bet.BetAmount - SizeReducton);
    	}
        }
       
        // pass orders to the PlaceOrder
        IList<PlaceInstruction> placeInstructions = new List<PlaceInstruction>();
        PlaceInstruction placeInstruction = new PlaceInstruction();
    
        placeInstructions.Add(placeInstruction);
    
        // now place it
        bet = this.PlaceOrder(ref bet, placeInstructions);
    
        // check bet status - need this code as well
    
        // return bet object with changed properties e.g size matched, status etc
        return bet;
    }
    Now I don't know if this is right or wrong. I would have expected any example code to have all the methods and classes necessary to do a full job but if not IS THIS THE WAY TO GO??

    Any answers would be great!

    Comment


    • #3
      Does anyone have any working code?

      Does anyone have any working code for getting Account information such as current balance or cancelling bets etc?

      Even if it's in a different language.

      Do I need to login to a different API for account info?

      I see on this page >

      https://api.developer.betfair.com/se...ni/Betting+API

      The Accounts API has

      JSON-RPC > https://api.betfair.com/exchange/account/json-rpc/v1/ <methodname>

      JSON REST > https://api.betfair.com/exchange/account/rest/v1.0

      But the Betting API has

      JSON-RPC > https://api.betfair.com/exchange/betting/json-rpc/v1 <methodname>

      JSON REST > https://api.betfair.com/exchange/betting/rest/v1.0

      Do I need to login to both, can I use the same example classes in the C# API-ING examples or do I need to make a whole separate lot for Account methods.

      Any help would be appreciated.

      Thanks

      Comment

      Working...
      X