Home Random Page


CATEGORIES:

BiologyChemistryConstructionCultureEcologyEconomyElectronicsFinanceGeographyHistoryInformaticsLawMathematicsMechanicsMedicineOtherPedagogyPhilosophyPhysicsPolicyPsychologySociologySportTourism






Step 24. Calling getMarketTradedVolumeCompressed

The API service getMarketTradedVolumeCompressed returns the values shown in the ‘Price’ and ‘Traded’ columns on the ‘Market Information’ page for each runner shown on the website page for a market. This shows you the amounts that have been traded at each price increment.

The returned data can be used in conjunction with data returned by getCompleteMarketPricesCompressed. For example, at a particular price value, if the back amount available reduces, you can determine whether this change was caused by bets being matched or unmatched bets being withdrawn.

This service can be called 60/min on the free API. Because a typical app will call this fairly frequently It’s best to call getMarketTradedVolumeCompressedAsync because this is more efficient.

This call returns the compressed .tradedVolume string which can be unpacked using these classes. (Add these to module Unpack2):

Code:

'Classes for unpacking getMarketTradedVolumeCompressed:

 

Class RunnerVolumeType

Public selectionId As Integer

Public asianLineId As Integer

Public actualBSP As Double

Public totalBspBackMatchedAmount As Double

Public totalBspLiabilityMatchedAmount As Double

Public tradedVolume As VolumeType()

End Class

 

Class VolumeType

Public odds As Double

Public totalMatchedAmount As Double

End Class

 

Class UnpackMarketTradedVolumeCompressed

Public RunnerVolume As RunnerVolumeType() = {}

 

Sub New(ByVal TradedVolume As String)

Dim Tvolume, Part, Field As String(), m, n As Integer

 

Tvolume = TradedVolume.Split(":") 'Split volume data for each runner

n = UBound(Tvolume) - 1

ReDim RunnerVolume(n)

For i = 0 To n 'For each runner

Part = Tvolume(i + 1).Split("|")

Field = Part(0).Split("~")

RunnerVolume(i) = New RunnerVolumeType

With RunnerVolume(i)

.selectionId = Field(0)

.asianLineId = Field(1)

.actualBSP = Val(Field(2))

.totalBspBackMatchedAmount = Val(Field(3))

.totalBspLiabilityMatchedAmount = Val(Field(4))

m = UBound(Part) - 1

ReDim .tradedVolume(m)

For j = 0 To m

Field = Part(j + 1).Split("~")

.tradedVolume(j) = New VolumeType

.tradedVolume(j).odds = Val(Field(0))

.tradedVolume(j).totalMatchedAmount = Val(Field(1))

Next

End With

Next

End Sub

End Class

When an new instance of class UnpackMarketTradedVolumeCompressed is created, Sub New unpacks the .tradedVolume string. Its operation is similar to that described in Step 10 for unpacking getCompleteMarketPricesCompressed, but the logic is slightly different to match the different data structure (it is a bit simpler). If you wish you can single step through this to see how it works.

The object thus created contains an array of RunnerVolumeType. The properties of this are described in the API Guide.

To test the call add another button to the TestForm. Name it bGetMTVComp and change its Text property to something like TradedVolume. Double-click it to create its event handler Sub bGetMTVComp_Click. Add this code:



Code:

Private Sub bGetMTVComp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bGetMTVComp.Click

Print("*** MarketTradedVolume ***")

Dim oMTVCReq As New BFUK.GetMarketTradedVolumeCompressedReq 'The request object

With oMTVCReq

.header = oHeaderUK()

.marketId = YourMarketIdOfInterest 'An active market ID

End With

StateCount += 1

BetFairUK.getMarketTradedVolumeCompressedAsync(oMTVCReq, StateCount) 'Call the API

End Sub

This is an Async call which requires an event handler. In the Class Name box select BetFairUK. In the Method Name box click on getMarketTradeVolumeCompressedCompleted. Add this code:

Code:

Private Sub BetFairUK_getMarketTradedVolumeCompressedCompleted(ByVal sender As Object, ByVal e As BFUK.getMarketTradedVolumeCompressedCompletedEventArgs) Handles BetFairUK.getMarketTradedVolumeCompressedCompleted

Try

If Not e.Cancelled Then

With e.Result

CheckHeader(.header)

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

If .errorCode = BFUK.GetMarketTradedVolumeCompressedErrorEnum.OK Then

Dim oTradedVolume As New UnpackMarketTradedVolumeCompressed(.tradedVolume) 'Unpack the traded volume data

With oTradedVolume 'Process the unpacked data

For i = 0 To .RunnerVolume.Length - 1 'For each runner

With .RunnerVolume(i)

Print("selectionId = " & .selectionId & " -----")

For j = 0 To .tradedVolume.Length - 1 'Print the table of odds and amounts matched

Print("odds = " & .tradedVolume(j).odds & " amt = " & .tradedVolume(j).totalMatchedAmount)

Next

End With

Next

End With

End If

End With

End If

 

Catch ex As ApplicationException 'If problem

Print(ex.Message)

End Try

End Sub

This is the “callback” procedure which handles the response. To demonstrate what is returned, this sub prints the table of odds and amounts matched for each runner.

Note that, unlike getMarketPricesCompressed, there is no .sortOrder parameter. To determine which table belongs to which runner you will have to match selectionIds.


 


Date: 2014-12-21; view: 1098


<== previous page | next page ==>
Step 23. Changing a Bet. | Step 25. Accessing Australian Markets.
doclecture.net - lectures - 2014-2024 year. Copyright infringement or personal data (0.009 sec.)