Ethereum: C# library Binance.NET: get current average coin price

Here’s an article containing code examples and explanations for picking up the current coin price using the Binance.net library in C#:

Applying for the current average coin price of binance.net

The Binance.net Library provides a convenient way to interact with the Binance application interface, allowing you to use different financial markets and information. One of the most important features of this library is its support for the current prices of the various assets, including the retrieval of encryption currencies.

In this article, we focus on finding the current average Bitcoin price using C#.

Prerequisites

Before continuing, make sure you have installed the Binance.net library and correctly determined it. To install it via NUGET Package Manager or by completing your next command of your end:

`Bash

Dotnet Add Package Binance.net

`

In addition, you need to create an account for Binance.com and get an application connector.

Code Example

Here is a simple C

code example indicating how the current average Bitcoin price is picked up at the Binance.net library:

`Csharp

use of the system;

using system.net.http;

Using System.threading.Tasks;

Name mode binance.netxample

{

class

{

Static Async task Main (string [] Args)

{

// Set API key and exchange ID

Const String Mirikey = “Your_API_KEY”;

Const String Exchangeid = “Binance”;

// Create a new HTTPCLIET expression

Using var client = new httpclient ();

try

{

// Search for the current average Bitcoin price

Var reply = wait customer.getasync ($ “

// check to see if the request is successful

If (Response.isuccessstatusCode)

{

VAR DATA = Wait for response.Content.Readstringync ();

VAR mean = calculateevergeprice (data);

Console.writeline ($ “Current Average Bitcoin Price: {Average} BTC”);

}

}

Catch (exception ex)

{

Console.Writeline ($ “Error: {ex.message}”);

}

// to clean up

Client.dispose ();

}

Static Double CalculateAvergePrice (string information)

{

Var lines = data.split (‘\ n’);

If (lines.the length <1) Return 0;

VAR average = 0.0;

var sum = 0.0;

Foreach (VAR -row lines)

{

Var parts = line.prit (‘,’);

if (parts length> = 9 && int.tryparers (parts [8], out var prices)))

{

mean += price;

sum += price * flot.parers (parts [8]);

}

}

Return Average / Sum> 0? mean: 0;

}

}

}

`

Explanation

Ethereum: C# library Binance.NET: get current average coin price

The code above is looking for the current average Bitcoin price by making a request to the Binance API “Klinesterminal.

In order to calculate the average price, I itee through each line of data and pick up price values ​​for each row. Then we increase these prices and share an estimate of the average price of the lines.

Note that if there are less than 100 lines at a qualified price, "CalculateAvergePrice method returns 0 due to the distribution of zero.

tips and variations

  • You can customize the “symbol”, “interval” and “limit” parameters as needed, as needed.
上部へスクロール