Skip to content

Commit

Permalink
Merge branch 'feature_LWDEV-7845-Bulk-orders' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
njannink committed Jul 9, 2018
2 parents 09586fc + b5e77c3 commit 464f1d3
Show file tree
Hide file tree
Showing 23 changed files with 437 additions and 45 deletions.
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Lykke.Service.HftInternalService
# Lykke.Service.Hft

Lykke internal service for creation and management of high-frequency trading wallets and it's api-keys.
Lykke service for high frequency trading.

Nuget: https://www.nuget.org/packages/Lykke.Service.HFT.Client/

Expand Down Expand Up @@ -171,4 +171,30 @@ await client.CancelLimitOrder(orderId);

// Cancel all open limit orders
await client.CancelAll();
```
```

#### Bulk limit orders
```csharp
var order = new PlaceBulkOrderModel
{
AssetPairId = "BTCUSD",
CancelPreviousOrders = true,
Orders = Enumerable.Range(0,10).Select(x => new BulkOrderItemModel
{
OrderAction = OrderAction.Buy,
Price = 500 + x,
Volume = 0.001
})
};

var result = await client.PlaceBulkOrder(order).TryExecute();

if (!result.Success) {
Console.WriteLine(result.Error);
} else {
foreach(var status in result.Statuses) {
// Handle the specific order status
// Order progress can be retrieved by Id or cancelled by like regular limit orders
}
}
```
11 changes: 11 additions & 0 deletions client/Lykke.Service.HFT.Client/IOrdersApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ Task<Guid> PlaceLimitOrder(
[Body] PlaceLimitOrderModel limitOrder,
[Header("api-key")] string apiKey = null);

/// <summary>
/// Places a bulk limit order.
/// </summary>
/// <param name="bulkOrder">The bulk order data.</param>
/// <param name="apiKey">The API key header. Can also be send using a custom handler or the Lykke WithApiKey call on the client generator.</param>
/// <returns>the limit order ID</returns>
[Post("/api/Orders/bulk")]
Task<BulkOrderResponseModel> PlaceBulkOrder(
[Body] PlaceBulkOrderModel bulkOrder,
[Header("api-key")] string apiKey = null);

/// <summary>
/// Cancels the specific limit order.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>2.0.0</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup>
<Authors>Lykke</Authors>
<Company>Lykke</Company>
<Product>Lykke.Service.HFT</Product>
Expand All @@ -15,7 +21,6 @@
<RepositoryUrl>https://github.com/LykkeCity/Lykke.Service.HFT.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>lykke;hft;internal;refit;api-client</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -27,4 +32,5 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Lykke.Service.HFT.Contracts\Lykke.Service.HFT.Contracts.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<ApplicationIcon />
<OutputType>Exe</OutputType>
<StartupObject />
<Version>1.0.0</Version>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Lykke.Common" Version="7.0.1" />
<PackageReference Include="Lykke.WampSharp.Default.Client" Version="1.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Lykke.Service.HFT.Contracts\Lykke.Service.HFT.Contracts.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<Version>1.0.0</Version>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.0.0</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
35 changes: 35 additions & 0 deletions src/Lykke.Service.HFT.Contracts/Orders/BulkOrderItemModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.ComponentModel.DataAnnotations;
using JetBrains.Annotations;

namespace Lykke.Service.HFT.Contracts.Orders
{
/// <summary>
/// Order model for bulk limit orders.
/// </summary>
[PublicAPI]
public class BulkOrderItemModel
{
/// <summary>
/// The order action, buy or sell.
/// </summary>
[Required]
public OrderAction OrderAction { get; set; }

/// <summary>
/// The volume of the order.
/// </summary>
[Required]
public double Volume { get; set; }

/// <summary>
/// The price of the order.
/// </summary>
[Required]
public double Price { get; set; }

/// <summary>
/// [Optional] The old order identifier that needs to be replaced with this order.
/// </summary>
public string OldId { get; set; }
}
}
32 changes: 32 additions & 0 deletions src/Lykke.Service.HFT.Contracts/Orders/BulkOrderItemStatusModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using JetBrains.Annotations;

namespace Lykke.Service.HFT.Contracts.Orders
{
/// <summary>
/// Response status model for a specific order in a bulk order.
/// </summary>
[PublicAPI]
public class BulkOrderItemStatusModel
{
/// <summary>
/// The id under which this order was registered. Needed for cancel or status updates.
/// </summary>
public Guid Id { get; set; }

/// <summary>
/// The possible error that occured when placing this order.
/// </summary>
public ErrorCodeType? Error { get; set; }

/// <summary>
/// The volume of this order.
/// </summary>
public double Volume { get; set; }

/// <summary>
/// The price of this order.
/// </summary>
public double Price { get; set; }
}
}
27 changes: 27 additions & 0 deletions src/Lykke.Service.HFT.Contracts/Orders/BulkOrderResponseModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using JetBrains.Annotations;

namespace Lykke.Service.HFT.Contracts.Orders
{
/// <summary>
/// Response model for placing new bulk orders.
/// </summary>
[PublicAPI]
public class BulkOrderResponseModel
{
/// <summary>
/// The asset pair of this bulk order.
/// </summary>
public string AssetPairId { get; set; }

/// <summary>
/// The possible error that occured when processing this bulk order. Check individual statusses for the status per order.
/// </summary>
public ErrorCodeType? Error { get; set; }

/// <summary>
/// The bulk order item statuses.
/// </summary>
public IReadOnlyList<BulkOrderItemStatusModel> Statuses { get; set; }
}
}
31 changes: 31 additions & 0 deletions src/Lykke.Service.HFT.Contracts/Orders/CancelMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using JetBrains.Annotations;

