Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="FluentResults" Version="4.0.0" />
<PackageReference Include="MediatR" Version="14.1.0" />
<PackageReference Include="MediatR.Contracts" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.5" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.7" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Crypto.Compare.DataAccess;
using Crypto.Compare.Services.Queries.Symbols;
using Crypto.Compare.Services.Results.Symbols;
using FluentResults;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace Crypto.Compare.Services.Handlers.Queries.Symbols;

public class GetSymbolsBestPriceQueryHandler : IRequestHandler<GetSymbolsBestPriceQuery, Result<GetSymbolsBestPriceResult>>
{
private readonly CryptoCompareContext _cryptoCompareContext;

public GetSymbolsBestPriceQueryHandler(CryptoCompareContext cryptoCompareContext)
{
_cryptoCompareContext = cryptoCompareContext;
}

public async Task<Result<GetSymbolsBestPriceResult>> Handle(GetSymbolsBestPriceQuery request, CancellationToken cancellationToken)
{
var query = _cryptoCompareContext
.Symbols
.Include(x => x.SymbolProviders)
.AsQueryable()
.AsNoTracking();

if (!string.IsNullOrEmpty(request.Ticker))
{
query = query.Where(x => x.Ticker == request.Ticker);
}

var symbols = await query
.Select(symbol => new SymbolResult
{
Id = symbol.Id,
Ticker = symbol.Ticker,
Symbol = $"{symbol.BaseSymbol}/{symbol.QuoteSymbol}",
ProviderSellId = symbol.SymbolProviders
.OrderByDescending(sp => sp.PriceSell)
.Select(sp => sp.ProviderId)
.FirstOrDefault(),
PriceSell = symbol.SymbolProviders
.OrderByDescending(sp => sp.PriceSell)
.Select(sp => sp.PriceSell)
.FirstOrDefault(),
ProviderBuyId = symbol.SymbolProviders
.OrderBy(sp => sp.PriceBuy)
.Select(sp => sp.ProviderId)
.FirstOrDefault(),
PriceBuy = symbol.SymbolProviders
.OrderBy(sp => sp.PriceBuy)
.Select(sp => sp.PriceBuy)
.FirstOrDefault(),
UpdatedAt = symbol.UpdatedAt
})
.Skip((int)request.Skip)
.Take(request.Rows)
.ToListAsync(cancellationToken);

return new GetSymbolsBestPriceResult
{
Symbols = symbols
};
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Crypto.Compare.DataAccess;
using Crypto.Compare.Services.Queries.Symbols;
using Crypto.Compare.Services.Results.Symbols;
using Crypto.Compare.Services.Results.SymbolProviders;
using FluentResults;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace Crypto.Compare.Services.Handlers.Queries.Symbols;

public class GetSymbolsQueryHandler : IRequestHandler<GetSymbolsQuery, Result<GetSymbolsResult>>
public class GetSymbolsQueryHandler : IRequestHandler<GetSymbolsQuery, Result<GetSymbolProviderResult>>
{
private readonly CryptoCompareContext _cryptoCompareContext;

Expand All @@ -16,50 +16,28 @@ public GetSymbolsQueryHandler(CryptoCompareContext cryptoCompareContext)
_cryptoCompareContext = cryptoCompareContext;
}

public async Task<Result<GetSymbolsResult>> Handle(GetSymbolsQuery request, CancellationToken cancellationToken)
public async Task<Result<GetSymbolProviderResult>> Handle(GetSymbolsQuery request, CancellationToken cancellationToken)
{
var query = _cryptoCompareContext
.Symbols
.Include(x=>x.SymbolProviders)
.AsQueryable()
.AsNoTracking();

if (!string.IsNullOrEmpty(request.Ticker))
{
query = query.Where(x => x.Ticker == request.Ticker);
}

var symbols = await query
.Select(symbol => new SymbolResult
{
Id = symbol.Id,
Ticker = symbol.Ticker,
Symbol = $"{symbol.BaseSymbol}/{symbol.QuoteSymbol}",
ProviderSellId = symbol.SymbolProviders
.OrderByDescending(sp => sp.PriceSell)
.Select(sp => sp.ProviderId)
.FirstOrDefault(),
PriceSell = symbol.SymbolProviders
.OrderByDescending(sp => sp.PriceSell)
.Select(sp => sp.PriceSell)
.FirstOrDefault(),
ProviderBuyId = symbol.SymbolProviders
.OrderBy(sp => sp.PriceBuy)
.Select(sp => sp.ProviderId)
.FirstOrDefault(),
PriceBuy = symbol.SymbolProviders
.OrderBy(sp => sp.PriceBuy)
.Select(sp => sp.PriceBuy)
.FirstOrDefault(),
UpdatedAt = symbol.UpdatedAt
})
.Skip((int)request.Skip)
.Take(request.Rows)
.ToListAsync(cancellationToken);

return new GetSymbolsResult
{
Symbols = symbols
};
return
new GetSymbolProviderResult()
{
Symbols = await _cryptoCompareContext
.SymbolProviders
.AsQueryable()
.AsNoTracking()
.Include(x => x.Symbol)
.Where(x => x.Symbol.Ticker == request.Ticker)
.Select(s => new SymbolProviderResult
{
Id = s.Symbol.Id,
Ticker = s.Ticker,
Symbol = $"{s.Symbol.BaseSymbol}/{s.Symbol.QuoteSymbol}",
ProviderId = s.ProviderId,
PriceSell = s.PriceSell,
PriceBuy = s.PriceBuy,
UpdatedAt = s.UpdatedAt
})
.ToListAsync(cancellationToken)
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Crypto.Compare.Services.Results.Symbols;
using FluentResults;
using MediatR;

namespace Crypto.Compare.Services.Queries.Symbols;

public class GetSymbolsBestPriceQuery : IRequest<Result<GetSymbolsBestPriceResult>>
{
private const int MaxRows = 30;
private const int DefaultRows = 10;

public GetSymbolsBestPriceQuery(string? ticker = null, long? skip = 0, int? rows = DefaultRows)
{
Ticker = ticker?.ToLowerInvariant();
Skip = skip ?? 0;
Rows = rows is null or < 10 or > MaxRows ? DefaultRows : rows.Value;
}

/// <summary>
/// Ticker symbol
/// </summary>
public string? Ticker { get; }

/// <summary>
/// Skip rows
/// </summary>
public long Skip { get; }

/// <summary>
/// Get rows
/// </summary>
public int Rows { get; }
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,7 @@
using Crypto.Compare.Services.Results.Symbols;
using Crypto.Compare.Services.Results.SymbolProviders;
using FluentResults;
using MediatR;

namespace Crypto.Compare.Services.Queries.Symbols;

public class GetSymbolsQuery : IRequest<Result<GetSymbolsResult>>
{
private const int MaxRows = 30;
private const int DefaultRows = 10;

public GetSymbolsQuery(string? ticker = null, long? skip = 0, int? rows = DefaultRows)
{
Ticker = ticker?.ToLowerInvariant();
Skip = skip ?? 0;
Rows = rows is null or < 10 or > MaxRows ? DefaultRows : rows.Value;
}

/// <summary>
/// Ticker symbol
/// </summary>
public string? Ticker { get; }

/// <summary>
/// Skip rows
/// </summary>
public long Skip { get; }

/// <summary>
/// Get rows
/// </summary>
public int Rows { get; }
}
public record GetSymbolsQuery(string Ticker) : IRequest<Result<GetSymbolProviderResult>>;
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Crypto.Compare.Data;

namespace Crypto.Compare.Services.Results.SymbolProviders;
namespace Crypto.Compare.Services.Results.SymbolProviders;

public class GetSymbolProviderResult : IHandlerResult
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Crypto.Compare.Services.Results.Symbols;

public class GetSymbolsBestPriceResult : IHandlerResult
{
public List<SymbolResult> Symbols { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace Crypto.Compare.Services.Results.Symbols;
using Crypto.Compare.Data;

public class GetSymbolsResult : IHandlerResult
namespace Crypto.Compare.Services.Results.Symbols;

public class GetSymbolsResult
{
public List<SymbolResult> Symbols { get; set; }
}
public List<Symbol> Symbols { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="7.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="10.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="10.0.7" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Binance.Net" Version="12.11.3" />
<PackageReference Include="Binance.Net" Version="12.11.4" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JK.BingX.Net" Version="3.9.1" />
<PackageReference Include="JK.BingX.Net" Version="3.10.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BitMart.Net" Version="3.9.1" />
<PackageReference Include="BitMart.Net" Version="3.10.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JK.Bitget.Net" Version="3.9.0" />
<PackageReference Include="JK.Bitget.Net" Version="3.10.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bybit.Net" Version="6.10.0" />
<PackageReference Include="Bybit.Net" Version="6.11.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GateIo.Net" Version="3.10.1" />
<PackageReference Include="GateIo.Net" Version="3.10.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="JK.Mexc.Net" Version="5.0.0" />
<PackageReference Include="JK.Mexc.Net" Version="5.0.1" />
<PackageReference Include="CryptoExchange.Net" Version="11.1.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ProjectReference Include="..\..\core\Crypto.Compare.Data\Crypto.Compare.Data.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="XT.Net" Version="3.9.1" />
<PackageReference Include="XT.Net" Version="3.9.2" />
</ItemGroup>

</Project>
Loading
Loading