Skip to content

Commit

Permalink
Merge pull request #38 from swisschain/LM-3196-api-trading-blocking-f…
Browse files Browse the repository at this point in the history
…ixes

LM-3196 Fixed API keys caching
  • Loading branch information
KonstantinRyazantsev committed Mar 22, 2024
2 parents 813b9df + e7615c1 commit 69f549f
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/HftApi.Worker/Profiles/WorkerProfile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System;
using System.Globalization;
using AutoMapper;
using HftApi.Common.Domain.MyNoSqlEntities;
using Lykke.MatchingEngine.Connector.Models.Events;
Expand All @@ -17,8 +18,8 @@ public WorkerProfile()
.ForMember(d => d.Expires, o => o.Ignore())
.ForMember(d => d.Id, o => o.MapFrom(x => x.ExternalId))
.ForMember(d => d.LastTradeTimestamp, o => o.MapFrom(x => x.LastMatchTime))
.ForMember(d => d.Volume, o => o.MapFrom(x => Math.Abs(Convert.ToDecimal(x.Volume))))
.ForMember(d => d.RemainingVolume, o => o.MapFrom(x => Math.Abs(Convert.ToDecimal(x.RemainingVolume))))
.ForMember(d => d.Volume, o => o.MapFrom(x => Math.Abs(Convert.ToDecimal(x.Volume, CultureInfo.InvariantCulture))))
.ForMember(d => d.RemainingVolume, o => o.MapFrom(x => Math.Abs(Convert.ToDecimal(x.RemainingVolume, CultureInfo.InvariantCulture))))
.ForMember(d => d.Type, o => o.MapFrom(x => x.OrderType.ToString()));

CreateMap<Lykke.MatchingEngine.Connector.Models.Events.Trade, Trade>(MemberList.Destination)
Expand Down
9 changes: 7 additions & 2 deletions src/HftApi/GrpcServices/PrivateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ public override async Task<LimitOrderResponse> PlaceLimitOrder(LimitOrderRequest
var walletId = context.GetHttpContext().User.GetWalletId();
var orderAction = _mapper.Map<OrderAction>(request.Side);

var result = await _validationService.ValidateLimitOrderAsync(walletId, request.AssetPairId, orderAction, Convert.ToDecimal(request.Price), Convert.ToDecimal(request.Volume));
var result = await _validationService.ValidateLimitOrderAsync(
walletId,
request.AssetPairId,
orderAction,
Convert.ToDecimal(request.Price, CultureInfo.InvariantCulture),
Convert.ToDecimal(request.Volume, CultureInfo.InvariantCulture));

if (result != null)
{
Expand Down Expand Up @@ -212,7 +217,7 @@ public override async Task<MarketOrderResponse> PlaceMarketOrder(MarketOrderRequ
{
var walletId = context.GetHttpContext().User.GetWalletId();

var result = await _validationService.ValidateMarketOrderAsync(request.AssetPairId, Convert.ToDecimal(request.Volume));
var result = await _validationService.ValidateMarketOrderAsync(request.AssetPairId, Convert.ToDecimal(request.Volume, CultureInfo.InvariantCulture));

if (result != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/HftApi/HftApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PackageReference Include="Lykke.Messaging.RabbitMq" Version="2.2.2" />
<PackageReference Include="Lykke.Service.Balances.Client" Version="2.3.2" />
<PackageReference Include="Lykke.Service.ClientDialogs.Client" Version="1.0.1" />
<PackageReference Include="Lykke.Service.HftInternalService.Client" Version="2.4.0" />
<PackageReference Include="Lykke.Service.HftInternalService.Client" Version="2.5.0" />
<PackageReference Include="Lykke.Service.Kyc.Client" Version="1.5.0" />
<PackageReference Include="Lykke.Service.Operations.Client" Version="3.1.0" />
<PackageReference Include="Lykke.Service.Operations.Contracts" Version="3.1.1" />
Expand Down
6 changes: 3 additions & 3 deletions src/HftApi/Profiles/GrpcProfile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Globalization;
using System.Linq;
using AutoMapper;
Expand Down Expand Up @@ -124,8 +124,8 @@ public GrpcProfile()
.ForMember(d => d.Expires, o => o.Ignore())
.ForMember(d => d.Id, o => o.MapFrom(x => x.ExternalId))
.ForMember(d => d.LastTradeTimestamp, o => o.MapFrom(x => x.LastMatchTime))
.ForMember(d => d.Volume, o => o.MapFrom(x => Math.Abs(Convert.ToDecimal(x.Volume))))
.ForMember(d => d.RemainingVolume, o => o.MapFrom(x => Math.Abs(Convert.ToDecimal(x.RemainingVolume))))
.ForMember(d => d.Volume, o => o.MapFrom(x => Math.Abs(Convert.ToDecimal(x.Volume, CultureInfo.InvariantCulture))))
.ForMember(d => d.RemainingVolume, o => o.MapFrom(x => Math.Abs(Convert.ToDecimal(x.RemainingVolume, CultureInfo.InvariantCulture))))
.ForMember(d => d.Type, o => o.MapFrom(x => x.OrderType.ToString()));

CreateMap<Lykke.MatchingEngine.Connector.Models.Events.Trade, Trade>(MemberList.Destination)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task HandleMessage(ClientSettingsCashoutBlockUpdated evt)
{
foreach (var key in enabledClientApiKeys)
{
_tokenService.Remove(key.ApiKey);
_tokenService.Remove(key.Id);

var apiKeyStart = key.ApiKey.Substring(0, 4);

Expand Down
2 changes: 1 addition & 1 deletion src/Lykke.HftApi.Services/Lykke.HftApi.Services.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="Lykke.Cqrs" Version="9.0.1" />
<PackageReference Include="Lykke.MatchingEngineConnector" Version="8.6.0" />
<PackageReference Include="Lykke.Service.ClientDialogs.Client" Version="1.0.1" />
<PackageReference Include="Lykke.Service.HftInternalService.Client" Version="2.4.0" />
<PackageReference Include="Lykke.Service.HftInternalService.Client" Version="2.5.0" />
<PackageReference Include="Lykke.Service.Operations.Client" Version="3.1.0" />
<PackageReference Include="Lykke.Service.Operations.Contracts" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="5.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/Lykke.HftApi.Services/TokenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task InitAsync()
{
if (!await _blockedClients.IsClientBlocked(key.ClientId))
{
_cache.TryAdd(key.ApiKey, 0);
_cache.TryAdd(key.Id, 0);
}
}

Expand Down

0 comments on commit 69f549f

Please sign in to comment.