Skip to content

Commit

Permalink
feat: re-use same order
Browse files Browse the repository at this point in the history
  • Loading branch information
CumpsD committed Sep 20, 2024
1 parent 81faa98 commit 777f5ca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
14 changes: 10 additions & 4 deletions chainflip-lp/Model/OrderManager/PlaceBuyOrders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ namespace ChainflipLp.Model
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Mime;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ChainflipLp.Configuration;
using ChainflipLp.Infrastructure;
using ChainflipLp.RpcModel;
using Microsoft.Extensions.Logging;
using Telegram.Bot;
using xxHashSharp;

public partial class OrderManager
{
Expand All @@ -21,7 +23,7 @@ public partial class OrderManager
{
"jsonrpc": "2.0",
"id": 1,
"method": "lp_set_limit_order",
"method": "lp_update_limit_order",
"params": {
"base_asset": { "chain": "REPLACE_CHAIN", "asset": "REPLACE_ASSET" },
"quote_asset": { "chain": "Ethereum", "asset": "USDC" },
Expand Down Expand Up @@ -110,7 +112,7 @@ private async Task PlaceBuyOrder(
var query = BuyOrderQuery
.Replace("REPLACE_CHAIN", pool.Chain)
.Replace("REPLACE_ASSET", pool.Asset)
.Replace("REPLACE_ID", GenerateRandomId())
.Replace("REPLACE_ID", GenerateAssetId(pool.Chain, pool.Asset, "buy"))
.Replace("REPLACE_AMOUNT", balance)
.Replace("REPLACE_BUY_TICK", pool.MaxBuyTick.Value.ToString());

Expand Down Expand Up @@ -139,7 +141,11 @@ await response.Content.ReadAsStringAsync(cancellationToken),
query);
}

private static string GenerateRandomId()
=> Random.Shared.NextInt64().ToString("X");
private static string GenerateAssetId(string chain, string asset, string side)
{
var id = $"{asset.ToLower()}-{chain.ToLower()}-{side.ToLower()}";
var hashValue = xxHash.CalculateHash(Encoding.UTF8.GetBytes(id));
return hashValue.ToString("x8");
}
}
}
4 changes: 2 additions & 2 deletions chainflip-lp/Model/OrderManager/PlaceSellOrders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class OrderManager
{
"jsonrpc": "2.0",
"id": 1,
"method": "lp_set_limit_order",
"method": "lp_update_limit_order",
"params": {
"base_asset": { "chain": "REPLACE_CHAIN", "asset": "REPLACE_ASSET" },
"quote_asset": { "chain": "Ethereum", "asset": "USDC" },
Expand Down Expand Up @@ -83,7 +83,7 @@ private async Task PlaceSellOrder(
var query = SellOrderQuery
.Replace("REPLACE_CHAIN", pool.Chain)
.Replace("REPLACE_ASSET", pool.Asset)
.Replace("REPLACE_ID", GenerateRandomId())
.Replace("REPLACE_ID", GenerateAssetId(pool.Chain, pool.Asset, "sell"))
.Replace("REPLACE_AMOUNT", balance)
.Replace("REPLACE_SELL_TICK", pool.MaxSellTick.Value.ToString());

Expand Down
1 change: 1 addition & 0 deletions chainflip-lp/chainflip-lp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Telegram.Bot" Version="20.0.0-alpha.3" />
<PackageReference Include="xxHashSharp" Version="1.0.0" />
</ItemGroup>
</Project>

0 comments on commit 777f5ca

Please sign in to comment.