Skip to content

Commit

Permalink
Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Mar 27, 2024
1 parent 6039b19 commit 6c9bf91
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 5 deletions.
5 changes: 0 additions & 5 deletions CoinGecko.Net/CoinGecko.Net.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Examples/CoinGecko.Examples.Api/CoinGecko.Examples.Api.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CoinGecko.Net" Version="2.2.1" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.17" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

</Project>
37 changes: 37 additions & 0 deletions Examples/CoinGecko.Examples.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using CoinGecko.Net.Interfaces;
using CryptoExchange.Net.Authentication;
using Microsoft.AspNetCore.Mvc;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

// Add the CoinGecko services
builder.Services.AddCoinGecko();

// OR to provide options:
/*
builder.Services.AddCoinGecko(restOptions =>
{
restOptions.RequestTimeout = TimeSpan.FromSeconds(5);
}, socketOptions =>
{
socketOptions.ApiCredentials = new ApiCredentials("<APIKEY>", "<APISECRET>");
});
*/

var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();

// Map the endpoints and inject the CoinGecko rest client
app.MapGet("/{asset}", async ([FromServices] ICoinGeckoRestClient client, string asset) =>
{
var result = await client.Api.GetMarketsAsync(asset);
return (object)(result.Success ? result.Data : result.Error!);
})
.WithOpenApi();

app.Run();
41 changes: 41 additions & 0 deletions Examples/CoinGecko.Examples.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
8 changes: 8 additions & 0 deletions Examples/CoinGecko.Examples.Api/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions Examples/CoinGecko.Examples.Api/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CoinGecko.Net" Version="2.2.1" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions Examples/CoinGecko.Examples.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

using CoinGecko.Net.Clients;

// REST
var restClient = new CoinGeckoRestClient();
var markets = await restClient.Api.GetMarketsAsync("usd");
var ethMarket = markets.Data.Single(d => d.Name == "Ethereum");
Console.WriteLine($"Rest client ticker price for ETHUSDT: {ethMarket.CurrentPrice}");

Console.ReadLine();
31 changes: 31 additions & 0 deletions Examples/Examples.sln
Original file line number Diff line number Diff line change
@@ -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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoinGecko.Examples.Console", "CoinGecko.Examples.Console\CoinGecko.Examples.Console.csproj", "{72F29164-3C3E-4EB1-9C2B-BC9BA5FCD5AA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoinGecko.Examples.Api", "CoinGecko.Examples.Api\CoinGecko.Examples.Api.csproj", "{2E6BB5F7-6F04-4122-8CB6-6B89E822040A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{72F29164-3C3E-4EB1-9C2B-BC9BA5FCD5AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72F29164-3C3E-4EB1-9C2B-BC9BA5FCD5AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72F29164-3C3E-4EB1-9C2B-BC9BA5FCD5AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72F29164-3C3E-4EB1-9C2B-BC9BA5FCD5AA}.Release|Any CPU.Build.0 = Release|Any CPU
{2E6BB5F7-6F04-4122-8CB6-6B89E822040A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E6BB5F7-6F04-4122-8CB6-6B89E822040A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E6BB5F7-6F04-4122-8CB6-6B89E822040A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E6BB5F7-6F04-4122-8CB6-6B89E822040A}.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
7 changes: 7 additions & 0 deletions Examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Examples

### CoinGecko.Examples.Api
A minimal API showing how to integrate CoinGecko.Net in a web API project

### CoinGecko.Examples.Console
A simple console client demonstrating basic usage

0 comments on commit 6c9bf91

Please sign in to comment.