Exemplo n.º 1
0
 /// <remarks/>
 public void placeBetsAsync(PlaceBetsReq request, object userState) {
     if ((this.placeBetsOperationCompleted == null)) {
         this.placeBetsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnplaceBetsOperationCompleted);
     }
     this.InvokeAsync("placeBets", new object[] {
                 request}, this.placeBetsOperationCompleted, userState);
 }
Exemplo n.º 2
0
 public PlaceBetsResp placeBets(PlaceBetsReq request) {
     object[] results = this.Invoke("placeBets", new object[] {
                 request});
     return ((PlaceBetsResp)(results[0]));
 }
Exemplo n.º 3
0
 /// <remarks/>
 public void placeBetsAsync(PlaceBetsReq request) {
     this.placeBetsAsync(request, null);
 }
Exemplo n.º 4
0
        /// <summary>
        /// The API PlaceBets service allows you to place multiple (1 to 60) bets on 
        /// a single Market. There is an instance of PlaceBetsResp returned in the 
        /// output for each instance of PlaceBets in the input. The success or failure 
        /// of the individual bet placement operation is indicated by the Success Boolean.
        /// Note: To bet on an event, you need to have sufficient funds available 
        /// in the relevant local wallet to cover your entire liability. If you want 
        /// to bet on the Australian exchange server and you do not have sufficient funds 
        /// in your Australian wallet to cover the liability, you must first transfer funds 
        /// into that wallet from your UK wallet by using the transferFunds service 
        /// (see Chapter 56). Also, your wallet must be active 
        /// (and not, for example, suspended for any reason) at the time you place the bet.
        /// </summary>
        /// <param name="bets">The bets.</param>
        /// <returns></returns>
        public List<Bet> PlaceBets(List<Bet> bets)
        {
            const string serviceName = "PlaceBets";
            Console.WriteLine("{0}$ API_SERVICE {1}", DateTime.Now, serviceName);

            var errorMessages = new List<string>();

            for (int x = 0; x < bets.Count; x++)
            {
                if (!bets[x].betRequestprocessed && bets[x].betId == 0)
                {
                    Bet bet = bets[x];
                    var request = new PlaceBetsReq
                                      {
                                          header = ((BetfairExchangeAPI.APIRequestHeader) GetHeader(false)),
                                          bets = new PlaceBets[1]
                                      };

                    request.bets[0] = new PlaceBets();

                    bets[x].betRequestprocessed = true;

                    request.bets[0].asianLineId = bet.asianLineId;

                    switch (bet.betCategory)
                    {
                        case BetCategoryOptions.EXCHANGE:
                            request.bets[0].betCategoryType = BetCategoryTypeEnum.E;
                            break;
                        case BetCategoryOptions.LIMIT_ON_CLOSE:
                            request.bets[0].betCategoryType = BetCategoryTypeEnum.L;
                            break;
                        default:
                            request.bets[0].betCategoryType = bet.betCategory == BetCategoryOptions.MARKET_ON_CLOSE ? BetCategoryTypeEnum.M : BetCategoryTypeEnum.NONE;
                            break;
                    }

                    switch (bet.betPersistence)
                    {
                        case BetPersistenceOptions.IN_PLAY_PERSISTENCE:
                            request.bets[0].betPersistenceType = BetPersistenceTypeEnum.IP;
                            break;
                        case BetPersistenceOptions.UNMATCHED_FILL_WITH_SP:
                            request.bets[0].betPersistenceType = BetPersistenceTypeEnum.SP;
                            break;
                        default:
                            request.bets[0].betPersistenceType = BetPersistenceTypeEnum.NONE;
                            break;
                    }

                    request.bets[0].betType = bet.betType == BetTypeOptions.L ? BetTypeEnum.L : BetTypeEnum.B;

                    request.bets[0].bspLiability = bet.bspLiability;
                    request.bets[0].marketId = bet.marketId;
                    request.bets[0].price = bet.price;
                    request.bets[0].selectionId = bet.selectionId;
                    request.bets[0].size = bet.size;

                    var response = _bfExchangeService[bet.exchangeId].placeBets(request);

                    if (response.betResults[0] != null && response.betResults[0].betId > 0)
                        bets[x].betId = response.betResults[0].betId;

                    try
                    {
                        bets[x].success = response.betResults[0].success;
                        bets[x].systemBetCreateDate = DateTime.Now.ToUniversalTime();

                        ValidateAPIResponse(serviceName, Convert.ToString(response.header.errorCode),
                                            Convert.ToString(response.errorCode), response.header.sessionToken);

                        if (response.betResults[0].sizeMatched > 0)
                            bets[x].size = response.betResults[0].sizeMatched;

                        bets[x].customUserBetNote = response.betResults[0].resultCode.ToString();
                    }
                    catch (Exception ex)
                    {
                        errorMessages.Add(ex.Message);
                    }
                }
            }

            foreach (string message in errorMessages)
                Console.WriteLine("{0}$ API_SERVICE {1} :{2} ", DateTime.Now, serviceName, message);

            return bets;
        }