diff --git a/Examples/Examples.sln b/Examples/Examples.sln new file mode 100644 index 00000000..a44315be --- /dev/null +++ b/Examples/Examples.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34330.188 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kucoin.Examples.Api", "Kucoin.Examples.Api\Kucoin.Examples.Api.csproj", "{ECA139DF-CA98-4E98-89DA-C594FEBC0865}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kucoin.Examples.Console", "Kucoin.Examples.Console\Kucoin.Examples.Console.csproj", "{FD4F95C8-D9B7-4F81-9245-4CE667DFD421}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {ECA139DF-CA98-4E98-89DA-C594FEBC0865}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ECA139DF-CA98-4E98-89DA-C594FEBC0865}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ECA139DF-CA98-4E98-89DA-C594FEBC0865}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ECA139DF-CA98-4E98-89DA-C594FEBC0865}.Release|Any CPU.Build.0 = Release|Any CPU + {FD4F95C8-D9B7-4F81-9245-4CE667DFD421}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FD4F95C8-D9B7-4F81-9245-4CE667DFD421}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FD4F95C8-D9B7-4F81-9245-4CE667DFD421}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FD4F95C8-D9B7-4F81-9245-4CE667DFD421}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {84A4E6CE-9D3A-43FF-97B1-D91CE93B7E8F} + EndGlobalSection +EndGlobal diff --git a/Examples/Kucoin.Examples.Api/Kucoin.Examples.Api.csproj b/Examples/Kucoin.Examples.Api/Kucoin.Examples.Api.csproj new file mode 100644 index 00000000..2e32e76f --- /dev/null +++ b/Examples/Kucoin.Examples.Api/Kucoin.Examples.Api.csproj @@ -0,0 +1,16 @@ + + + + net7.0 + enable + enable + true + + + + + + + + + diff --git a/Examples/Kucoin.Examples.Api/Program.cs b/Examples/Kucoin.Examples.Api/Program.cs new file mode 100644 index 00000000..fefd2665 --- /dev/null +++ b/Examples/Kucoin.Examples.Api/Program.cs @@ -0,0 +1,47 @@ +using Kucoin.Net.Interfaces.Clients; +using CryptoExchange.Net.Authentication; +using Microsoft.AspNetCore.Mvc; +using Kucoin.Net.Clients; +using Kucoin.Net.Objects; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +// Add the Kucoin services +builder.Services.AddKucoin(); + +// OR to provide API credentials for accessing private endpoints, or setting other options: +/* +builder.Services.AddKucoin(restOptions => +{ + restOptions.ApiCredentials = new KucoinApiCredentials("", "", ""); + restOptions.RequestTimeout = TimeSpan.FromSeconds(5); +}, socketOptions => +{ + socketOptions.ApiCredentials = new KucoinApiCredentials("", "", ""); +}); +*/ + +var app = builder.Build(); +app.UseSwagger(); +app.UseSwaggerUI(); +app.UseHttpsRedirection(); + +// Map the endpoints and inject the Kucoin rest client +app.MapGet("/{Symbol}", async ([FromServices] IKucoinRestClient client, string symbol) => +{ + var result = await client.SpotApi.ExchangeData.GetTickerAsync(symbol); + return (object)(result.Success ? result.Data : result.Error!); +}) +.WithOpenApi(); + +app.MapGet("/Balances", async ([FromServices] IKucoinRestClient client) => +{ + var result = await client.SpotApi.Account.GetAccountsAsync(); + return (object)(result.Success ? result.Data : result.Error!); +}) +.WithOpenApi(); + +app.Run(); \ No newline at end of file diff --git a/Examples/Kucoin.Examples.Api/Properties/launchSettings.json b/Examples/Kucoin.Examples.Api/Properties/launchSettings.json new file mode 100644 index 00000000..066e9d1f --- /dev/null +++ b/Examples/Kucoin.Examples.Api/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:23442", + "sslPort": 44376 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5114", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7266;http://localhost:5114", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Examples/Kucoin.Examples.Api/appsettings.Development.json b/Examples/Kucoin.Examples.Api/appsettings.Development.json new file mode 100644 index 00000000..0c208ae9 --- /dev/null +++ b/Examples/Kucoin.Examples.Api/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Examples/Kucoin.Examples.Api/appsettings.json b/Examples/Kucoin.Examples.Api/appsettings.json new file mode 100644 index 00000000..10f68b8c --- /dev/null +++ b/Examples/Kucoin.Examples.Api/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Examples/Kucoin.Examples.Console/Kucoin.Examples.Console.csproj b/Examples/Kucoin.Examples.Console/Kucoin.Examples.Console.csproj new file mode 100644 index 00000000..4a356a1a --- /dev/null +++ b/Examples/Kucoin.Examples.Console/Kucoin.Examples.Console.csproj @@ -0,0 +1,14 @@ + + + + Exe + net7.0 + enable + enable + + + + + + + diff --git a/Examples/Kucoin.Examples.Console/Program.cs b/Examples/Kucoin.Examples.Console/Program.cs new file mode 100644 index 00000000..f808f880 --- /dev/null +++ b/Examples/Kucoin.Examples.Console/Program.cs @@ -0,0 +1,25 @@ +using Kucoin.Net.Clients; +using CryptoExchange.Net.Objects; +using Microsoft.Extensions.Logging; + +// REST +var restClient = new KucoinRestClient(); +var ticker = await restClient.SpotApi.ExchangeData.GetTickerAsync("ETH-USDT"); +Console.WriteLine($"Rest client ticker price for ETH-USDT: {ticker.Data.LastPrice}"); + +Console.WriteLine(); +Console.WriteLine("Press enter to start websocket subscription"); +Console.ReadLine(); + +// Websocket +// Optional, manually add logging +var logFactory = new LoggerFactory(); +logFactory.AddProvider(new TraceLoggerProvider()); + +var socketClient = new KucoinSocketClient(logFactory); +var subscription = await socketClient.SpotApi.SubscribeToTickerUpdatesAsync("ETH-USDT", update => +{ + Console.WriteLine($"Websocket client ticker price for ETHUSDT: {update.Data.LastPrice}"); +}); + +Console.ReadLine(); diff --git a/Examples/README.md b/Examples/README.md new file mode 100644 index 00000000..c57a10e8 --- /dev/null +++ b/Examples/README.md @@ -0,0 +1,7 @@ +# Examples + +### Kucoin.Examples.Api +A minimal API showing how to integrate Kucoin.Net in a web API project + +### Kucoin.Examples.Console +A simple console client demonstrating basic usage \ No newline at end of file