Code examples
The same request in twelve languages, ready to copy and run. On JavaScript or TypeScript, the open-source client covers REST and WebSocket in one package.
Last updated:
JavaScript / TypeScript client
On JavaScript or TypeScript, the open-source harem-altin-api client handles REST and WebSocket for you. npm · View on GitHub
harem-altin-api
// npm install harem-altin-api
import { createClient } from "harem-altin-api";
const client = createClient({ apiKey: process.env.PIXCHARP_API_KEY });
const has = await client.getPrice("HAS");
console.log(has.symbol, has.alis, has.satis);REST request samples
A GET /v1/prices/HAS call for one symbol's price, in twelve languages. Keep the key in the PIXCHARP_API_KEY environment variable instead of in your code.
curl https://api.pixcharp.com/v1/prices/HAS \
-H "X-API-Key: $PIXCHARP_API_KEY"// Node.js 18+, Deno, Bun
const response = await fetch("https://api.pixcharp.com/v1/prices/HAS", {
headers: { "X-API-Key": process.env.PIXCHARP_API_KEY },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const price = await response.json();
console.log(price.symbol, price.alis, price.satis);# Install: pip install requests
import os
import requests
response = requests.get(
"https://api.pixcharp.com/v1/prices/HAS",
headers={"X-API-Key": os.environ["PIXCHARP_API_KEY"]},
timeout=10,
)
response.raise_for_status()
price = response.json()
print(price["symbol"], price["alis"], price["satis"])<?php
$client = curl_init("https://api.pixcharp.com/v1/prices/HAS");
curl_setopt_array($client, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["X-API-Key: " . getenv("PIXCHARP_API_KEY")],
CURLOPT_TIMEOUT => 10,
]);
$price = json_decode(curl_exec($client), true);
curl_close($client);
echo $price["symbol"], " ", $price["alis"], " ", $price["satis"], PHP_EOL;package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
)
type Price struct {
Symbol string `json:"symbol"`
Alis float64 `json:"alis"`
Satis float64 `json:"satis"`
AsOfUtc string `json:"asOfUtc"`
Stale bool `json:"stale"`
}
func main() {
req, _ := http.NewRequest(http.MethodGet, "https://api.pixcharp.com/v1/prices/HAS", nil)
req.Header.Set("X-API-Key", os.Getenv("PIXCHARP_API_KEY"))
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
var price Price
if err := json.NewDecoder(res.Body).Decode(&price); err != nil {
panic(err)
}
fmt.Println(price.Symbol, price.Alis, price.Satis)
}// Java 11+
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.pixcharp.com/v1/prices/HAS"))
.header("X-API-Key", System.getenv("PIXCHARP_API_KEY"))
.GET()
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}// .NET 6+
using System.Net.Http.Json;
using var http = new HttpClient { BaseAddress = new Uri("https://api.pixcharp.com") };
http.DefaultRequestHeaders.Add("X-API-Key", Environment.GetEnvironmentVariable("PIXCHARP_API_KEY"));
var price = await http.GetFromJsonAsync<Price>("/v1/prices/HAS");
Console.WriteLine($"{price!.Symbol} {price.Alis} {price.Satis}");
record Price(string Symbol, decimal Alis, decimal Satis, DateTime AsOfUtc, bool Stale);require "net/http"
require "json"
uri = URI("https://api.pixcharp.com/v1/prices/HAS")
request = Net::HTTP::Get.new(uri)
request["X-API-Key"] = ENV.fetch("PIXCHARP_API_KEY")
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) }
price = JSON.parse(response.body)
puts "#{price["symbol"]} #{price["alis"]} #{price["satis"]}"// Cargo.toml: reqwest = { version = "0.12", features = ["json"] }, serde_json = "1",
// tokio = { version = "1", features = ["full"] }
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let price: serde_json::Value = reqwest::Client::new()
.get("https://api.pixcharp.com/v1/prices/HAS")
.header("X-API-Key", std::env::var("PIXCHARP_API_KEY")?)
.send()
.await?
.error_for_status()?
.json()
.await?;
println!("{} {} {}", price["symbol"], price["alis"], price["satis"]);
Ok(())
}// Do not ship the key inside an app bundle; make this call from your own server.
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
fun main() {
val request = HttpRequest.newBuilder(URI("https://api.pixcharp.com/v1/prices/HAS"))
.header("X-API-Key", System.getenv("PIXCHARP_API_KEY"))
.build()
val response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString())
println(response.body())
}// Do not ship the key inside an app bundle; make this call from your own server.
import Foundation
struct Price: Decodable {
let symbol: String
let alis: Double
let satis: Double
}
var request = URLRequest(url: URL(string: "https://api.pixcharp.com/v1/prices/HAS")!)
request.setValue(ProcessInfo.processInfo.environment["PIXCHARP_API_KEY"], forHTTPHeaderField: "X-API-Key")
let (data, _) = try await URLSession.shared.data(for: request)
let price = try JSONDecoder().decode(Price.self, from: data)
print(price.symbol, price.alis, price.satis)// Do not ship the key inside an app bundle; make this call from your own server.
// Install: dart pub add http
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
Future<void> main() async {
final response = await http.get(
Uri.parse('https://api.pixcharp.com/v1/prices/HAS'),
headers: {'X-API-Key': Platform.environment['PIXCHARP_API_KEY']!},
);
final price = jsonDecode(response.body) as Map<String, dynamic>;
print('${price['symbol']} ${price['alis']} ${price['satis']}');
}WebSocket samples in the same languages are on the WebSocket stream page.