Fix API offset limit 400 Bad Request, implement requested UI/UX improvements
This commit is contained in:
@@ -111,6 +111,16 @@ public class PolymarketApiClient
|
||||
return result ?? [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetch CLOB orderbook for a given token ID.
|
||||
/// </summary>
|
||||
public async Task<OrderBookResponse?> GetOrderBookAsync(string tokenId, CancellationToken ct = default)
|
||||
{
|
||||
var url = $"/book?token_id={tokenId}";
|
||||
_logger.LogDebug("Fetching orderbook for token: {TokenId}", tokenId);
|
||||
return await ExecuteWithRetryAsync<OrderBookResponse>(_clobClient, url, "CLOB", ct);
|
||||
}
|
||||
|
||||
private async Task<T?> ExecuteWithRetryAsync<T>(HttpClient client, string url, string endpointGroup, CancellationToken ct, int attempt = 1)
|
||||
{
|
||||
await _rateLimiter.WaitAsync(PlatformType.Polymarket, ct, endpointGroup);
|
||||
|
||||
@@ -138,6 +138,9 @@ public class GammaMarketResponse
|
||||
[JsonPropertyName("active")] public bool Active { get; set; }
|
||||
[JsonPropertyName("resolved")] public bool Resolved { get; set; }
|
||||
[JsonPropertyName("resolution_outcome")] public string? ResolutionOutcome { get; set; }
|
||||
[JsonPropertyName("negRisk")] public bool NegRisk { get; set; }
|
||||
[JsonPropertyName("closedTime")] public string? ClosedTime { get; set; }
|
||||
[JsonPropertyName("takerFee")] [JsonConverter(typeof(FlexibleDoubleConverter))] public double TakerFee { get; set; }
|
||||
|
||||
/// <summary>JSON string of outcomes, e.g. "[\"Yes\", \"No\"]"</summary>
|
||||
[JsonPropertyName("outcomes")] public string? Outcomes { get; set; }
|
||||
@@ -165,6 +168,18 @@ public class GammaEventResponse
|
||||
[JsonPropertyName("markets")] public List<GammaMarketResponse> Markets { get; set; } = [];
|
||||
}
|
||||
|
||||
public class OrderBookResponse
|
||||
{
|
||||
[JsonPropertyName("bids")] public List<OrderBookLevel> Bids { get; set; } = [];
|
||||
[JsonPropertyName("asks")] public List<OrderBookLevel> Asks { get; set; } = [];
|
||||
}
|
||||
|
||||
public class OrderBookLevel
|
||||
{
|
||||
[JsonPropertyName("price")] public string Price { get; set; } = "0";
|
||||
[JsonPropertyName("size")] public string Size { get; set; } = "0";
|
||||
}
|
||||
|
||||
public class GammaTagResponse
|
||||
{
|
||||
[JsonPropertyName("id")] public string Id { get; set; } = "";
|
||||
|
||||
@@ -302,7 +302,10 @@ public class PolymarketProvider : IPlatformProvider
|
||||
DbCreatedAt = DateTime.UtcNow,
|
||||
IsResolved = raw.Resolved || raw.Closed,
|
||||
ResolutionOutcome = raw.ResolutionOutcome,
|
||||
LastUpdatedAt = DateTime.UtcNow
|
||||
LastUpdatedAt = DateTime.UtcNow,
|
||||
FeeRateBps = (decimal)(raw.TakerFee * 10000),
|
||||
IsNegRisk = raw.NegRisk,
|
||||
ClosedAt = DateTime.TryParse(raw.ClosedTime, out var mct) ? mct : null
|
||||
};
|
||||
|
||||
// Parse outcomes, prices, and token IDs from JSON strings
|
||||
|
||||
Reference in New Issue
Block a user