-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Huobi.Examples.Api", "Huobi.Examples.Api\Huobi.Examples.Api.csproj", "{ECA139DF-CA98-4E98-89DA-C594FEBC0865}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Huobi.Examples.Console", "Huobi.Examples.Console\Huobi.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="Huobi.Net" Version="5.2.1" /> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Huobi.Net.Interfaces.Clients; | ||
using CryptoExchange.Net.Authentication; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
// Add the Bitget services | ||
builder.Services.AddHuobi(); | ||
|
||
// OR to provide API credentials for accessing private endpoints, or setting other options: | ||
/* | ||
builder.Services.AddHuobi(restOptions => | ||
{ | ||
restOptions.ApiCredentials = new ApiCredentials("<APIKEY>", "<APISECRET>"); | ||
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 Huobi rest client | ||
app.MapGet("/{Symbol}", async ([FromServices] IHuobiRestClient 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] IHuobiRestClient client) => | ||
{ | ||
var account = await client.SpotApi.Account.GetAccountsAsync(); | ||
var result = await client.SpotApi.Account.GetBalancesAsync(account.Data.Single(d => d.Type == Huobi.Net.Enums.AccountType.Spot).Id); | ||
return (object)(result.Success ? result.Data : result.Error!); | ||
}) | ||
.WithOpenApi(); | ||
|
||
app.Run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
14 changes: 14 additions & 0 deletions
14
Examples/Huobi.Examples.Console/Huobi.Examples.Console.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="Huobi.Net" Version="5.2.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Huobi.Net.Clients; | ||
using CryptoExchange.Net.Objects; | ||
using Microsoft.Extensions.Logging; | ||
|
||
// REST | ||
var restClient = new HuobiRestClient(); | ||
var ticker = await restClient.SpotApi.ExchangeData.GetTickerAsync("ETHUSDT"); | ||
Console.WriteLine($"Rest client ticker price for ETH-USDT: {ticker.Data.ClosePrice}"); | ||
|
||
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 HuobiSocketClient(logFactory); | ||
var subscription = await socketClient.SpotApi.SubscribeToTickerUpdatesAsync("ethusdt", update => | ||
{ | ||
Console.WriteLine($"Websocket client ticker price for ETHUSDT: {update.Data.ClosePrice}"); | ||
}); | ||
|
||
Console.ReadLine(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Examples | ||
|
||
### Huobi.Examples.Api | ||
A minimal API showing how to integrate Huobi.Net in a web API project | ||
|
||
### Huobi.Examples.Console | ||
A simple console client demonstrating basic usage |