GateIo.Net
GateIo.Net is a client library for accessing the Gate.io REST and Websocket API.
Features
- Response data is mapped to descriptive models
- Input parameters and response values are mapped to discriptive enum values where possible
- Automatic websocket (re)connection management
- Client side rate limiting
- Cient side order book implementation
- Extensive logging
- Support for different environments
- Easy integration with other exchange client based on the CryptoExchange.Net base library
Supported Frameworks
The library is targeting both .NET Standard 2.0
and .NET Standard 2.1
for optimal compatibility
.NET implementation | Version Support |
---|---|
.NET Core | 2.0 and higher |
.NET Framework | 4.6.1 and higher |
Mono | 5.4 and higher |
Xamarin.iOS | 10.14 and higher |
Xamarin.Android | 8.0 and higher |
UWP | 10.0.16299 and higher |
Unity | 2018.1 and higher |
Discord
A Discord server is available here. Feel free to join for discussion and/or questions around the CryptoExchange.Net and implementation libraries.
Support the project
DonateMake a one time donation in a crypto currency of your choice. If you prefer to donate a currency not listed here please contact me.
Btc: bc1q277a5n54s2l2mzlu778ef7lpkwhjhyvghuv8qf
Eth: 0xcb1b63aCF9fef2755eBf4a0506250074496Ad5b7
USDT (TRX): TKigKeJPXZYyMVDgMyXxMf17MWYia92Rjd
Alternatively, sponsor me on Github using Github Sponsors.
Getting Started
The package is available on Nuget. After installing the package the Gate.io API is available by using the GateIoRestClient
and GateIoSocketClient
.
Installation
Nuget
dotnet add package GateIo.Net
GitHub packages
GateIo.Net is available on GitHub packages. You'll need to add https://nuget.pkg.github.com/JKorf/index.json
as a NuGet package source.
Download release
The NuGet package files are added along side the source with the latest GitHub release which can found here.
API Access
GateIo.Net can be configured using Dotnet dependency injection, after which the clients can be injected into your services. It also correctly configures logging and HttpClient usage.
// Configure options from config file
// see https://github.com/JKorf/CryptoExchange.Net/tree/master/Examples/example-config.json for an example
builder.Services.AddGateIo(builder.Configuration.GetSection("GateIo"));
// OR
builder.Services.AddGateIo(options => {
// Configure options in code
options.ApiCredentials = new ApiCredentials("APIKEY", "APISECRET");
});
The IGateIoRestClient
and IGateIoSocketClient
can then be injected.
Alternatively the rest and socket client can be constructed directly
var restClient = new GateIoRestClient(options => {
// Options can be configured here, for example:
options.ApiCredentials = new ApiCredentials("APIKEY", "APISECRET");
});
var socketClient = new GateIoSocketClient();
For information on the clients, dependency injection, response processing and more see the CryptoExchange.Net documentation.
Examples
Get SymbolsGet a list of supported symbols on Gate.io
var symbolsResult = await gateIoRestClient.SpotApi.ExchangeData.GetSymbolsAsync();
if (!symbolsResult.Success)
{
Console.WriteLine("Failed to retrieve symbols: " + symbolsResult.Error);
return;
}
foreach (var symbol in symbolsResult.Data)
Console.WriteLine(symbol.Name);
Get TickersGet a ticker data (price statistics)
var tickersResult = await gateIoRestClient.SpotApi.ExchangeData.GetTickersAsync();
if (!tickersResult.Success)
{
Console.WriteLine("Failed to retrieve tickers: " + tickersResult.Error);
return;
}
foreach (var ticker in tickersResult.Data)
Console.WriteLine($"{ticker.Symbol}: " + ticker.LastPrice);
Get Spot BalancesGet the balances on the spot account
// Assumes that API credentials are set in the client options / DI configuration
var balanceResult = await gateIoRestClient.SpotApi.Account.GetBalancesAsync();
if (!balanceResult.Success)
{
Console.WriteLine("Failed to retrieve balances: " + balanceResult.Error);
return;
}
foreach (var balance in balanceResult.Data)
Console.WriteLine($"{balance.Asset}: " + balance.Available);
Place orderPlace limit order for buying 0.01 eth at a price of 3000 per eth
// Assumes that API credentials are set in the client options / DI configuration
var orderResult = await gateIoRestClient.SpotApi.Trading.PlaceOrderAsync("ETH_USDT", GateIo.Net.Enums.OrderSide.Buy, GateIo.Net.Enums.NewOrderType.Limit, 0.01m, 3000);
if (!orderResult.Success)
{
Console.WriteLine("Failed to place order: " + orderResult.Error);
return;
}
Console.WriteLine($"Order placed, id: {orderResult.Data.Id}");
Subscribe to book ticker updatesSubscribe to book ticker (best ask/bid) updates for the ETH_USDT symbol
var subscribeResult = await gateIoSocketClient.SpotApi.SubscribeToBookTickerUpdatesAsync("ETH_USDT", update =>
{
Console.WriteLine($"Best ask: {update.Data.BestAskPrice}, best bid: {update.Data.BestBidPrice}");
});
if (!subscribeResult.Success)
{
Console.WriteLine($"Failed to subscribe: {subscribeResult.Error}");
return;
}
Console.WriteLine("Successfully subscribed to book ticker updates");