CryptoCandles.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using MediatR;
  2. using Web.Api.Common;
  3. namespace Web.Api.Endpoints.Crypto;
  4. internal sealed class CryptoCandles : IEndpoint
  5. {
  6. public void MapEndpoint(IEndpointRouteBuilder app)
  7. {
  8. app.MapGet("api/crypto/{market}/candles/seconds", 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.Candle.GetSeconds.Query(NormalizeMarket(market), count ?? 200), ct);
  16. return ApiResponse.Ok(response.Candles);
  17. })
  18. .WithTags("Crypto")
  19. .AllowAnonymous();
  20. app.MapGet("api/crypto/{market}/candles/minutes/{unit:int}", async (
  21. string market,
  22. int unit,
  23. int? count,
  24. ISender sender,
  25. CancellationToken ct
  26. ) =>
  27. {
  28. var response = await sender.Send(new Application.Features.Api.Crypto.Candle.GetMinutes.Query(NormalizeMarket(market), unit, count ?? 200), ct);
  29. return ApiResponse.Ok(response.Candles);
  30. })
  31. .WithTags("Crypto")
  32. .AllowAnonymous();
  33. app.MapGet("api/crypto/{market}/candles/days", async (
  34. string market,
  35. int? count,
  36. ISender sender,
  37. CancellationToken ct
  38. ) =>
  39. {
  40. var response = await sender.Send(new Application.Features.Api.Crypto.Candle.GetDays.Query(NormalizeMarket(market), count ?? 200), ct);
  41. return ApiResponse.Ok(response.Candles);
  42. })
  43. .WithTags("Crypto")
  44. .AllowAnonymous();
  45. app.MapGet("api/crypto/{market}/candles/weeks", async (
  46. string market,
  47. int? count,
  48. ISender sender,
  49. CancellationToken ct
  50. ) =>
  51. {
  52. var response = await sender.Send(new Application.Features.Api.Crypto.Candle.GetWeeks.Query(NormalizeMarket(market), count ?? 200), ct);
  53. return ApiResponse.Ok(response.Candles);
  54. })
  55. .WithTags("Crypto")
  56. .AllowAnonymous();
  57. app.MapGet("api/crypto/{market}/candles/months", async (
  58. string market,
  59. int? count,
  60. ISender sender,
  61. CancellationToken ct
  62. ) =>
  63. {
  64. var response = await sender.Send(new Application.Features.Api.Crypto.Candle.GetMonths.Query(NormalizeMarket(market), count ?? 200), ct);
  65. return ApiResponse.Ok(response.Candles);
  66. })
  67. .WithTags("Crypto")
  68. .AllowAnonymous();
  69. app.MapGet("api/crypto/{market}/candles/years", async (
  70. string market,
  71. int? count,
  72. ISender sender,
  73. CancellationToken ct
  74. ) =>
  75. {
  76. var response = await sender.Send(new Application.Features.Api.Crypto.Candle.GetYears.Query(NormalizeMarket(market), count ?? 200), ct);
  77. return ApiResponse.Ok(response.Candles);
  78. })
  79. .WithTags("Crypto")
  80. .AllowAnonymous();
  81. app.MapGet("api/crypto/{market}/candles/live/{interval}", async (
  82. string market,
  83. string interval,
  84. ISender sender,
  85. CancellationToken ct
  86. ) =>
  87. {
  88. var response = await sender.Send(new Application.Features.Api.Crypto.Candle.GetLive.Query(NormalizeMarket(market), interval), ct);
  89. return ApiResponse.Ok(response.Candle);
  90. })
  91. .WithTags("Crypto")
  92. .AllowAnonymous();
  93. }
  94. private static string NormalizeMarket(string input) =>
  95. input.Contains('-') ? input.ToUpper() : $"KRW-{input.ToUpper()}";
  96. }