In step 19 TheBetId is the name of a variable accessed from within the PlaceBet sub. Make sure that you have declared it outside the sub with a line like this:
Dim TheBetId As Long
(In step 19 this has been declared in the code for the test call.)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BFGlobalService" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="999999999" maxBufferPoolSize="524288" maxReceivedMessageSize="999999999"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="999999999" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="BFGlobalService1" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="999999999" maxBufferPoolSize="524288" maxReceivedMessageSize="999999999"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="999999999" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="BFExchangeService" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="999999999" maxBufferPoolSize="524288" maxReceivedMessageSize="999999999"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="999999999" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="BFExchangeService1" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="999999999" maxBufferPoolSize="524288" maxReceivedMessageSize="999999999"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="999999999" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://api.betfair.com/global/v3/BFGlobalService"
binding="basicHttpBinding" bindingConfiguration="BFGlobalService"
contract="BFGlobal.BFGlobalService" name="BFGlobalService" />
<endpoint address="https://api.betfair.com/exchange/v5/BFExchangeService"
binding="basicHttpBinding" bindingConfiguration="BFExchangeService"
contract="BFUK.BFExchangeService" name="BFExchangeService" />
</client>
</system.serviceModel>
</configuration>
<readerQuotas maxDepth="32" maxStringContentLength="999999999" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
Private Sub bMarkets_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bMarkets.Click
Print("*** Markets ***")
Dim oMarketsReq As New BFUK.GetAllMarketsReq
Dim oMarketsResp As BFUK.GetAllMarketsResp
With oMarketsReq
.header = oHeaderUK()
ReDim .eventTypeIds(0) : .eventTypeIds(0) = 1
.fromDate = Today.AddDays(2)
.toDate = Today.AddDays(3)
End With
oMarketsResp = BetFairUK.getAllMarkets(oMarketsReq) 'Call the UK API
With oMarketsResp
CheckHeader(.header)
Print("ErrorCode = " & .errorCode.ToString)
If .errorCode = BFUK.GetAllMarketsErrorEnum.OK Then
Dim AllMarkets As New UnpackAllMarkets(.marketData) 'Create an object and unpack the string
With AllMarkets
For i = 0 To .marketData.Length - 1
With .marketData(i)
Print(.marketId & " " & .marketStatus & " " & .marketName & " " & .menuPath)
End With
Next
End With
End If
End With
End Sub
System.ServiceModel.CommunicationException was unhandled
Message=Error in deserializing body of reply message for operation 'getAllMarkets'.
Source=mscorlib
StackTrace:
Server stack trace:
at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at TestForm.BFUK.BFExchangeService.getAllMarkets(getAllMarketsIn request)
at TestForm.BFUK.BFExchangeServiceClient.BFUK_BFExchangeService_getAllMarkets(getAllMarketsIn request) in C:\Users\Dom\documents\visual studio 2010\Projects\TestForm\TestForm\Service References\BFUK\Reference.vb:line 12966
at TestForm.BFUK.BFExchangeServiceClient.getAllMarkets(GetAllMarketsReq request) in C:\Users\Dom\documents\visual studio 2010\Projects\TestForm\TestForm\Service References\BFUK\Reference.vb:line 12972
at TestForm.Form1.bMarkets_Click(Object sender, EventArgs e) in C:\Users\Dom\documents\visual studio 2010\Projects\TestForm\TestForm\Form1.vb:line 104
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at TestForm.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.InvalidOperationException
Message=There is an error in XML document (2, 41100).
Source=System.Xml
StackTrace:
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest)
InnerException: System.Xml.XmlException
LineNumber=0
LinePosition=0
Message=The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 2, position 41100.
Source=System.Runtime.Serialization
StackTrace:
at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
at System.Xml.XmlExceptionHelper.ThrowMaxStringContentLengthExceeded(XmlDictionaryReader reader, Int32 maxStringContentLength)
at System.Xml.XmlDictionaryReader.ReadString(Int32 maxStringContentLength)
at System.Xml.XmlDictionaryReader.ReadString()
at System.Xml.XmlBaseReader.ReadElementString()
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderBFExchangeService.Read32_GetAllMarketsResp(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderBFExchangeService.Read154_getAllMarketsResponse()
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer8.Deserialize(XmlSerializationReader reader)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
InnerException:
Private Sub betSmallStake() 'Place bet less then the minimum Stake of 2 on LAY bets
Dim oPlaceBetsReq As New BFUK.PlaceBetsReq 'Create the request object
Dim oPlaceBetsResp As BFUK.PlaceBetsResp 'A variable to hold the response object
Dim oBet As New BFUK.PlaceBets 'An object to specify the bet
Dim oUpdateBetsReq As New BFUK.UpdateBetsReq
Dim oUpdateBetsResp As New BFUK.UpdateBetsResp
Dim oUpdateFrage As New BFUK.UpdateBets
Dim oUpdateAnswer As New BFUK.UpdateBetsResult
Dim ersteBET As Long
Dim neueBetID As Long
Dim YourMarket As Long
Dim YourSelection As Long
Dim YourBetType As New BFUK.BetTypeEnum
Dim BetSize, BetPrice As Double
YourMarket = 101560066
YourSelection = 3079062
YourBetType = BFUK.BetTypeEnum.L
BetSize = 0.1
BetPrice = 1.01
'Documentation will not help you with this issue. Trick is to do it in few steps.
'If you want, for example, to place £0.1 bet then place regular £2 bet on highest quote (1000 if you want to back)
'or lowest quote (1.01 if you want to lay). The bet will not be matched.
'Change its amount to 2.1£ and as result you will have two bets: one with £2 and the other with £0.1 amount.
'Cancel first one, change £0.1 bet quote on the desired value and that's it
With oPlaceBetsReq
.header = oHeaderUK() 'The standard header
With oBet 'Specify the bet details:
.asianLineId = 0 'Non-asian handicap market
.betCategoryType = BFUK.BetCategoryTypeEnum.E 'Normal exchange bet
.betPersistenceType = BFUK.BetPersistenceTypeEnum.NONE 'Standard bet (not SP or InPlay persistence)
.betType = YourBetType 'Back or Lay
.marketId = YourMarket 'The market of interest
.price = 1.01 'The desired price (odds)
.selectionId = YourSelection 'Your selection of interest
.size = 2 'The bet amount (stake)
.bspLiability = 0 'Must be 0 for non-SP bet
End With
ReDim .bets(0) 'Array length = 1 to hold single bet
.bets(0) = oBet 'Put the bet details object in element 0
End With
oPlaceBetsResp = BetFairUK.placeBets(oPlaceBetsReq)
With oPlaceBetsResp ' Place 1. bet
If .errorCode = BFUK.PlaceBetsErrorEnum.OK Then
With .betResults(0)
If .success Then
ersteBET = .betId
'----------------------------------------------- ' Update 1. bet - Change Price and Stakesize
With oUpdateBetsReq
.header = oHeaderUK() 'The standard header
With oUpdateFrage
.oldBetPersistenceType = BFUK.BetPersistenceTypeEnum.NONE
.newBetPersistenceType = BFUK.BetPersistenceTypeEnum.NONE
.betId = ersteBET
.oldPrice = 1.01
'.newPrice = 9.8
.oldSize = 2
.newSize = 2.1
End With
End With
oUpdateBetsResp = BetFairUK.updateBets(oUpdateBetsReq)
With oUpdateBetsResp
CheckHeader(.header)
If .errorCode = BFUK.UpdateBetsErrorEnum.OK Then box("Error OK ")
With oUpdateAnswer
If .resultCode = BFUK.UpdateBetsResultEnum.OK Then box(" Update A OK " & .success)
If .success = True Then
neueBetID = .newBetId '?
BetPrice = .newPrice '?
BetSize = .newSize '?
cancelBets(ersteBET) '?
End If
End With
End With
End If
End With
End If
End With
End Sub
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
Private Sub TestForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing My.Computer.FileSystem.WriteAllText(SessTokFile, oHeaderGL.sessionToken, False) End Sub
Private Sub TestForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
With My.Computer.FileSystem.OpenTextFileWriter(SessTokFile, False)
.WriteLine(oHeaderGL.sessionToken) 'Save the session token
.WriteLine(Setting1) 'Save setting 1
.WriteLine(Setting2) 'Save setting 2
.WriteLine(Setting3) 'Save setting 3
'etc.
.Close() 'Done
End With
End Sub
Private Sub TestForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
With My.Computer.FileSystem.OpenTextFileReader(SessTokFile)
oHeaderGL.sessionToken = .ReadLine 'Read the session token
Setting1 = .ReadLine 'Read setting 1
Setting2 = .ReadLine 'Read setting 2
Setting3 = .ReadLine 'Read setting 3
'etc.
.Close() 'Done
End With
.......
.......
End Sub
Leave a comment: