Reading in other languages: English, Русский.
This is the unofficial .NET client to access the API for Exmo exchange.
The description of API can be found on https://exmo.me/api
This package targets .NET Standard 2.0 (see supporting platforms)
Open the Package Manager Console in Visual Studio, and enter the following command:
PM> Install-Package Exmo
Open a command shell, and enter the following command:
dotnet add package Exmo
Add the following code in the method ConfigureServices
of the class Startup
:
public void ConfigureServices(IServiceCollection services)
{
services.AddExmoApi();
}
Add the following code for the console project:
var serviceProvider = new ServiceCollection()
.AddExmoApi()
.BuildServiceProvider();
var publicApi = serviceProvider.GetRequiredService<IPublicApi>();
var authenticatedApi = serviceProvider.GetRequiredService<IAuthenticatedApi>();
services.AddExmoApi(options => {
options.PublicKey = "*****";
options.SecretKey = "*****";
});
Create the file appsettings.json
in the project folder and add the section Exmo with PublicKey and SecretKey:
{
"Exmo": {
"PublicKey": "*****",
"SecretKey": "*****"
}
}
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
var serviceProvider = new ServiceCollection()
.AddExmoApi()
.Configure<ExmoOptions>(configuration.GetSection("Exmo"))
.BuildServiceProvider();
Use User Secrets if you want to hide PublicKey and SecretKey.
Run the following commands to setup user secrets in the project and to add PublicKey and SecretKey:
dotnet user-secrets init
dotnet user-secrets set "Exmo:PublicKey" "*****"
dotnet user-secrets set "Exmo:SecretKey" "*****"
Then add the following code:
var configuration = new ConfigurationBuilder()
.AddUserSecrets(Assembly.GetExecutingAssembly())
.Build();
var serviceProvider = new ServiceCollection()
.AddExmoApi()
.Configure<ExmoOptions>(configuration.GetSection("Exmo"))
.BuildServiceProvider();
Resolve the IPublicApi
service to access Public API.
Getting the list of deals by currency pairs:
var pairs = new CurrencyPairCollection("BTC_USD", "ETH_USD");
var trades = await publicApi.GetTradesAsync(pairs);
Resolve the IAuthenticatedApi
to access Athenticated API, Wallet API and Excode API.
Getting the list of the user's open orders:
var openOrders = await authenticatedApi.GetOpenOrdersAsync();
The client methods don't return the request status. If the server cannot execute the request, the client method throws the ExmoApiException
instead. The given exception can be thrown by any API method.
Error handling example:
try
{
var request = new CreateOrderRequest
{
Pair = "BTC_USD",
Type = OrderType.Buy,
Quantity = 0.01m,
Price = 9700m
};
var orderId = await authenticatedApi.CreateOrderAsync(request);
}
catch (ExmoApiException ex)
{
Console.WriteLine(ex.Message);
}
Create a class inherited from the class DelegatingHandler to log HTTP requests. See the example here.