Comment on page
API Request Samples
To simplify your DIA API integration journey, we created sample API calls for retrieving price data in the most widely used programming languages.
All examples make a call to DIA Asset Quotation API for Bitcoin price.
curl --request GET \
--url https://api.diadata.org/v1/assetQuotation/Bitcoin/0x000000000000000000000000000000000000000 \
--header 'Content-Type: application/json'
http GET https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000 \
Content-Type:application/json
wget --quiet \
--method GET \
--header 'Content-Type: application/json' \
--output-document \
- https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000
fetch("https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000", {
"method": "GET",
"headers": {
"Content-Type": "application/json"
}
})
.then(response => {
console.log(response);
})
.catch(err => {
console.error(err);
});
const data = null;
const xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
const settings = {
"async": true,
"crossDomain": true,
"url": "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000",
"method": "GET",
"headers": {
"Content-Type": "application/json"
}
};
$.ajax(settings).done(function (response) {
console.log(response);
});
import axios from "axios";
const options = {
method: 'GET',
url: 'https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000',
headers: {'Content-Type': 'application/json'}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
const http = require("https");
const options = {
"method": "GET",
"hostname": "api.diadata.org",
"port": null,
"path": "/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000",
"headers": {
"Content-Type": "application/json"
}
};
const req = http.request(options, function (res) {
const chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
const body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.end();
const request = require('request');
const options = {
method: 'GET',
url: 'https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000',
headers: {'Content-Type': 'application/json'}
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
const unirest = require("unirest");
const req = unirest("GET", "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000");
req.headers({
"Content-Type": "application/json"
});
req.end(function (res) {
if (res.error) throw new Error(res.error);
console.log(res.body);
});
const fetch = require('node-fetch');
let url = 'https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000';
let options = {method: 'GET', headers: {'Content-Type': 'application/json'}};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err));
var axios = require("axios").default;
var options = {
method: 'GET',
url: 'https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000',
headers: {'Content-Type': 'application/json'}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
import http.client
conn = http.client.HTTPSConnection("api.diadata.org")
headers = { 'Content-Type': "application/json" }
conn.request("GET", "/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
import requests
url = "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000"
headers = {'Content-Type': 'application/json'}
response = requests.request("GET", url, headers=headers)
print(response.text)
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(hnd, CURLOPT_URL, "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
CURLcode ret = curl_easy_perform(hnd);
#import <Foundation/Foundation.h>
NSDictionary *headers = @{ @"Content-Type": @"application/json" };
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"GET"];
[request setAllHTTPHeaderFields:headers];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSLog(@"%@", httpResponse);
}
}];
[dataTask resume];
open Cohttp_lwt_unix
open Cohttp
open Lwt
let uri = Uri.of_string "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000" in
let headers = Header.add (Header.init ()) "Content-Type" "application/json" in
Client.call ~headers `GET uri
>>= fun (res, body_stream) ->
(* Do stuff with the result *)
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri("https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000"),
Headers =
{
{ "Content-Type", "application/json" },
},
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}
var client = new RestClient("https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000");
var request = new RestRequest(Method.GET);
request.AddHeader("Content-Type", "application/json");
IRestResponse response = client.Execute(request);
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.prepare("GET", "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000")
.setHeader("Content-Type", "application/json")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();
client.close();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000"))
.header("Content-Type", "application/json")
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000")
.get()
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
HttpResponse<String> response = Unirest.get("https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000")
.header("Content-Type", "application/json")
.asString();
<?php
$request = new HttpRequest();
$request->setUrl('https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000');
$request->setMethod(HTTP_METH_GET);
$request->setHeaders([
'Content-Type' => 'application/json'
]);
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
<?php
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl('https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000');
$request->setRequestMethod('GET');
$request->setHeaders([
'Content-Type' => 'application/json'
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
$headers=@{}
$headers.Add("Content-Type", "application/json")
$response = Invoke-WebRequest -Uri 'https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000' -Method GET -Headers $headers
$headers=@{}
$headers.Add("Content-Type", "application/json")
$response = Invoke-RestMethod -Uri 'https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000' -Method GET -Headers $headers
require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(url)
request["Content-Type"] = 'application/json'
response = http.request(request)
puts response.read_body
import Foundation
let headers = ["Content-Type": "application/json"]
let request = NSMutableURLRequest(url: NSURL(string: "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()
Last modified 5mo ago