Skip to content
Open
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
7 changes: 7 additions & 0 deletions Crypto.Compare.sln
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crypto.Compare.GateIo", "so
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crypto.Compare.BitMart", "sources\integrations\Crypto.Compare.BitMart\Crypto.Compare.BitMart.csproj", "{B6196161-CEF3-48D7-8F56-692472A5E4FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crypto.Comapre.Binance", "sources\integrations\Crypto.Comapre.Binance\Crypto.Comapre.Binance.csproj", "{A62F8D6B-37A8-4D7A-A759-03E3C883239B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -111,6 +113,10 @@ Global
{B6196161-CEF3-48D7-8F56-692472A5E4FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6196161-CEF3-48D7-8F56-692472A5E4FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6196161-CEF3-48D7-8F56-692472A5E4FB}.Release|Any CPU.Build.0 = Release|Any CPU
{A62F8D6B-37A8-4D7A-A759-03E3C883239B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A62F8D6B-37A8-4D7A-A759-03E3C883239B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A62F8D6B-37A8-4D7A-A759-03E3C883239B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A62F8D6B-37A8-4D7A-A759-03E3C883239B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -135,6 +141,7 @@ Global
{410272B7-D024-49E8-9435-DDF0F309A134} = {A9E9246F-B758-4D14-ADAD-1EF937DCC5E8}
{A2DB814C-895A-4D09-AFC1-FDD0C988F2FD} = {A9E9246F-B758-4D14-ADAD-1EF937DCC5E8}
{B6196161-CEF3-48D7-8F56-692472A5E4FB} = {A9E9246F-B758-4D14-ADAD-1EF937DCC5E8}
{A62F8D6B-37A8-4D7A-A759-03E3C883239B} = {A9E9246F-B758-4D14-ADAD-1EF937DCC5E8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D179164C-BFE5-45FD-BD60-476E93A84589}
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,17 @@ INSERT INTO public."Providers"(
Need to replace in the request:
AccessKey and SecretKey - for keys from the exchange's personal account

### BINANCE

```sql
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt")
VALUES ('binance', 'https://binance.com', 'https://api.binance.com', 'AccessKey', 'SecretKey', 1,NOW(), NOW());
```

Need to replace in the request:
AccessKey and SecretKey - for keys from the exchange's personal account

## Getting API keys for exchanges

- **ByBit:** https://www.bybit.com/en/help-center/article/How-to-create-your-API-key?category=ae1012f19fad1c184e
Expand Down Expand Up @@ -502,6 +513,18 @@ INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt", "PasswordKey")
VALUES ( 'bitmart', 'https://bitmart.com', 'https://api-cloud.bitmart.com', 'AccessKey', 'SecretKey', 1,NOW(), NOW(), '');
```

Нужно заменить в запросе:
AccessKey и SecretKey - на ключи с личного кабинета биржи

### BINANCE

```sql
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt")
VALUES ('binance', 'https://binance.com', 'https://api.binance.com', 'AccessKey', 'SecretKey', 1,NOW(), NOW());
```

Нужно заменить в запросе:
AccessKey и SecretKey - на ключи с личного кабинета биржи

Expand Down
4 changes: 2 additions & 2 deletions sources/core/Crypto.Compare.Data/SymbolProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public class SymbolProvider
/// Last date get quotes
/// </summary>
public DateTime UpdatedAt { get; set; }

/// <summary>
/// id symbol
/// </summary>
public long SymbolId { get; set; }

public virtual Symbol? Symbol { get; set; }
}
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
Loading
Loading