Home Random Page


CATEGORIES:

BiologyChemistryConstructionCultureEcologyEconomyElectronicsFinanceGeographyHistoryInformaticsLawMathematicsMechanicsMedicineOtherPedagogyPhilosophyPhysicsPolicyPsychologySociologySportTourism






Step 21. Cancelling a Bet

To cancel unmatched bets you can call cancelBets. With cancelBets you can cancel several bets at once. To keep things simple the following example cancels a single bet only.

Add this sub to Class TestForm:

Code:

Sub CancelBet(ByVal betId As Long)

 

Dim oCancelBetsReq As New BFUK.CancelBetsReq 'Create the request object

Dim oCancelBetsResp As BFUK.CancelBetsResp 'A variable to hold the response object

With oCancelBetsReq

.header = oHeaderUK() 'The standard request header

ReDim .bets(0) 'Single element array

.bets(0) = New BFUK.CancelBets 'Create an object of type CancelBets

.bets(0).betId = betId 'The BetId to be cancelled

End With

 

oCancelBetsResp = BetFairUK.cancelBets(oCancelBetsReq) 'Call API to cancel the bet

 

With oCancelBetsResp 'The response

CheckHeader(.header)

Print("ErrorCode = " & .errorCode.ToString)

If .errorCode = BFUK.CancelBetsErrorEnum.OK Then 'The call succeeded

For i = 0 To .betResults.Length - 1 'In this case there should only be one result

With .betResults(i)

Print(.resultCode.ToString) 'The result of the cancellation

If .success Then Print("BetId " & .betId & " cancelled")

End With

Next

End If

End With

 

End Sub

This is a sync call which follows the normal calling procedure. Note that an object of type BFUK.CancelBets is required to hold the betId in the first element of the .bets array. Do not confuse the BFUK.CancelBets class with the service object method BetfairUK.cancelBets. They are different things even though they have the same name.

To cancel a bet you simply call Sub CancelBet with the betId. To test this add a “CancelBet” button to the TestForm. Name it bCancelBet and add this code:

Code:

Private Sub bCancelBet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bCancelBet.Click

Print("*** CancelBet ***")

CancelBet(TheBetId) 'TheBetId is saved by Sub PlaceBet

End Sub

Now set up the parameters for a test bet (as in step 19) and run the project. Observe this market on the website. As previously, the bet will be appear on “My Bets” after you click the “PlaceBet” button. Now click “CancelBet” and observe what happens.

There is a similar service called cancelBetsByMarket. Use this if you require bulk cancellation of unmatched bets across one or more markets.

 

 


Date: 2014-12-21; view: 1146


<== previous page | next page ==>
Step 20. Monitoring Bet Status | Step 22. Changing the bet size and price
doclecture.net - lectures - 2014-2024 year. Copyright infringement or personal data (0.012 sec.)