M
Mark Cooney
Good afternoon, yes i am a newby so pls keep it simple.
Yesterday I started a small project where I have to make an API call and
receive back from that the long xml transcript down below.
Now, not knowing about XML I have experienced one or 2 issues.
Firstly, this is the code I have created to make the call and then extract a
few bits of information:
'Create the web request
Dim request As HttpWebRequest =
WebRequest.Create(https://api.games.betfair.com/rest/v1/channels/1444074/snapshot?username=******)
request.Method = "GET"
request.Timeout = 5000
'Add headers to the web request
request.Headers.Add("gamexAPIAgent", ********@hotmail.co.uk.myGames.4.0)
request.Headers.Add("gamexAPIAgentInstance",
"0d69ee8290ee2f9b336c1f060e3497a5")
request.Headers.Add("gamexAPIPassword", "*******")
'Get response
Dim response As HttpWebResponse = request.GetResponse()
Dim reader As StreamReader = New StreamReader(response.GetResponseStream)
Dim objDoc As XmlReader = XmlReader.Create(reader)
objDoc.MoveToContent()
objDoc.ReadToFollowing("status")
Me.StatusTextBox.Text = objDoc.ReadElementContentAsString
objDoc.ReadToFollowing("game")
Me.GameIDTextBox.Text = objDoc.GetAttribute("id").ToString
objDoc.ReadToFollowing("round")
Me.RoundNumberTextBox.Text = objDoc.ReadElementContentAsString
objDoc.ReadToFollowing("bettingWindowPercentageComplete")
Me.PercentageTimeTextBox.Text = objDoc.ReadElementContentAsString
CallLabel.Text = "captured"
Catch ex As Exception
CallLabel.Text = "not captured"
End Try
For the most part this works fine but what I would rather do, is point
directly to the nodes listed in the code directly, now I have some tell me
"//channelSnaphot/channel/status" is the way to go through a
XMLSelectSingleNode, but I have tried and failed using that method.
Is there anyone out the who can improve on my code so I can make 20 or 30
direct calls to the nodes in the Stream Response I receive below? I am
pleased to say the layout of the response will never change so thats not an
issue i need to address.
Regards
API Call Returns the following:
<channelSnapshot>
<channel gameType="POKER" id="1444074" name="Exchange Poker Texas
Hold'em">
<status>RUNNING</status>
<game id="1817283">
<round>3</round>
<bettingWindowTime>45</bettingWindowTime>
<bettingWindowPercentageComplete>24</bettingWindowPercentageComplete>
<gameData>
<object name="Hand 1">
<description>One Pair, Fours, Ace High,
with Q, 8 Kickers</description>
<status>IN_PLAY</status>
<property name="Card 1" value="20"/>
<property name="Card 2" value="29"/>
</object>
<object name="Hand 2">
<description>One Pair, Sixes, Ace
High</description>
<status>IN_PLAY</status>
<property name="Card 1" value="5"/>
<property name="Card 2" value="44"/>
</object>
<object name="Hand 3">
<description>One Pair, Fours, Ace High,
with Q, 6 Kickers</description>
<status>IN_PLAY</status>
<property name="Card 1" value="31"/>
<property name="Card 2" value="42"/>
</object>
<object name="Hand 4">
<description>Ace High</description>
<status>IN_PLAY</status>
<property name="Card 1" value="49"/>
<property name="Card 2" value="45"/>
</object>
<object name="Community Cards">
<description/>
<status>N/A</status>
<property name="Card 1" value="3"/>
<property name="Card 2" value="13"/>
<property name="Card 3" value="11"/>
<property name="Card 4" value="NOT
AVAILABLE"/>
<property name="Card 5" value="NOT
AVAILABLE"/>
</object>
</gameData>
<markets currency="GBP">
<market id="5615051">
<status>ACTIVE</status>
<commissionRate>2.5</commissionRate>
<marketType>WIN_ONLY</marketType>
<selections type="MainBets">
<selection id="658439">
<name>Hand 1</name>
<resource
href="https://api.games.betfair.com/rest/v1/selection/tradeActivity?marketId=5615051&selectionId=658439"
responseType="selectionTradeActivity" title="Trade Activity"/>
<status>IN_PLAY</status>
<amountMatched>22.74</amountMatched>
<bestAvailableToBackPrices>
<price
amountUnmatched="204.42">6.6</price>
<price
amountUnmatched="381.64">6.55</price>
<price
amountUnmatched="576.92">6.5</price>
</bestAvailableToBackPrices>
<bestAvailableToLayPrices>
<price
amountUnmatched="74.6">6.7</price>
<price
amountUnmatched="504.74">6.75</price>
<price
amountUnmatched="551.44">6.8</price>
</bestAvailableToLayPrices>
</selection>
<selection id="658440">
<name>Hand 2</name>
<resource
href="https://api.games.betfair.com/rest/v1/selection/tradeActivity?marketId=5615051&selectionId=658440"
responseType="selectionTradeActivity" title="Trade Activity"/>
<status>IN_PLAY</status>
<amountMatched>88.68</amountMatched>
<bestAvailableToBackPrices>
<price
amountUnmatched="306.66">1.72</price>
<price
amountUnmatched="4127.36">1.71</price>
<price
amountUnmatched="59.63">1.7</price>
</bestAvailableToBackPrices>
<bestAvailableToLayPrices>
<price
amountUnmatched="99.98">1.73</price>
<price
amountUnmatched="2188.96">1.74</price>
<price
amountUnmatched="2200.77">1.75</price>
</bestAvailableToLayPrices>
</selection>
<selection id="658441">
<name>Hand 3</name>
<resource
href="https://api.games.betfair.com/rest/v1/selection/tradeActivity?marketId=5615051&selectionId=658441"
responseType="selectionTradeActivity" title="Trade Activity"/>
<status>IN_PLAY</status>
<amountMatched>102.9</amountMatched>
<bestAvailableToBackPrices>
<price
amountUnmatched="17.99">45.0</price>
<price
amountUnmatched="140.4">44.5</price>
<price
amountUnmatched="2.19">44.0</price>
</bestAvailableToBackPrices>
<bestAvailableToLayPrices>
<price
amountUnmatched="33.52">46.0</price>
<price
amountUnmatched="53.76">46.5</price>
<price
amountUnmatched="79.76">47.0</price>
</bestAvailableToLayPrices>
</selection>
<selection id="658442">
<name>Hand 4</name>
<resource
href="https://api.games.betfair.com/rest/v1/selection/tradeActivity?marketId=5615051&selectionId=658442"
responseType="selectionTradeActivity" title="Trade Activity"/>
<status>IN_PLAY</status>
<amountMatched>1020.0</amountMatched>
<bestAvailableToBackPrices>
<price
amountUnmatched="158.07">4.0</price>
<price
amountUnmatched="198.19">3.98</price>
<price
amountUnmatched="631.28">3.96</price>
</bestAvailableToBackPrices>
<bestAvailableToLayPrices>
<price
amountUnmatched="103.84">4.06</price>
<price
amountUnmatched="612.72">4.08</price>
<price
amountUnmatched="914.6">4.1</price>
</bestAvailableToLayPrices>
</selection>
</selections>
</market>
</markets>
</game>
</channel>
</channelSnapshot>
Yesterday I started a small project where I have to make an API call and
receive back from that the long xml transcript down below.
Now, not knowing about XML I have experienced one or 2 issues.
Firstly, this is the code I have created to make the call and then extract a
few bits of information:
'Create the web request
Dim request As HttpWebRequest =
WebRequest.Create(https://api.games.betfair.com/rest/v1/channels/1444074/snapshot?username=******)
request.Method = "GET"
request.Timeout = 5000
'Add headers to the web request
request.Headers.Add("gamexAPIAgent", ********@hotmail.co.uk.myGames.4.0)
request.Headers.Add("gamexAPIAgentInstance",
"0d69ee8290ee2f9b336c1f060e3497a5")
request.Headers.Add("gamexAPIPassword", "*******")
'Get response
Dim response As HttpWebResponse = request.GetResponse()
Dim reader As StreamReader = New StreamReader(response.GetResponseStream)
Dim objDoc As XmlReader = XmlReader.Create(reader)
objDoc.MoveToContent()
objDoc.ReadToFollowing("status")
Me.StatusTextBox.Text = objDoc.ReadElementContentAsString
objDoc.ReadToFollowing("game")
Me.GameIDTextBox.Text = objDoc.GetAttribute("id").ToString
objDoc.ReadToFollowing("round")
Me.RoundNumberTextBox.Text = objDoc.ReadElementContentAsString
objDoc.ReadToFollowing("bettingWindowPercentageComplete")
Me.PercentageTimeTextBox.Text = objDoc.ReadElementContentAsString
CallLabel.Text = "captured"
Catch ex As Exception
CallLabel.Text = "not captured"
End Try
For the most part this works fine but what I would rather do, is point
directly to the nodes listed in the code directly, now I have some tell me
"//channelSnaphot/channel/status" is the way to go through a
XMLSelectSingleNode, but I have tried and failed using that method.
Is there anyone out the who can improve on my code so I can make 20 or 30
direct calls to the nodes in the Stream Response I receive below? I am
pleased to say the layout of the response will never change so thats not an
issue i need to address.
Regards
API Call Returns the following:
<channelSnapshot>
<channel gameType="POKER" id="1444074" name="Exchange Poker Texas
Hold'em">
<status>RUNNING</status>
<game id="1817283">
<round>3</round>
<bettingWindowTime>45</bettingWindowTime>
<bettingWindowPercentageComplete>24</bettingWindowPercentageComplete>
<gameData>
<object name="Hand 1">
<description>One Pair, Fours, Ace High,
with Q, 8 Kickers</description>
<status>IN_PLAY</status>
<property name="Card 1" value="20"/>
<property name="Card 2" value="29"/>
</object>
<object name="Hand 2">
<description>One Pair, Sixes, Ace
High</description>
<status>IN_PLAY</status>
<property name="Card 1" value="5"/>
<property name="Card 2" value="44"/>
</object>
<object name="Hand 3">
<description>One Pair, Fours, Ace High,
with Q, 6 Kickers</description>
<status>IN_PLAY</status>
<property name="Card 1" value="31"/>
<property name="Card 2" value="42"/>
</object>
<object name="Hand 4">
<description>Ace High</description>
<status>IN_PLAY</status>
<property name="Card 1" value="49"/>
<property name="Card 2" value="45"/>
</object>
<object name="Community Cards">
<description/>
<status>N/A</status>
<property name="Card 1" value="3"/>
<property name="Card 2" value="13"/>
<property name="Card 3" value="11"/>
<property name="Card 4" value="NOT
AVAILABLE"/>
<property name="Card 5" value="NOT
AVAILABLE"/>
</object>
</gameData>
<markets currency="GBP">
<market id="5615051">
<status>ACTIVE</status>
<commissionRate>2.5</commissionRate>
<marketType>WIN_ONLY</marketType>
<selections type="MainBets">
<selection id="658439">
<name>Hand 1</name>
<resource
href="https://api.games.betfair.com/rest/v1/selection/tradeActivity?marketId=5615051&selectionId=658439"
responseType="selectionTradeActivity" title="Trade Activity"/>
<status>IN_PLAY</status>
<amountMatched>22.74</amountMatched>
<bestAvailableToBackPrices>
<price
amountUnmatched="204.42">6.6</price>
<price
amountUnmatched="381.64">6.55</price>
<price
amountUnmatched="576.92">6.5</price>
</bestAvailableToBackPrices>
<bestAvailableToLayPrices>
<price
amountUnmatched="74.6">6.7</price>
<price
amountUnmatched="504.74">6.75</price>
<price
amountUnmatched="551.44">6.8</price>
</bestAvailableToLayPrices>
</selection>
<selection id="658440">
<name>Hand 2</name>
<resource
href="https://api.games.betfair.com/rest/v1/selection/tradeActivity?marketId=5615051&selectionId=658440"
responseType="selectionTradeActivity" title="Trade Activity"/>
<status>IN_PLAY</status>
<amountMatched>88.68</amountMatched>
<bestAvailableToBackPrices>
<price
amountUnmatched="306.66">1.72</price>
<price
amountUnmatched="4127.36">1.71</price>
<price
amountUnmatched="59.63">1.7</price>
</bestAvailableToBackPrices>
<bestAvailableToLayPrices>
<price
amountUnmatched="99.98">1.73</price>
<price
amountUnmatched="2188.96">1.74</price>
<price
amountUnmatched="2200.77">1.75</price>
</bestAvailableToLayPrices>
</selection>
<selection id="658441">
<name>Hand 3</name>
<resource
href="https://api.games.betfair.com/rest/v1/selection/tradeActivity?marketId=5615051&selectionId=658441"
responseType="selectionTradeActivity" title="Trade Activity"/>
<status>IN_PLAY</status>
<amountMatched>102.9</amountMatched>
<bestAvailableToBackPrices>
<price
amountUnmatched="17.99">45.0</price>
<price
amountUnmatched="140.4">44.5</price>
<price
amountUnmatched="2.19">44.0</price>
</bestAvailableToBackPrices>
<bestAvailableToLayPrices>
<price
amountUnmatched="33.52">46.0</price>
<price
amountUnmatched="53.76">46.5</price>
<price
amountUnmatched="79.76">47.0</price>
</bestAvailableToLayPrices>
</selection>
<selection id="658442">
<name>Hand 4</name>
<resource
href="https://api.games.betfair.com/rest/v1/selection/tradeActivity?marketId=5615051&selectionId=658442"
responseType="selectionTradeActivity" title="Trade Activity"/>
<status>IN_PLAY</status>
<amountMatched>1020.0</amountMatched>
<bestAvailableToBackPrices>
<price
amountUnmatched="158.07">4.0</price>
<price
amountUnmatched="198.19">3.98</price>
<price
amountUnmatched="631.28">3.96</price>
</bestAvailableToBackPrices>
<bestAvailableToLayPrices>
<price
amountUnmatched="103.84">4.06</price>
<price
amountUnmatched="612.72">4.08</price>
<price
amountUnmatched="914.6">4.1</price>
</bestAvailableToLayPrices>
</selection>
</selections>
</market>
</markets>
</game>
</channel>
</channelSnapshot>