Hoytman999,
I’m fairly sure floating-point rounding errors cause these problems. I prefer to use the Decimal data type (rather than Double) to hold price and amount values.
Here's Function BFPrice. This will round any value to a valid Betfair price:
Code:
'Rounds to the nearest Betfair price value
Private OddsLim() As Decimal = {2, 3, 4, 6, 10, 20, 30, 50, 100} 'Odds range limits
Private OddsInc() As Decimal = {0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10} 'Odds increments
Function BFPrice(ByVal Price As Decimal) As Decimal
Dim i As Integer, p As Decimal
For i = 0 To UBound(OddsLim) 'Determine price range
If Price <= OddsLim(i) Then Exit For
Next i
p = Decimal.Round(Price / OddsInc(i), MidpointRounding.AwayFromZero) * OddsInc(i) 'Round to the nearest valid price
Return Math.Min(Math.Max(p, 1.01D), 1000D) 'Keep within limits
End Function



Leave a comment: