CryptoTrades.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using MediatR;
  2. using Web.Api.Common;
  3. namespace Web.Api.Endpoints.Crypto;
  4. internal sealed class CryptoTrades : IEndpoint
  5. {
  6. public void MapEndpoint(IEndpointRouteBuilder app)
  7. {
  8. app.MapGet("api/crypto/{market}/trades", async (
  9. string market,
  10. int? count,
  11. ISender sender,
  12. CancellationToken ct
  13. ) =>
  14. {
  15. var response = await sender.Send(new Application.Features.Api.Crypto.Trade.GetRecent.Query(NormalizeMarket(market), count ?? 50), ct);
  16. return ApiResponse.Ok(response.Trades);
  17. })
  18. .WithTags("Crypto")
  19. .AllowAnonymous();
  20. app.MapGet("api/crypto/{market}/trades/live", async (
  21. string market,
  22. ISender sender,
  23. CancellationToken ct
  24. ) =>
  25. {
  26. var response = await sender.Send(new Application.Features.Api.Crypto.Trade.GetLive.Query(NormalizeMarket(market)), ct);
  27. return ApiResponse.Ok(response.Trade);
  28. })
  29. .WithTags("Crypto")
  30. .AllowAnonymous();
  31. }
  32. private static string NormalizeMarket(string input) =>
  33. input.Contains('-') ? input.ToUpper() : $"KRW-{input.ToUpper()}";
  34. }