Skip to content

Commit 0c5b5ab

Browse files
committed
additional odds formats
1 parent 29c9a76 commit 0c5b5ab

File tree

8 files changed

+140
-1
lines changed

8 files changed

+140
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Text.Json.Serialization;
2+
using Sportradar.Mbs.Sdk.Internal.Utils;
3+
4+
namespace Sportradar.Mbs.Sdk.Entities.Odds;
5+
6+
/// <summary>
7+
/// Represents fractional odds.
8+
/// </summary>
9+
public class FractionalOdds : OddsBase
10+
{
11+
[JsonInclude]
12+
[JsonPropertyName("type")]
13+
private string Type => "fractional";
14+
15+
/// <summary>
16+
/// Gets or sets the value of the numerator (top, first part) of the fractional odds.
17+
/// </summary>
18+
[JsonConverter(typeof(LongJsonConverter))]
19+
[JsonPropertyName("numerator")]
20+
public long? Numerator { get; set; }
21+
22+
/// <summary>
23+
/// Gets or sets the value of the denominator (bottom, last part) of the fractional odds.
24+
/// </summary>
25+
[JsonConverter(typeof(LongJsonConverter))]
26+
[JsonPropertyName("denominator")]
27+
public long? Denominator { get; set; }
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Text.Json.Serialization;
2+
using Sportradar.Mbs.Sdk.Internal.Utils;
3+
4+
namespace Sportradar.Mbs.Sdk.Entities.Odds;
5+
6+
/// <summary>
7+
/// Represents hong kong odds.
8+
/// </summary>
9+
public class HongKongOdds : OddsBase
10+
{
11+
[JsonInclude]
12+
[JsonPropertyName("type")]
13+
private string Type => "hong-kong";
14+
15+
/// <summary>
16+
/// Gets or sets the hong kong value of the odds: eg "0.75".
17+
/// </summary>
18+
[JsonConverter(typeof(DecimalJsonConverter))]
19+
[JsonPropertyName("value")]
20+
public decimal? Value { get; set; }
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Text.Json.Serialization;
2+
using Sportradar.Mbs.Sdk.Internal.Utils;
3+
4+
namespace Sportradar.Mbs.Sdk.Entities.Odds;
5+
6+
/// <summary>
7+
/// Represents indonesian odds.
8+
/// </summary>
9+
public class IndonesianOdds : OddsBase
10+
{
11+
[JsonInclude]
12+
[JsonPropertyName("type")]
13+
private string Type => "indonesian";
14+
15+
/// <summary>
16+
/// Gets or sets the indonesian value of the odds: eg "-3.4".
17+
/// </summary>
18+
[JsonConverter(typeof(DecimalJsonConverter))]
19+
[JsonPropertyName("value")]
20+
public decimal? Value { get; set; }
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Text.Json.Serialization;
2+
using Sportradar.Mbs.Sdk.Internal.Utils;
3+
4+
namespace Sportradar.Mbs.Sdk.Entities.Odds;
5+
6+
/// <summary>
7+
/// Represents malay odds.
8+
/// </summary>
9+
public class MalayOdds : OddsBase
10+
{
11+
[JsonInclude]
12+
[JsonPropertyName("type")]
13+
private string Type => "malay";
14+
15+
/// <summary>
16+
/// Gets or sets the malay value of the odds: eg "0.75".
17+
/// </summary>
18+
[JsonConverter(typeof(DecimalJsonConverter))]
19+
[JsonPropertyName("value")]
20+
public decimal? Value { get; set; }
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Text.Json.Serialization;
2+
using Sportradar.Mbs.Sdk.Internal.Utils;
3+
4+
namespace Sportradar.Mbs.Sdk.Entities.Odds;
5+
6+
/// <summary>
7+
/// Represents moneyline odds.
8+
/// </summary>
9+
public class MoneylineOdds : OddsBase
10+
{
11+
[JsonInclude]
12+
[JsonPropertyName("type")]
13+
private string Type => "moneyline";
14+
15+
/// <summary>
16+
/// Gets or sets the moneyline value of the odds: eg "-340".
17+
/// </summary>
18+
[JsonConverter(typeof(LongJsonConverter))]
19+
[JsonPropertyName("value")]
20+
public long? Value { get; set; }
21+
}

src/Sportradar.Mbs.Sdk/Entities/Odds/OddsBase.cs

+5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ public override OddsBase Read(ref Utf8JsonReader reader, Type typeToConvert, Jso
2121

2222
OddsBase? result = type switch
2323
{
24+
"indonesian" => JsonSerializer.Deserialize<IndonesianOdds>(root.GetRawText()),
25+
"hong-kong" => JsonSerializer.Deserialize<HongKongOdds>(root.GetRawText()),
26+
"fractional" => JsonSerializer.Deserialize<FractionalOdds>(root.GetRawText()),
2427
"decimal" => JsonSerializer.Deserialize<DecimalOdds>(root.GetRawText()),
28+
"moneyline" => JsonSerializer.Deserialize<MoneylineOdds>(root.GetRawText()),
29+
"malay" => JsonSerializer.Deserialize<MalayOdds>(root.GetRawText()),
2530
_ => throw new JsonException("Unknown type of OddsBase: " + type)
2631
};
2732
return result ?? throw new NullReferenceException("Null OddsBase: " + type);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Globalization;
2+
using System.Text.Json;
3+
using System.Text.Json.Serialization;
4+
5+
namespace Sportradar.Mbs.Sdk.Internal.Utils;
6+
7+
internal class LongJsonConverter : JsonConverter<long>
8+
{
9+
public override long Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
10+
{
11+
var jsonVal = reader.GetString();
12+
if (long.TryParse(jsonVal, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result)) return result;
13+
14+
throw new JsonException("Unknown long: " + jsonVal);
15+
}
16+
17+
public override void Write(Utf8JsonWriter writer, long value, JsonSerializerOptions options)
18+
{
19+
var jsonVal = value.ToString(CultureInfo.InvariantCulture);
20+
writer.WriteStringValue(jsonVal);
21+
}
22+
}

src/Sportradar.Mbs.Sdk/Sportradar.Mbs.Sdk.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</PropertyGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="System.Text.Json" Version="8.0.0"/>
30+
<PackageReference Include="System.Text.Json" Version="8.0.5"/>
3131
<PackageReference Include="System.Threading.Channels" Version="8.0.0"/>
3232
</ItemGroup>
3333

0 commit comments

Comments
 (0)