namespace Lykke.Service.HFT.Contracts.Orders
{
/// <summary>
/// CancelMode behavior for bulk orders.
/// </summary>
[PublicAPI]
public enum CancelMode
{
/// <summary>
/// Cancel previous orders as defined in the given parameter.
/// </summary>
NotEmptySide = 0,

/// <summary>
/// Cancel all previous buy- and sell-orders (even if there are no incoming orders)
/// </summary>
BothSides = 1,

/// <summary>
/// Cancel only previous sell-orders(even if there are no incoming sell-orders)
/// </summary>
SellSide = 2,

/// <summary>
/// Cancel only previous buy-orders(even if there are no incoming buy-orders)
/// </summary>
BuySide = 3,
}
}
34 changes: 34 additions & 0 deletions src/Lykke.Service.HFT.Contracts/Orders/PlaceBulkOrderModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using JetBrains.Annotations;

namespace Lykke.Service.HFT.Contracts.Orders
{
/// <summary>
/// Request model for placing bulk limit orders.
/// </summary>
[PublicAPI]
public class PlaceBulkOrderModel
{
/// <summary>
/// The asset pair you want to buy or sell.
/// </summary>
[Required]
public string AssetPairId { get; set; }

/// <summary>
/// Cancel the previous orders of this asset pair.
/// </summary>
public bool CancelPreviousOrders { get; set; }

/// <summary>
/// [Optional] The cancel mode behavior for cancelling previous orders.
/// </summary>
public CancelMode? CancelMode { get; set; }

/// <summary>
/// The orders you want to place.
/// </summary>
public IEnumerable<BulkOrderItemModel> Orders { get; set; }
}
}
3 changes: 1 addition & 2 deletions src/Lykke.Service.HFT.Core/Lykke.Service.HFT.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AssemblyName>Lykke.Service.HFT.Core</AssemblyName>
<RootNamespace>Lykke.Service.HFT.Core</RootNamespace>
<Version>1.0.0</Version>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 5 additions & 3 deletions src/Lykke.Service.HFT.Core/Services/IMatchingEngineAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Lykke.Service.Assets.Client.Models;
using OrderAction = Lykke.Service.HFT.Contracts.Orders.OrderAction;
using Lykke.Service.HFT.Contracts;
using Lykke.Service.HFT.Contracts.Orders;
using OrderAction = Lykke.Service.HFT.Contracts.Orders.OrderAction;

namespace Lykke.Service.HFT.Core.Services
{
public interface IMatchingEngineAdapter
{
Task<ResponseModel> CancelLimitOrderAsync(Guid limitOrderId);
Task<ResponseModel> CancelAllAsync(string clientId, AssetPair pair, bool? isBuy);
Task<ResponseModel<double>> HandleMarketOrderAsync(string clientId, AssetPair assetPair, OrderAction orderAction, double volume, bool straight, double? reservedLimitVolume = default(double?));
Task<ResponseModel<double>> HandleMarketOrderAsync(string clientId, AssetPair assetPair, OrderAction orderAction, double volume, bool straight, double? reservedLimitVolume = default);
Task<ResponseModel<Guid>> PlaceLimitOrderAsync(string clientId, AssetPair assetPair, OrderAction orderAction, double volume, double price, bool cancelPreviousOrders = false);

Task<ResponseModel<BulkOrderResponseModel>> PlaceBulkLimitOrderAsync(string clientId, AssetPair assetPair, IEnumerable<BulkOrderItemModel> items, bool cancelPrevious = false, CancelMode? cancelMode = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AssemblyName>Lykke.Service.HFT.MongoRepositories</AssemblyName>
<RootNamespace>Lykke.Service.HFT.MongoRepositories</RootNamespace>
<Version>1.0.0</Version>
<Version>1.0.0</Version>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AssemblyName>Lykke.Service.HFT.Services</AssemblyName>
<RootNamespace>Lykke.Service.HFT.Services</RootNamespace>
<Version>1.0.0</Version>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
20 changes: 19 additions & 1 deletion src/Lykke.Service.HFT.Services/Mapper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Lykke.Service.HFT.Contracts.Orders;
using MeCancelMode = Lykke.MatchingEngine.Connector.Models.Api.CancelMode;
using MeOrderAction = Lykke.MatchingEngine.Connector.Models.Common.OrderAction;

namespace Lykke.Service.HFT.Services
Expand All @@ -18,10 +19,27 @@ public static MeOrderAction ToMeOrderAction(this OrderAction action)
orderAction = MeOrderAction.Sell;
break;
default:
throw new InvalidOperationException("Unknown order action");
throw new ArgumentException($"Unknown order action: {action}");
}

return orderAction;
}

public static MeCancelMode ToMeCancelModel(this CancelMode cancelMode)
{
switch (cancelMode)
{
case CancelMode.NotEmptySide:
return MeCancelMode.NotEmptySide;
case CancelMode.BothSides:
return MeCancelMode.BothSides;
case CancelMode.SellSide:
return MeCancelMode.SellSide;
case CancelMode.BuySide:
return MeCancelMode.BuySide;
default:
throw new ArgumentException($"Unknown cancel model: {cancelMode}");
}
}
}
}
Loading

0 comments on commit 464f1d3

Please sign in to comment.