| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using MediatR;
- using Web.Api.Common;
- namespace Web.Api.Endpoints.Crypto;
- internal sealed class CryptoCandles : IEndpoint
- {
- public void MapEndpoint(IEndpointRouteBuilder app)
- {
- app.MapGet("api/crypto/{market}/candles/seconds", async (
- string market,
- int? count,
- ISender sender,
- CancellationToken ct
- ) =>
- {
- var response = await sender.Send(new Application.Features.Api.Crypto.Candle.GetSeconds.Query(NormalizeMarket(market), count ?? 200), ct);
- return ApiResponse.Ok(response.Candles);
- })
- .WithTags("Crypto")
- .AllowAnonymous();
- app.MapGet("api/crypto/{market}/candles/minutes/{unit:int}", async (
- string market,
- int unit,
- int? count,
- ISender sender,
- CancellationToken ct
- ) =>
- {
- var response = await sender.Send(new Application.Features.Api.Crypto.Candle.GetMinutes.Query(NormalizeMarket(market), unit, count ?? 200), ct);
- return ApiResponse.Ok(response.Candles);
- })
- .WithTags("Crypto")
- .AllowAnonymous();
- app.MapGet("api/crypto/{market}/candles/days", async (
- string market,
- int? count,
- ISender sender,
- CancellationToken ct
- ) =>
- {
- var response = await sender.Send(new Application.Features.Api.Crypto.Candle.GetDays.Query(NormalizeMarket(market), count ?? 200), ct);
- return ApiResponse.Ok(response.Candles);
- })
- .WithTags("Crypto")
- .AllowAnonymous();
- app.MapGet("api/crypto/{market}/candles/weeks", async (
- string market,
- int? count,
- ISender sender,
- CancellationToken ct
- ) =>
- {
- var response = await sender.Send(new Application.Features.Api.Crypto.Candle.GetWeeks.Query(NormalizeMarket(market), count ?? 200), ct);
- return ApiResponse.Ok(response.Candles);
- })
- .WithTags("Crypto")
- .AllowAnonymous();
- app.MapGet("api/crypto/{market}/candles/months", async (
- string market,
- int? count,
- ISender sender,
- CancellationToken ct
- ) =>
- {
- var response = await sender.Send(new Application.Features.Api.Crypto.Candle.GetMonths.Query(NormalizeMarket(market), count ?? 200), ct);
- return ApiResponse.Ok(response.Candles);
- })
- .WithTags("Crypto")
- .AllowAnonymous();
- app.MapGet("api/crypto/{market}/candles/years", async (
- string market,
- int? count,
- ISender sender,
- CancellationToken ct
- ) =>
- {
- var response = await sender.Send(new Application.Features.Api.Crypto.Candle.GetYears.Query(NormalizeMarket(market), count ?? 200), ct);
- return ApiResponse.Ok(response.Candles);
- })
- .WithTags("Crypto")
- .AllowAnonymous();
- app.MapGet("api/crypto/{market}/candles/live/{interval}", async (
- string market,
- string interval,
- ISender sender,
- CancellationToken ct
- ) =>
- {
- var response = await sender.Send(new Application.Features.Api.Crypto.Candle.GetLive.Query(NormalizeMarket(market), interval), ct);
- return ApiResponse.Ok(response.Candle);
- })
- .WithTags("Crypto")
- .AllowAnonymous();
- }
- private static string NormalizeMarket(string input) =>
- input.Contains('-') ? input.ToUpper() : $"KRW-{input.ToUpper()}";
- }
|