Home Random Page


CATEGORIES:

BiologyChemistryConstructionCultureEcologyEconomyElectronicsFinanceGeographyHistoryInformaticsLawMathematicsMechanicsMedicineOtherPedagogyPhilosophyPhysicsPolicyPsychologySociologySportTourism






Step 23. Changing a Bet.

You can change the parameters of unmatched bets by calling updateBets. You can change the price or size of an unmatched bet, but not both at the same time. If you attempt to do this, only the price changes. You can also change the betPersistenceType (prior to the market turning in-play).

Note that updateBets can process a batch of bet changes at once, but again, to keep things simple, we will only change one bet at a time here. Add the following sub to the TestForm to perform the updateBets call:

Code:

Private Sub UpdateBet(ByVal BetId As Long, ByVal NewPrice As Decimal, ByVal OldPrice As Decimal, ByVal NewSize As Decimal, ByVal OldSize As Decimal)

 

Dim oUpdateBetsReq As New BFUK.UpdateBetsReq 'Create the request object

Dim oUpdateBetsResp As BFUK.UpdateBetsResp 'A variable to hold the response object

Dim oUpdateBet As New BFUK.UpdateBets 'An object to specify the changes

With oUpdateBetsReq

.header = oHeaderUK() 'The standard header

With oUpdateBet 'Specify the desired changes:

.betId = BetId 'The betId of the existing bet to be changed

.newBetPersistenceType = BFUK.BetPersistenceTypeEnum.NONE 'No change

.oldBetPersistenceType = BFUK.BetPersistenceTypeEnum.NONE

.newPrice = NewPrice 'The desired new price

.oldPrice = OldPrice 'The existing price

.newSize = NewSize 'The desired new bet size

.oldSize = OldSize 'The existing bet size

End With

ReDim .bets(0) 'Array length = 1 to hold single bet changes

.bets(0) = oUpdateBet 'Put the bet changes object in element 0

End With

 

oUpdateBetsResp = BetFairUK.updateBets(oUpdateBetsReq) 'Call the API to change the bet

 

With oUpdateBetsResp 'The response

CheckHeader(.header)

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

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

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

With .betResults(i)

Print(.resultCode.ToString) 'Print the result

If .success Then 'Print details of the change if successful

Print("BetId = " & .betId & " NewBetId = " & .newBetId)

Print("NewPrice = " & .newPrice & " NewSize = " & .newSize & " SizeCancelled = " & .sizeCancelled)

 

If .newBetId <> 0 Then TheBetId = .newBetId 'Save the new betId if there is one

BetPrice = .newPrice

BetSize = .newSize 'Update with the new values

nudPrice.Value = .newPrice

nudSize.Value = .newSize

 

End If

End With

Next

End If

End With

 

End Sub

This is a sync call which follows the normal calling procedure. We create an object oUpdateBet to hold the our desired changes. This object is then assigned to the first element of the .bets array in the request object and the API is called.

When the response is received the result of the call is printed. If the update succeeds we print details of the change and also update the variables and NumericUpDown controls with the new values.



In this example we don’t change betPersistenceType. The changes given in the sub’s calling parameters are assigned to oUpdateBet. The call syntax is:

UpdateBet(BetId, NewPrice, OldPrice, NewSize, OldSize)

You must specify both old and new values even though sometimes they may not appear necessary. Also, it’s good practice to use the “correct” old values otherwise you may get unexpected results.

To test this add this code to the click event handler of the UpdateBet button we added in Step 22:

Code:

Private Sub bUpdateBet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bUpdateBet.Click

Print("*** UpdateBet ***")

UpdateBet(TheBetId, nudPrice.Value, BetPrice, nudSize.Value, BetSize)

End Sub

Here we take the new values from the NumericUpDown controls we added in Step 22. The existing values are held in TheBetId, BetPrice and BetSize (variables we added in Step 19).

To experiment, I suggest you log onto the Betfair website (as per previous steps) to observe the effects of the changes we will request. Select a suitable market and a short-priced runner and set the Market and Selection values accordingly (as per step 19).

Now place a test bet using the bet controls. My example: select Back, set Price = 25.00, Size = 10. Click PlaceBet. If successful this bet will appear on the “MyBets” tab on the web page. You should now have a bet: 10 units @25.00.

To change the bet price:

Set Price = 23 and click UpdateBet. Note that you now have a new bet: 10 units @23.00. The original bet has been cancelled.

To reduce the bet size:

Set Size = 6 and click UpdateBet. The existing bet is retained with reduced size. You now have 6 units @23.00.

To increase the bet size:

Set Size = 8 and click UpdateBet. The existing bet is retained as is, and a new bet is created to cover the size increase. You now have 2 bets: 6 units @23.00 and 2 units @23.00.

 

 


Date: 2014-12-21; view: 1165


<== previous page | next page ==>
Step 22. Changing the bet size and price | Step 24. Calling getMarketTradedVolumeCompressed
doclecture.net - lectures - 2014-2024 year. Copyright infringement or personal data (0.007 sec.)