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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Binance.Net.Objects.Models.Futures;
using HyBe.SharedKernel.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HyBe.Application.Abstractions.Infrastructure
{
public interface IBinanceFutureService
{
Task<List<BinanceFuturesUsdtSymbol>> GetListSymbol();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace HyBe.Application.Features.Symbols.Commands.DeleteSymbol
public class DeleteSymbolCommand : IRequest<IResult>
{
public DeleteSymbolRequest Request { get; set; }
public string MemberId { get; set; }

public DeleteSymbolCommand(DeleteSymbolRequest request)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ public DeleteSymbolCommandHandler(ISymbolService symbolService, IMapper mapper)
#region Methods
public async Task<IResult> Handle(DeleteSymbolCommand query, CancellationToken cancellationToken)
{
var getSymbol = _symbolService.Get(b => b.MemberId.ToString() == query.MemberId && b.Id == query.Request.Id);
if (getSymbol.Success == false)
{
return new ErrorResult("Data Not Found!");
}
var result = _symbolService.Delete(query.Request.Id);
if (result.Success)
return new SuccessResult();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using HyBe.Domain.Contracts.Backtests;
using HyBe.Domain.Contracts.Symbols;
using HyBe.Domain.Contracts.Symbols;
using HyBe.SharedKernel.Utilities;
using MediatR;
using System;
Expand All @@ -13,7 +12,6 @@ namespace HyBe.Application.Features.Symbols.Commands.UpdateSymbol
public class UpdateSymbolCommand : IRequest<IResult>
{
public UpdateSymbolRequest Request { get; set; }
public string MemberId { get; set; }

public UpdateSymbolCommand(UpdateSymbolRequest request)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ public UpdateSymbolCommandHandler(ISymbolService symbolService, IMapper mapper)
#region Methods
public async Task<IResult> Handle(UpdateSymbolCommand query, CancellationToken cancellationToken)
{
var getSymbol = _symbolService.Get(b => b.MemberId.ToString() == query.MemberId && b.Id == query.Request.Id);
if (getSymbol == null)
{
return new ErrorResult("Data Not Found!");
}
var symbolMapper = _mapper.Map<Symbol>(query.Request);
var result = _symbolService.Update(symbolMapper);
if (result.Success)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public GetByIdSymbolQueryHandler(ISymbolService symbolService, IMapper mapper)
public async Task<IResult> Handle(GetByIdSymbolQuery query, CancellationToken cancellationToken)
{

var result = _symbolService.Get(b => b.MemberId.ToString() == query.Request.MemberId && b.Id == query.Request.Id);
var result = _symbolService.Get(b => b.Id == query.Request.Id);
if (result.Success)
{
var symbolMapper = _mapper.Map<GetByIdSymbolResponse>(result.Data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public GetListSymbolQueryHandler(ISymbolService symbolService, IMapper mapper)
public async Task<IResult> Handle(GetListSymbolQuery query, CancellationToken cancellationToken)
{

var result = _symbolService.GetAll(b => b.MemberId.ToString() == query.Request.MemberId);
var result = _symbolService.GetAll();
if (result.Success)
{
var symbolMapper = _mapper.Map<List<GetListSymbolResponse>>(result.Data);
Expand Down
5 changes: 4 additions & 1 deletion Core/HyBe.Domain/Entities/Symbols/Symbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ public class Symbol : BaseEntity
public decimal MinQuantity { get; set; }
public decimal MaxQuantity { get; set; }
public bool IsActive { get; set; }
public Guid MemberId { get; set; }
public decimal StepSize { get; set; }
public decimal TickSize { get; set; }
public decimal Precision { get; set; }
public string Icon { get; set; }
}
24 changes: 13 additions & 11 deletions Core/HyBe.SharedKernel/HyBe.SharedKernel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,28 @@
<Folder Include="Utilities\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PackageReference Include="Binance.Net" Version="9.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.13">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.5" />
<PackageReference Include="MediatR" Version="12.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.13" />
<PackageReference Include="MediatR" Version="12.1.1" />
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="AutoMapper.Extensions.EnumMapping" Version="3.1.0" />
<PackageReference Include="FluentValidation" Version="11.5.2" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.5.2" />
<PackageReference Include="Autofac" Version="7.0.1" />
<PackageReference Include="FluentValidation" Version="11.8.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.8.0" />
<PackageReference Include="Autofac" Version="7.1.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.30.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.5" />
<PackageReference Include="RestSharp" Version="110.2.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.13" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Binance.Net.Clients;
using Binance.Net.Interfaces.Clients;
using Binance.Net.Objects.Models.Futures;
using CryptoExchange.Net.Authentication;
using HyBe.Application.Abstractions.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HyBe.Infrastructure.ExternalServices.BinanceFeatures
{
public class BinanceFutureService : IBinanceFutureService
{
private readonly IBinanceRestClient _client;
public BinanceFutureService()
{
var binanceClient = new BinanceRestClient(options => { options.UsdFuturesOptions.ApiCredentials = new ApiCredentials("", ""); });
_client = binanceClient;
}
public async Task<List<BinanceFuturesUsdtSymbol>> GetListSymbol()
{
var symbolList = await _client.UsdFuturesApi.ExchangeData.GetExchangeInfoAsync();
if (symbolList.Success)
{
return symbolList.Data.Symbols.ToList();
}
return new List<BinanceFuturesUsdtSymbol>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static class InfrastructureServiceRegistration
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services)
{
services.AddScoped<INotificationService, TelegramNotificationService>();
services.AddScoped<IBinanceFutureService, IBinanceFutureService>();
return services;
}
}
Expand Down
51 changes: 49 additions & 2 deletions Infrastructure/HyBe.Persistence/Services/SymbolService.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,62 @@
using HyBe.Application.Abstractions.Services;
using CryptoExchange.Net.Interfaces;
using HyBe.Application.Abstractions.Infrastructure;
using HyBe.Application.Abstractions.Services;
using HyBe.Domain.Entities.Symbols;
using HyBe.Persistence.Contexts;
using HyBe.Persistence.Repositories;
using HyBe.SharedKernel.Repositories;
using System.Net;

namespace HyBe.Persistence.Services;

public class SymbolService : EfRepository<Symbol>, ISymbolService
{
public SymbolService(HypanceDbContext hypanceDbContext) : base(hypanceDbContext)
private readonly IBinanceFutureService _binanceFutureService;
public SymbolService(HypanceDbContext hypanceDbContext, IBinanceFutureService binanceFutureService) : base(hypanceDbContext)
{
_binanceFutureService = binanceFutureService;
}
public async Task AddOrUpdateSymbolList()
{
var symbolList = await _binanceFutureService.GetListSymbol();
foreach (var symbol in symbolList)
{
var newSymbol = new Symbol
{
Name = symbol.Pair,
MinQuantity = symbol.LotSizeFilter.MinQuantity,
MaxQuantity = symbol.LotSizeFilter.MaxQuantity,
IsActive = true,
TickSize = symbol.PriceFilter.TickSize,
StepSize = symbol.LotSizeFilter.StepSize,
Precision = symbol.PricePrecision,
Icon = GetSymbolIcon(symbol.BaseAsset)
};
Add(newSymbol);
}
}
private string GetSymbolIcon(string coin)
{
string imageUrl = $"https://s3-symbol-logo.tradingview.com/crypto/XTVC%7Bcoin%7D--big.svg";
string fileName = $"{coin}.svg";
string savePath = Path.Combine(Environment.CurrentDirectory, "wwwroot/icons");
Directory.CreateDirectory(savePath);
string filePath = Path.Combine(savePath, fileName);
if (File.Exists(filePath))
return filePath;

using (WebClient client = new WebClient())
{
try
{
client.DownloadFile(imageUrl, filePath);
return filePath;
}
catch (Exception ex)
{
return ex.Message;
}
}
}
}

13 changes: 1 addition & 12 deletions Presentation/HyBe.WebAPI/Controllers/v1/SymbolController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public async Task<IActionResult> GetList()
{
try
{
System.Security.Claims.ClaimsPrincipal currentUser = this.User;
var claims = currentUser.Claims.ToArray();
var request = new GetListSymbolRequest { MemberId = claims[3].Value };
var request = new GetListSymbolRequest {};
var query = _mapper.Map<GetListSymbolQuery>(request);
var result = await _mediatr.Send(query);
return Ok(result);
Expand Down Expand Up @@ -69,10 +67,7 @@ public async Task<IActionResult> Create([FromBody] CreateSymbolRequest request)
{
try
{
System.Security.Claims.ClaimsPrincipal currentUser = this.User;
var claims = currentUser.Claims.ToArray();
var query = _mapper.Map<CreateSymbolCommand>(request);
query.Request.MemberId = claims[3].Value;
var result = await _mediatr.Send(query);
return Ok(result);
}
Expand All @@ -87,10 +82,7 @@ public async Task<IActionResult> Update([FromBody] UpdateSymbolRequest request)
{
try
{
System.Security.Claims.ClaimsPrincipal currentUser = this.User;
var claims = currentUser.Claims.ToArray();
var query = _mapper.Map<UpdateSymbolCommand>(request);
query.MemberId = claims[3].Value;
var result = await _mediatr.Send(query);
return Ok(result);
}
Expand All @@ -105,10 +97,7 @@ public async Task<IActionResult> Delete([FromBody] DeleteSymbolRequest request)
{
try
{
System.Security.Claims.ClaimsPrincipal currentUser = this.User;
var claims = currentUser.Claims.ToArray();
var query = _mapper.Map<DeleteSymbolCommand>(request);
query.MemberId = claims[3].Value;
var result = await _mediatr.Send(query);
return Ok(result);
}
Expand Down
4 changes: 4 additions & 0 deletions Presentation/HyBe.WebAPI/HyBe.WebAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@
</ProjectReference>
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\Icons\" />
</ItemGroup>


</Project>