CryptoOrderbook.cs 1.1 KB

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