CryptoCandles.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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/{symbol}/candles/seconds", async (
  9. string symbol,
  10. int? count,
  11. ISender sender,
  12. CancellationToken ct
  13. ) =>
  14. {
  15. return ApiResponse.Ok(
  16. await sender.Send(new Application.Features.Api.Crypto.Candle.GetSeconds.Query(symbol, count ?? 200), ct)
  17. );
  18. })
  19. .WithTags("Crypto")
  20. .AllowAnonymous();
  21. app.MapGet("api/crypto/{symbol}/candles/minutes/{unit:int}", async (
  22. string symbol,
  23. int unit,
  24. int? count,
  25. ISender sender,
  26. CancellationToken ct
  27. ) =>
  28. {
  29. return ApiResponse.Ok(
  30. await sender.Send(new Application.Features.Api.Crypto.Candle.GetMinutes.Query(symbol, unit, count ?? 200), ct)
  31. );
  32. })
  33. .WithTags("Crypto")
  34. .AllowAnonymous();
  35. app.MapGet("api/crypto/{symbol}/candles/days", async (
  36. string symbol,
  37. int? count,
  38. ISender sender,
  39. CancellationToken ct
  40. ) =>
  41. {
  42. return ApiResponse.Ok(
  43. await sender.Send(new Application.Features.Api.Crypto.Candle.GetDays.Query(symbol, count ?? 200), ct)
  44. );
  45. })
  46. .WithTags("Crypto")
  47. .AllowAnonymous();
  48. app.MapGet("api/crypto/{symbol}/candles/weeks", async (
  49. string symbol,
  50. int? count,
  51. ISender sender,
  52. CancellationToken ct
  53. ) =>
  54. {
  55. return ApiResponse.Ok(
  56. await sender.Send(new Application.Features.Api.Crypto.Candle.GetWeeks.Query(symbol, count ?? 200), ct)
  57. );
  58. })
  59. .WithTags("Crypto")
  60. .AllowAnonymous();
  61. app.MapGet("api/crypto/{symbol}/candles/months", async (
  62. string symbol,
  63. int? count,
  64. ISender sender,
  65. CancellationToken ct
  66. ) =>
  67. {
  68. return ApiResponse.Ok(
  69. await sender.Send(new Application.Features.Api.Crypto.Candle.GetMonths.Query(symbol, count ?? 200), ct)
  70. );
  71. })
  72. .WithTags("Crypto")
  73. .AllowAnonymous();
  74. app.MapGet("api/crypto/{symbol}/candles/years", async (
  75. string symbol,
  76. int? count,
  77. ISender sender,
  78. CancellationToken ct
  79. ) =>
  80. {
  81. return ApiResponse.Ok(
  82. await sender.Send(new Application.Features.Api.Crypto.Candle.GetYears.Query(symbol, count ?? 200), ct)
  83. );
  84. })
  85. .WithTags("Crypto")
  86. .AllowAnonymous();
  87. app.MapGet("api/crypto/{symbol}/candles/live/{interval}", async (
  88. string symbol,
  89. string interval,
  90. ISender sender,
  91. CancellationToken ct
  92. ) =>
  93. {
  94. return ApiResponse.Ok(
  95. await sender.Send(new Application.Features.Api.Crypto.Candle.GetLive.Query(symbol, interval), ct)
  96. );
  97. })
  98. .WithTags("Crypto")
  99. .AllowAnonymous();
  100. }
  101. }