BtcTurkApiCore 8.1.0
See the version list below for details.
dotnet add package BtcTurkApiCore --version 8.1.0
NuGet\Install-Package BtcTurkApiCore -Version 8.1.0
<PackageReference Include="BtcTurkApiCore" Version="8.1.0" />
paket add BtcTurkApiCore --version 8.1.0
#r "nuget: BtcTurkApiCore, 8.1.0"
// Install BtcTurkApiCore as a Cake Addin #addin nuget:?package=BtcTurkApiCore&version=8.1.0 // Install BtcTurkApiCore as a Cake Tool #tool nuget:?package=BtcTurkApiCore&version=8.1.0
API and Websocket structure for BtcTurk API
<br /> <img width="25" align="left" alt="BtcTurk API Core" src="https://play-lh.googleusercontent.com/Oro51LB-uI56qErIMkUk4hO9ubB7O924ZiC7nSNyMyNeWmpxCvcXTFlEG6MbZTTMMpY" /> <br /><br />
<h2>Built With</h2>
Please open issues for your questions or bug reports.
Examples
Firstly, you need to inject the BtcTurkApiCore library into your application. When injecting, you will be required to configure your PublicKey and PrivateKey.
builder.Services.AddBtcTurkApiCore(conf =>
{
conf.PublicKey = "YOUR_PUBLIC_KEY";
conf.PrivateKey = "YOUR_PRIVATE_KEY";
});
Once the setup is complete, you can start utilizing the library in your integration.
Below are some examples you can use in your integration with the library.
Samples.cs
public Samples(
IBtcTurkApiCore btcTurkApiCore,
IBtcTurkPublicWebSocketClient btcTurkPublicWebSocketClient,
IBtcTurkPrivateWebSocketClient btcTurkPrivateWebSocketClient)
{
_btcTurkApiCore = btcTurkApiCore;
_btcTurkPublicWebSocketClient = btcTurkPublicWebSocketClient;
_btcTurkPrivateWebSocketClient = btcTurkPrivateWebSocketClient;
//OPTIONAL
//Public WebSocket Events. These events are triggered when the data is received from the socket.
_btcTurkPublicWebSocketClient.OnOrderBook += OnOrderBook;
_btcTurkPublicWebSocketClient.OnTickerAll += OnTickerAll;
_btcTurkPublicWebSocketClient.OnTickerPair += OnTickerPair;
_btcTurkPublicWebSocketClient.OnTradeSingle += OnTradeSingle;
_btcTurkPublicWebSocketClient.OnError += OnError;
//OPTINAL
//Private WebSocket Events These events are triggered when the data is received from the socket.
_btcTurkPrivateWebSocketClient.OnOrderInserted += OnOrderInserted;
_btcTurkPrivateWebSocketClient.OnOrderMatched += OnOrderMatched;
_btcTurkPrivateWebSocketClient.OnOrderDeleted += OnOrderDeleted;
_btcTurkPrivateWebSocketClient.OnUserTrade += OnUserTrade;
_btcTurkPrivateWebSocketClient.OnError += OnError;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
try
{
// Connect to private websocket
await _btcTurkPrivateWebSocketClient.StartSocketClientAsync(new BtcTurkWebSocketOptions()
{
PublicKey = "YOUR_PUBLIC_KEY",
PrivateKey = "YOUR_PRIVATE_KEY",
AutoReconnect = true,
ReceiveMessageBuffer = 1024 * 1024
}, stoppingToken);
// Connect to public websocket
await _btcTurkPublicWebSocketClient.StartSocketClientAsync(stoppingToken);
//Send subscription request to socket
await _btcTurkPublicWebSocketClient.SendSubscriptionRequest(Channels.TickerAll, "all");
await _btcTurkPublicWebSocketClient.SendSubscriptionRequest(Channels.TickerPair, "BTCUSDT");
await _btcTurkPublicWebSocketClient.SendSubscriptionRequest(Channels.OrderBook, "BTCUSDT");
await _btcTurkPublicWebSocketClient.SendSubscriptionRequest(Channels.TradeSingle, "BTCUSDT");
// Send request to api
OrderBook orderBook = await _btcTurkApiCore.GetOrderBookAsync("BTCTRY", 10);
Ticker tickers = await _btcTurkApiCore.GetTickersAsync();
ExchangeInfo exchangeInfo = await _btcTurkApiCore.GetExchangeInfoAsync();
Trade trades = await _btcTurkApiCore.GetTradesAsync("BTCTRY");
// Create order
CreateOrderResponse createOrderResponse = await _btcTurkApiCore.CreateOrderRequestAsync(new CreateOrderRequest()
{
Quantity = "0.001",
Price = "2000000",
OrderMethod = OrderMethod.Limit,
OrderType = OrderType.Buy,
PairSymbol = "BTCTRY",
NewOrderClientId = "BtcTurkApiCore"
});
// Cancel order
CancelOrderResponse? cancelOrderResponse = await _btcTurkApiCore.CancelOrderRequestAsync(createOrderResponse.Data.Id.ToString());
}
catch (Exception e)
{
await _btcTurkPrivateWebSocketClient.StopSocketClientAsync();
await _btcTurkPublicWebSocketClient.StopSocketClientAsync();
Console.WriteLine(e.Message);
throw;
}
}
private void OnUserTrade(UserTrade obj)
{
Console.WriteLine(JsonConvert.SerializeObject(obj));
}
private void OnOrderDeleted(OrderDeleted obj)
{
Console.WriteLine(JsonConvert.SerializeObject(obj));
}
private void OnOrderMatched(OrderMatched obj)
{
Console.WriteLine(JsonConvert.SerializeObject(obj));
}
private void OnOrderInserted(OrderInserted obj)
{
Console.WriteLine(JsonConvert.SerializeObject(obj));
}
private void OnTickerPair(TickerPair obj)
{
Console.WriteLine(JsonConvert.SerializeObject(obj));
}
private void OnTradeSingle(TradeSingle obj)
{
Console.WriteLine(JsonConvert.SerializeObject(obj));
}
private void OnTickerAll(TickerAll obj)
{
Console.WriteLine(JsonConvert.SerializeObject(obj));
}
private void OnOrderBook(OrderBookFull obj)
{
Console.WriteLine(JsonConvert.SerializeObject(obj));
}
private void OnError(Exception obj)
{
Console.WriteLine(JsonConvert.SerializeObject(obj));
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.