Skip to main content
CRYPTOCURRENCY

Ethereum: Binanace get Order Book in C# .Net Core

By February 9, 2025No Comments

Ethereum: Building a binary order book in C

.NET Core

As part of our MarketMaker team, we need a stable solution to extract Binance cryptocurrency market without API keys. In this article, we will study how to achieve this with the help of C

.NET Core.

Requirements

Before you immerse yourself in performance, let us outline the requirements:

  • Data on the public market

  • Depth of the order market at specific price levels

Step 1: Set a new .NET Core Project

Create a new .NET Core Project using DOTNET CLI:

`bash

Dotnet New Console -o BinanceMarketdata

Step 2: Install the required libraries

Ethereum: Binanace get Order Book in C# .Net Core

Install the following packages Nuget:

  • Microsoft.extensions.Dependencyenjection to inject addiction

  • Newtonsoft.json for serialization and deciring of JSON

Add the following to your file Startup.cs:

`csharp

Use of Microsoft.aspnetcore.builder;

Use of Microsoft.extensions.Dependency;

Names BinanceMarketdata names

{

Starting a public class

{

Public Void ConfigureServices (IserviceCollection Services)

{

Services.AdControllers ();

Services.Addjsonserialization ();

}

Public Void Configure

{

App.userouting ();

App.useendpoints (endpoints =>

{

endpoints.mapControllers ();

});

}

}

}

Step 3: Create a Market Data Extract Service

Create a new file Marketdataserice.cs:

`csharp

use of a system;

Use of System.Collections.Generic;

Use of microsoft.aspnetcore.http;

using binance.netapi.client;

Names BinanceMarketdata.Services

{

Marketdataservice of the public class

{

Private Readonly HttpClient _HttpClient;

Public Marketdataserice ()

{

_httpclient = new httpClient ();

}

A public task for asynchronization GetPublicMarketdataync ()

{

// Set the endpoint and parameters of API

Var apiendpoint = "

VAR Parameters = New Dictionary

{

{"Symbol", "ETH/BTC"}, // Replace with the desired symbol

{"Limit", "10"} // Number of market records of return data

};

// Make an API request and analyze JSON Answer

Var Marketdata = waiting _httpclient.getasync (apiendpoint, parameters) .Result;

Marketdata.nsuresuccessstatuscode ();

Var Jsondata = Wait a new StreamReader (Marketdata.Content.Radasstringasync ()). Readtoendasync ();

Var Marketdaobject = Jsonconvert.Deserizeobject (JSONDATA);

Return Marketdataobject;

}

Public Asinchioski Asinchook> Getorderbookasync (String symbol, int depth)

{

// Set the endpoint and parameters of API

Var apiendpoint = "

VAR Parameters = New Dictionary

{

{"symbol", symbol}, // Replace with the desired symbol

{"Limit", Depth.Tostring ()} // Number of Order Book Records to return

};

// Make an API request and analyze JSON Answer

Var Orderbook = Wait _httpClient.getasync (apiendpoint, parameters) .Result;

Orderbook.ensuresccessstatuscode ();

Var Jsondata = Wait a new streamReader (Orderbook.Content.Radasstringasync ()). Readtoendasync ();

Var Orderbookobject = Jsonconvert.Deserizeobject (JSONDATA);

Return of order order;

}

}

}

Step 4: Register the service in DI container

Add the following to your startup.

Exchange Fundamental Currency

Leave a Reply