Ethereum: Binance API - Get Klines for XXX/GBP only - Cloture & Carrelage

Ciri Blog

Netus et malesuada fames ac turpis egestas integer diam quam nulla porttitor massa amet purus gravida quis blandit.

Ethereum: Binance API – Get Klines for XXX/GBP only

Etherum Clines API: Current Bitcoin/ETH Prices

Binance Clines API is a powerful tool for market information, and in this article we will be the currt (BTC) and ethere.

Prerequisites

Before yu start, make yours you has been on the following:

  • Binance API account

2.

Code

`php

// Set your API credentials and binance clines API destination

$ URL = '

$ Apikey = Your_API_KEY_HERE; // Replant wth your actual API key

$ episecret = youur_api_secret_here; // Replant wth your actual API secret

// Set the asset you want to get past prices (in this case, BTC/ETH)

$Asset = 'BTC/ETH';

// Define the time range you want to get prices (eg 1 day to date)

$ startdate = '2023-02-20'; // Replac that desired start date

$ enddate = '2023-03-01'; // Replac that desired end date

// Set the frequency of Data obtaining (in this case 1 minute intervals)

$ frequency = '1m';

// Define all possable additional parameters (eg limit to get on it on the price per asset)

$ params = array (

'Symbol' => $ Asset,

'Interval' => $ frequency,

'Starttime' => $ startdate,

'Endtime' => $ enddate

);

// authenticate with API Using yours

$ header = array ('Authorization: Binance-Key', 'Accept: Application/JSON');

$ Ch = Curl_init ($ URL. '?'. http_build_query ($ params). '&'

Curl_Setopt ($ Ch, Curlop_httpheader, $ header);

Curl_Setopt ($ Ch, Curlop_returntransfer, True);

// Follow the API call and recover the answer

$ reply = Curl_exec ($ Ch);

$ STATUSCODE = Curl_getInfo ($ Ch, Curlinfo_http_code);

IF ($ STATUSCODE == 200) {

// parse JSON's rection toin the necessary data

$ data = json_decode ($ answer, True);

// Use price information about yours (BTC/ETH)

$ price is Set = Array_filter ($ data [$ asset]);

IF (! Empty ($price)) {

Echo "current prices for $asset:";

Foreach ($ price is USD value) {

Echo "$ value [1] ($ value [2]) \ n";

}

} else {

Echo "No Data for $asset \ n";

}

} else {

Echo "Error Getting Data ($ STATUSCODE) \ N";

}

?

Explanation

This fragment of code shows how to access Binance Clins API to get the current Bitcoin (BTC) and Etherum (ETH) prices. Gere are tep by tep:

  • Set the API credentials (`Apikey and ‘ApisECret’) as environmental variables or file.

  • Define the asset you want, in this case BTC/ETH prices.

  • Specify the Start and end dates you want to get past (for example, 1 day to date).

  • Set the frequency of Data obtaining at 1 minute interval.

  • Define all theaditional parameters required, for example by limiting

Note

Ethereum: Binance API - Get Klines for XXX/GBP only

: This fragment of code assumes that bienance API suppors multiple assets and time ranges at the same time. If this is not the case, you will need to change the mass « Params » according.

When performing thees, you chand is abtaine current for the desired asset as the Binance Clins API.

Role Role Cryptocurrency

Related Posts

Laisser un commentaire

author

Devon Lane

Categories
Archive
Follow us