BtcTurkApiCore 8.1.1

dotnet add package BtcTurkApiCore --version 8.1.1                
NuGet\Install-Package BtcTurkApiCore -Version 8.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BtcTurkApiCore" Version="8.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BtcTurkApiCore --version 8.1.1                
#r "nuget: BtcTurkApiCore, 8.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install BtcTurkApiCore as a Cake Addin
#addin nuget:?package=BtcTurkApiCore&version=8.1.1

// Install BtcTurkApiCore as a Cake Tool
#tool nuget:?package=BtcTurkApiCore&version=8.1.1                

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 />

GitHub stars GitHub forks

<h2>Built With</h2>

.NET 8

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.1.1 108 4/2/2024
8.1.0 105 3/28/2024
7.1.0 140 3/28/2024
6.1.0 119 3/28/2024