Lykke Trading API documentation: https://lykkecity.github.io/Trading-API/
To build client library in dotnet core 3
need to add .proto files into the project and configure autogeneration for gRPC.
Details you can see here: TradingApi.Client
In class TradingApiClient you can see how to create gRPC channel with api key. And create a PublicApi client and a PrivateApi client.
source code:Example.FollowPrices
Create a client. You can skip the API key because you need just public API.
var client = new TradingApiClient("https://hft-apiv2-grpc.lykke.com", "");
Get prices snapshot
var priceRequest = new PricesRequest();
// for example add filter by 3 instrument. You can keep AssetPairIds empty to receive all prices
priceRequest.AssetPairIds.Add("BTCUSD");
priceRequest.AssetPairIds.Add("BTCCHF");
priceRequest.AssetPairIds.Add("BTCEUR");
var prices = await client.PublicApi.GetPricesAsync(priceRequest);
if (prices.error == null)
{
foreach(var price in prices.Payload)
{
Console.WriteLine($"{price.AssetPairId}: Ask={price.Ask}; Bid={price.Bid}; Time={price.Timestamp}");
}
}
else
{
Console.WriteLine($"ERROR: {prices.error.Code}: {prices.error.Message}");
}
Subscribe to price stream
var priceUpdateRequest = new PriceUpdatesRequest();
priceUpdateRequest.AssetPairIds.Add("BTCUSD");
priceUpdateRequest.AssetPairIds.Add("BTCCHF");
priceUpdateRequest.AssetPairIds.Add("BTCEUR");
Console.WriteLine("Subscribe to prices.");
var priceStream = client.PublicApi.GetPriceUpdates(priceUpdateRequest);
var token = new CancellationToken();
while (await priceStream.ResponseStream.MoveNext(token))
{
var price = priceStream.ResponseStream.Current;
Console.WriteLine($"{price.AssetPairId}: Ask={price.Ask}; Bid={price.Bid}; Time={price.Timestamp}");
}
In this example, you can see how to work simple trading bot. The idea of bot - provide liquidity to several sell levels and several buy levels. If an order is matched then trading bot should create a new order to compensate previous. A new order created with spread = Delta. In this case, if the market goes up and down then trading boot makes a Profit from each level = LevelVolume * Delta
.
We need to:
- Create a Limit Order
- Cancel Limit Order
- Get Limit Order status
- Subscribe to trade stream by account
Implementation of trading boot you can see here: SimpleLP