### Make a POST request using Python Requests Source: https://livecoinwatch.github.io/lcw-api-docs All the examples are written using Python Requests. Install the library and import it along with the json library. Note that you don't have to install the json library, only import it. ```python import requests import json url = "https://api.livecoinwatch.com" payload={} headers = { 'content-type': 'application/json' } response = requests.request("POST", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### Make a POST request using Swift URLSession Source: https://livecoinwatch.github.io/lcw-api-docs All the examples use URLRequest and URLSession. Examples work without installing any package! Just change the `` to your key, and that's it!. ```swift import Foundation #if canImport(FoundationNetworking) import FoundationNetworking #endif var semaphore = DispatchSemaphore (value: 0) var request = URLRequest(url: URL(string: "https://api.livecoinwatch.com")!,timeoutInterval: Double.infinity) request.addValue("application/json", forHTTPHeaderField: "content-type") request.httpMethod = "POST" let task = URLSession.shared.dataTask(with: request) { data, response, error in guard let data = data else { print(String(describing: error)) semaphore.signal() return } print(String(data: data, encoding: .utf8)!) semaphore.signal() } task.resume() semaphore.wait() ``` -------------------------------- ### C# Example Source: https://livecoinwatch.github.io/lcw-api-docs This C# example uses the RestSharp library to execute a POST request to the Live Coin Watch API. Instructions for installing the package are provided. ```APIDOC ## C# All the examples are written using the RestSharp. Install the package and add it to your code. Everything is explained in their documentation. ```csharp var client = new RestClient("https://api.livecoinwatch.com"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("content-type", "application/json"); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` ``` -------------------------------- ### Python Example Source: https://livecoinwatch.github.io/lcw-api-docs This Python example utilizes the Requests library to send a POST request to the Live Coin Watch API. It includes instructions for installation and usage. ```APIDOC ## Python All the examples are written using Python Requests. Install the library and import it along with the json library. Note that you don't have to install the json library, only import it. If you prefer a wrapped up library approach, you may try this one, written by one of our team members. ```python import requests import json url = "https://api.livecoinwatch.com" payload={} headers = { 'content-type': 'application/json' } response = requests.request("POST", url, headers=headers, data=payload) print(response.text) ``` ``` -------------------------------- ### Get Overview Data with Go Source: https://livecoinwatch.github.io/lcw-api-docs Retrieve aggregated market data using Go's standard http package. This example demonstrates setting headers and sending a JSON payload. ```go package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://api.livecoinwatch.com/overview" method := "POST" payload := strings.NewReader(`{ "currency": "USD" }`) client := &http.Client { } req, err := http.NewRequest(method, url, payload) if err != nil { fmt.Println(err) return } req.Header.Add("content-type", "application/json") req.Header.Add("x-api-key", "") res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Get API Credits - C# (RestSharp) Source: https://livecoinwatch.github.io/lcw-api-docs This C# example uses RestSharp to get your API credits. Update `` with your key. ```csharp var client = new RestClient("https://api.livecoinwatch.com/credits"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("content-type", "application/json"); request.AddHeader("x-api-key", ""); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` -------------------------------- ### Get Overview Data with Swift Source: https://livecoinwatch.github.io/lcw-api-docs Retrieve aggregated market data using Swift's URLSession. This example includes semaphore for asynchronous operation management. ```swift import Foundation #if canImport(FoundationNetworking) import FoundationNetworking #endif var semaphore = DispatchSemaphore (value: 0) let parameters = "{\ \t\"currency\": \"USD\"\n}" let postData = parameters.data(using: .utf8) var request = URLRequest(url: URL(string: "https://api.livecoinwatch.com/overview")!,timeoutInterval: Double.infinity) request.addValue("application/json", forHTTPHeaderField: "content-type") request.addValue("", forHTTPHeaderField: "x-api-key") request.httpMethod = "POST" request.httpBody = postData let task = URLSession.shared.dataTask(with: request) { data, response, error in guard let data = data else { print(String(describing: error)) semaphore.signal() return } print(String(data: data, encoding: .utf8)!) semaphore.signal() } task.resume() semaphore.wait() ``` -------------------------------- ### Swift Example Source: https://livecoinwatch.github.io/lcw-api-docs This Swift example demonstrates making a POST request to the Live Coin Watch API using URLRequest and URLSession, without requiring any external packages. It includes instructions for API key integration. ```APIDOC ## Swift All the examples use URLRequest and URLSession. Examples work without installing any package! Just change the `` to your key, and that's it!. ```swift import Foundation #if canImport(FoundationNetworking) import FoundationNetworking #endif var semaphore = DispatchSemaphore (value: 0) var request = URLRequest(url: URL(string: "https://api.livecoinwatch.com")!,timeoutInterval: Double.infinity) request.addValue("application/json", forHTTPHeaderField: "content-type") request.httpMethod = "POST" let task = URLSession.shared.dataTask(with: request) { data, response, error in guard let data = data else { print(String(describing: error)) semaphore.signal() return } print(String(data: data, encoding: .utf8)!) semaphore.signal() } task.resume() semaphore.wait() ``` ``` -------------------------------- ### Get Coin Contract Info using Swift Source: https://livecoinwatch.github.io/lcw-api-docs This Swift example shows how to construct and execute a URL request to the API. It includes setting headers, the HTTP method, and the request body. Semaphore is used for synchronization. ```swift import Foundation #if canImport(FoundationNetworking) import FoundationNetworking #endif var semaphore = DispatchSemaphore (value: 0) let parameters = "{\n\t\"currency\": \"USD\",\n\t\"platform\": \"ETH\",\n\t\"address\": \"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\n\t\"meta\": true\n}" let postData = parameters.data(using: .utf8) var request = URLRequest(url: URL(string: "https://api.livecoinwatch.com/coins/contract")!,timeoutInterval: Double.infinity) request.addValue("application/json", forHTTPHeaderField: "content-type") request.addValue("", forHTTPHeaderField: "x-api-key") request.httpMethod = "POST" request.httpBody = postData let task = URLSession.shared.dataTask(with: request) { data, response, error in guard let data = data else { print(String(describing: error)) semaphore.signal() return } print(String(data: data, encoding: .utf8)!) semaphore.signal() } task.resume() semaphore.wait() ``` -------------------------------- ### Response Body Example for /platforms/all Source: https://livecoinwatch.github.io/lcw-api-docs This is an example of the JSON response body you can expect when successfully calling the `/platforms/all` endpoint. It lists supported platforms with their codes and names. ```json [ { "code": "BSC", "name": "BNB Chain" }, { "code": "ETH", "name": "Ethereum" }, ... ] ``` -------------------------------- ### Get Historical Market Data with Swift Source: https://livecoinwatch.github.io/lcw-api-docs This Swift code example shows how to make a POST request to fetch historical market data. Replace '' with your actual API key. ```swift import Foundation #if canImport(FoundationNetworking) import FoundationNetworking #endif var semaphore = DispatchSemaphore (value: 0) let parameters = "{\n\t\"currency\": \"USD\",\n\t\"start\": 1606232700000,\n\t\"end\": 1606233000000\n}\n" let postData = parameters.data(using: .utf8) var request = URLRequest(url: URL(string: "https://api.livecoinwatch.com/overview/history")!,timeoutInterval: Double.infinity) request.addValue("application/json", forHTTPHeaderField: "content-type") request.addValue("", forHTTPHeaderField: "x-api-key") request.httpMethod = "POST" request.httpBody = postData let task = URLSession.shared.dataTask(with: request) { data, response, error in guard let data = data else { print(String(describing: error)) semaphore.signal() return } print(String(data: data, encoding: .utf8)!) semaphore.signal() } task.resume() semaphore.wait() ``` -------------------------------- ### Make a POST request using C# RestSharp Source: https://livecoinwatch.github.io/lcw-api-docs All the examples are written using the RestSharp. Install the package and add it to your code. Everything is explained in their documentation. ```csharp var client = new RestClient("https://api.livecoinwatch.com"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("content-type", "application/json"); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` -------------------------------- ### Shell Example Source: https://livecoinwatch.github.io/lcw-api-docs This example demonstrates how to make a POST request to the Live Coin Watch API using cURL, suitable for exploring the API in most shells. ```APIDOC ## Shell For just exploring and playing around with the API, this might be the simplest option. All examples should run in most shells, as the only command used is the all-mighty cURL. ``` curl -X POST https://api.livecoinwatch.com \ -H 'content-type: application/json' ``` ``` -------------------------------- ### JavaScript Example Source: https://livecoinwatch.github.io/lcw-api-docs This example shows how to use the Fetch API in JavaScript to make a POST request to the Live Coin Watch API. It's designed for modern browsers and can be adapted for Node.js or Deno. ```APIDOC ## JavaScript All the examples are written for modern browers. Most examples should be easily portable to run in other JavaScript environments like Node.js or not even needing any changes from browser version with Deno. ```javascript await fetch(new Request('https://api.livecoinwatch.com'), { method: 'POST', headers: new Headers({ 'content-type': 'application/json' }) }) ``` ``` -------------------------------- ### Get Overview Data with Ruby Net::HTTP Source: https://livecoinwatch.github.io/lcw-api-docs Retrieve aggregated market data using Ruby's Net::HTTP library. This example shows how to construct and send an HTTP POST request. ```ruby require "uri" require "json" require "net/http" url = URI("https://api.livecoinwatch.com/overview") https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Post.new(url) request["content-type"] = "application/json" request["x-api-key"] = "" request.body = JSON.dump({ "currency": "USD" }) response = https.request(request) puts response.read_body ``` -------------------------------- ### Get List of Coins - JSON Response Example Source: https://livecoinwatch.github.io/lcw-api-docs This snippet shows an example of the JSON response structure for the `/coins/list` endpoint, detailing coin codes, current rates, trading volumes, market capitalization, and delta changes over various periods. ```json [ { "code": "BTC", "rate": 23456.789, "volume": 1234567890, "cap": 1102979514307, "delta": { "hour": 1.008, "day": 1.0808, "week": 1.2793, "month": 1.4754, "quarter": 0.4804, "year": 0.7455 } }, { "code": "ETH", "rate": 1933.6392223621567, "volume": 12686119704, "cap": 222928063223, "delta": { "hour": 1.0015, "day": 1.0386, "week": 1.0822, "month": 1.158, "quarter": 0.5436, "year": 0.7004 } } ] ``` -------------------------------- ### PHP Example Source: https://livecoinwatch.github.io/lcw-api-docs This PHP example demonstrates making a POST request to the Live Coin Watch API using built-in PHP stream functions, without external dependencies. It's compatible with PHP 5, 7, and 8. ```APIDOC ## PHP All PHP examples are written using pure PHP without using any dependencies. These examples should work on versions of PHP that support stream_context_create & stream_get_contents (Supported versions: PHP 5, PHP 7, PHP 8). ```php $context_options = array ( 'http' => array ( 'method' => 'POST', 'header' => "Content-type: application/json\r\n" ) ); $context = stream_context_create($context_options); $fp = fopen('https://api.livecoinwatch.com', 'r', false, $context); print_r(stream_get_contents($fp)); ``` ``` -------------------------------- ### Make a POST request using pure PHP Source: https://livecoinwatch.github.io/lcw-api-docs All PHP examples are written using pure PHP without using any dependencies. These examples should work on versions of PHP that support stream_context_create & stream_get_contents (Supported versions: PHP 5, PHP 7, PHP 8). ```php $context_options = array ( 'http' => array ( 'method' => 'POST', 'header' => "Content-type: application/json\r\n" ) ); $context = stream_context_create($context_options); $fp = fopen('https://api.livecoinwatch.com', 'r', false, $context); print_r(stream_get_contents($fp)); ``` -------------------------------- ### Get BTC Historical Data (Go HTTP Client) Source: https://livecoinwatch.github.io/lcw-api-docs Make a POST request to get historical Bitcoin data using Go's standard HTTP client. This example shows how to set headers and send the JSON payload. Replace '' with your key. ```go package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://api.livecoinwatch.com/coins/single/history" method := "POST" payload := strings.NewReader(`{ "currency": "USD", "code": "BTC", "start": 1617035100000, "end": 1617035400000, "meta": true }`) client := &http.Client { } req, err := http.NewRequest(method, url, payload) if err != nil { fmt.Println(err) return } req.Header.Add("content-type", "application/json") req.Header.Add("x-api-key", "") res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Get Overview Data with C# RestSharp Source: https://livecoinwatch.github.io/lcw-api-docs Fetch aggregated market data using the RestSharp library in C#. This example shows how to configure the request and execute it. ```csharp var client = new RestClient("https://api.livecoinwatch.com/overview"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("content-type", "application/json"); request.AddHeader("x-api-key", ""); var body = @"{{" + "\n" + @"\t""currency"" : ""USD""" + "\n" + @"}}"; request.AddParameter("application/json", body, ParameterType.RequestBody); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` -------------------------------- ### Make a POST request using JavaScript Fetch API Source: https://livecoinwatch.github.io/lcw-api-docs All the examples are written for modern browsers. Most examples should be easily portable to run in other JavaScript environments like Node.js or not even needing any changes from browser version with Deno. ```javascript await fetch(new Request('https://api.livecoinwatch.com'), { method: 'POST', headers: new Headers({ 'content-type': 'application/json' }) }) ``` -------------------------------- ### Get API Credits - Go Source: https://livecoinwatch.github.io/lcw-api-docs A Go program to fetch your API credits. Ensure `` is replaced with your actual key. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://api.livecoinwatch.com/credits" method := "POST" client := &http.Client { } req, err := http.NewRequest(method, url, nil) if err != nil { fmt.Println(err) return } req.Header.Add("content-type", "application/json") req.Header.Add("x-api-key", "") res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Get Coin Contract Info using C# (RestSharp) Source: https://livecoinwatch.github.io/lcw-api-docs This C# example uses the RestSharp library to interact with the API. It configures the request method, headers, and request body. The response content is then printed to the console. ```csharp var client = new RestClient("https://api.livecoinwatch.com/coins/contract"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("content-type", "application/json"); request.AddHeader("x-api-key", ""); var body = @"{{\"currency\": \"USD\",\n" + @" \"platform\": \"ETH\",\n" + @" \"address\": \"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\n" + @" \"meta\": true\n" + @"}}"; request.AddParameter("application/json", body, ParameterType.RequestBody); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` -------------------------------- ### Successful API Credits Response Example Source: https://livecoinwatch.github.io/lcw-api-docs This is an example of a successful response when querying your API credits. It shows the remaining daily credits and the daily limit. ```json { "dailyCreditsRemaining": 4321, "dailyCreditsLimit": 10000 } ``` -------------------------------- ### Get BTC Historical Data (Swift URLSession) Source: https://livecoinwatch.github.io/lcw-api-docs Fetch historical Bitcoin data using Swift's URLSession. This example sets up the request, headers, and body for the POST request. Ensure you replace '' with your actual key. ```swift import Foundation #if canImport(FoundationNetworking) import FoundationNetworking #endif var semaphore = DispatchSemaphore (value: 0) let parameters = "{\n\t\"currency\": \"USD\",\n\t\"code\": \"BTC\",\n\t\"start\": 1617035100000,\n\t\"end\": 1617035400000,\n \"meta\": true\n}" let postData = parameters.data(using: .utf8) var request = URLRequest(url: URL(string: "https://api.livecoinwatch.com/coins/single/history")!,timeoutInterval: Double.infinity) request.addValue("application/json", forHTTPHeaderField: "content-type") request.addValue("", forHTTPHeaderField: "x-api-key") request.httpMethod = "POST" request.httpBody = postData let task = URLSession.shared.dataTask(with: request) { data, response, error in guard let data = data else { print(String(describing: error)) semaphore.signal() return } print(String(data: data, encoding: .utf8)!) semaphore.signal() } task.resume() semaphore.wait() ``` -------------------------------- ### Get Overview Data with cURL Source: https://livecoinwatch.github.io/lcw-api-docs Use this cURL command to fetch aggregated market data. Replace `` with your actual API key. ```bash curl -X POST 'https://api.livecoinwatch.com/overview' \ -H 'content-type: application/json' \ -H 'x-api-key: ' \ -d '{"currency":"USD"}' ``` -------------------------------- ### Get Gemini Exchange Info with JavaScript (Fetch API) Source: https://livecoinwatch.github.io/lcw-api-docs Utilize the Fetch API in JavaScript to send a POST request to the /exchanges/single endpoint. This example shows how to set headers and stringify the JSON payload. Remember to substitute '' with your valid API key. ```javascript await fetch(new Request("https://api.livecoinwatch.com/exchanges/single"), { method: "POST", headers: new Headers({ "content-type": "application/json", "x-api-key": "", }), body: JSON.stringify({ currency: "ETH", code: "gemini", meta: true, }), }); ``` -------------------------------- ### Example Response for Single Coin Data Source: https://livecoinwatch.github.io/lcw-api-docs This is an example of the JSON response you might receive when querying for Ethereum (ETH) in USD. It includes metadata such as name, symbol, rank, and historical all-time high. ```json { "name": "Ethereum", "symbol": "Ξ", "rank": 2, "age": 2411, "color": "#282a2a", "png32": "https://lcw.nyc3.cdn.digitaloceanspaces.com/production/currencies/32/eth.png", "png64": "https://lcw.nyc3.cdn.digitaloceanspaces.com/production/currencies/64/eth.png", "webp32": "https://lcw.nyc3.cdn.digitaloceanspaces.com/production/currencies/32/eth.webp", "webp64": "https://lcw.nyc3.cdn.digitaloceanspaces.com/production/currencies/64/eth.webp", "exchanges": 153, "markets": 3717, "pairs": 1773, "allTimeHighUSD": 2036.3088032624153, "circulatingSupply": 115250583, "totalSupply": null } ``` -------------------------------- ### Get API Credits - Python Source: https://livecoinwatch.github.io/lcw-api-docs A Python script to check your API credits. Replace `` with your key before running. ```python import requests import json url = "https://api.livecoinwatch.com/credits" payload={} headers = { 'content-type': 'application/json', 'x-api-key': '' } response = requests.request("POST", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### Get Overview Data with Unirest (Java) Source: https://livecoinwatch.github.io/lcw-api-docs Fetch aggregated market data using the Unirest library in Java. Ensure Unirest is included in your project dependencies. ```java Unirest.setTimeouts(0, 0); HttpResponse response = Unirest.post("https://api.livecoinwatch.com/overview") .header("content-type", "application/json") .header("x-api-key", "") .body("{\n\t\"currency\": \"USD\"\n}") .asString(); ``` -------------------------------- ### Make a POST request using cURL Source: https://livecoinwatch.github.io/lcw-api-docs This is the simplest option for exploring and playing around with the API. All examples should run in most shells, as the only command used is the all-mighty cURL. ```shell curl -X POST https://api.livecoinwatch.com \ -H 'content-type: application/json' ``` -------------------------------- ### List All Platforms using Go Source: https://livecoinwatch.github.io/lcw-api-docs This Go program demonstrates how to fetch all coin platforms by making an HTTP POST request. It includes reading the response body and handling errors. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://api.livecoinwatch.com/platforms/all" method := "POST" client := &http.Client { } req, err := http.NewRequest(method, url, nil) if err != nil { fmt.Println(err) return } req.Header.Add("content-type", "application/json") req.Header.Add("x-api-key", "") res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Get API Credits - JavaScript (Fetch API) Source: https://livecoinwatch.github.io/lcw-api-docs This JavaScript snippet demonstrates how to fetch your API credits using the Fetch API. Ensure you replace ``. ```javascript await fetch(new Request('https://api.livecoinwatch.com/credits'), { method: 'POST', headers: new Headers({ 'content-type': 'application/json', 'x-api-key': '' }) }) ``` -------------------------------- ### List All Platforms using Ruby Net::HTTP Source: https://livecoinwatch.github.io/lcw-api-docs This Ruby example shows how to make a POST request to the `/platforms/all` endpoint using the built-in `Net::HTTP` library. It configures SSL and sets the necessary headers. ```ruby require "uri" require "json" require "net/http" url = URI("https://api.livecoinwatch.com/platforms/all") https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Post.new(url) request["content-type"] = "application/json" request["x-api-key"] = "" response = https.request(request) puts response.read_body ``` -------------------------------- ### List All Platforms using Unirest (Java/C#) Source: https://livecoinwatch.github.io/lcw-api-docs This example uses the Unirest library to send a POST request for all platforms. It sets the content type and API key headers. ```java Unirest.setTimeouts(0, 0); HttpResponse response = Unirest.post("https://api.livecoinwatch.com/platforms/all") .header("content-type", "application/json") .header("x-api-key", "") .asString(); ``` -------------------------------- ### Make POST Request in Go Source: https://livecoinwatch.github.io/lcw-api-docs This Go example shows how to send a POST request to the LiveCoinWatch API using the standard net/http package. Remember to replace `` with your API key. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://api.livecoinwatch.com" method := "POST" client := &http.Client { } req, err := http.NewRequest(method, url, nil) if err != nil { fmt.Println(err) return } req.Header.Add("content-type", "application/json") res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) ``` -------------------------------- ### Fetch Single Coin Data with Go Source: https://livecoinwatch.github.io/lcw-api-docs This Go program demonstrates how to make an HTTP POST request to the API using the standard net/http package. It shows how to set headers and send the JSON payload. ```go package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://api.livecoinwatch.com/coins/single" method := "POST" payload := strings.NewReader(`{ "currency": "USD", "code": "ETH", "meta": true }`) client := &http.Client { } req, err := http.NewRequest(method, url, payload) if err != nil { fmt.Println(err) return } req.Header.Add("content-type", "application/json") req.Header.Add("x-api-key", "") res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Get BTC Historical Data (JavaScript Fetch) Source: https://livecoinwatch.github.io/lcw-api-docs Fetch historical data for Bitcoin (BTC) using the JavaScript Fetch API. This example demonstrates how to set headers and send a JSON payload. Replace '' with your key. ```javascript await fetch(new Request("https://api.livecoinwatch.com/coins/single/history"), { method: "POST", headers: new Headers({ "content-type": "application/json", "x-api-key": "", }), body: JSON.stringify({ currency: "USD", code: "BTC", start: 1617035100000, end: 1617035400000, meta: true, }), }); ``` -------------------------------- ### Get BTC Historical Data (C# RestSharp) Source: https://livecoinwatch.github.io/lcw-api-docs Retrieve historical Bitcoin data using RestSharp in C#. This example demonstrates setting the request method, headers, and JSON body. Remember to replace '' with your actual API key. ```csharp var client = new RestClient("https://api.livecoinwatch.com/coins/single/history"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("content-type", "application/json"); request.AddHeader("x-api-key", ""); var body = @"{{\"currency\": \"USD\",\n" + @"\"code\": \"BTC\",\n" + @"\"start\": 1617035100000,\n" + @"\"end\": 1617035400000,\n" + @" \"meta\": true\n" + @"}}"; request.AddParameter("application/json", body, ParameterType.RequestBody); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` -------------------------------- ### List All Platforms using Swift Source: https://livecoinwatch.github.io/lcw-api-docs This Swift code shows how to make a POST request to the `/platforms/all` endpoint using `URLSession`. It handles the response and potential errors. ```swift import Foundation #if canImport(FoundationNetworking) import FoundationNetworking #endif var semaphore = DispatchSemaphore (value: 0) var request = URLRequest(url: URL(string: "https://api.livecoinwatch.com/platforms/all")!,timeoutInterval: Double.infinity) request.addValue("application/json", forHTTPHeaderField: "content-type") request.addValue("", forHTTPHeaderField: "x-api-key") request.httpMethod = "POST" let task = URLSession.shared.dataTask(with: request) { data, response, error in guard let data = data else { print(String(describing: error)) semaphore.signal() return } print(String(data: data, encoding: .utf8)!) semaphore.signal() } task.resume() semaphore.wait() ``` -------------------------------- ### Get Gemini Exchange Info with C# (RestSharp) Source: https://livecoinwatch.github.io/lcw-api-docs This C# example uses the RestSharp library to call the /exchanges/single API endpoint. It configures the request with POST method, JSON content type, and your API key. Replace '' with your actual API key. ```csharp var client = new RestClient("https://api.livecoinwatch.com/exchanges/single"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("content-type", "application/json"); request.AddHeader("x-api-key", ""); var body = @"{{" + "\n" + @ ``` -------------------------------- ### Get Coin Contract Info using Go Source: https://livecoinwatch.github.io/lcw-api-docs This Go program demonstrates making an HTTP POST request to the API. It sets the necessary headers and constructs the JSON payload. Error handling is included for request creation and response reading. ```go package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://api.livecoinwatch.com/coins/contract" method := "POST" payload := strings.NewReader(`{ "currency": "USD", "platform": "ETH", "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "meta": true }`) client := &http.Client { } req, err := http.NewRequest(method, url, payload) if err != nil { fmt.Println(err) return } req.Header.Add("content-type", "application/json") req.Header.Add("x-api-key", "") res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Get BTC Historical Data (PHP Stream Context) Source: https://livecoinwatch.github.io/lcw-api-docs Use PHP's stream context to make a POST request for historical Bitcoin data. This example demonstrates setting up the HTTP context with headers and the JSON payload. Replace '' with your key. ```php $data = json_encode(array('currency' => 'USD', 'code' => 'BTC', 'start' => 1617035100000, 'end' => 1617035400000, 'meta' => true)); $context_options = array ( 'http' => array ( 'method' => 'POST', 'header' => "Content-type: application/json\r\n" . "x-api-key: " . "\r\n", 'content' => $data ) ); $context = stream_context_create($context_options); $fp = fopen('https://api.livecoinwatch.com/coins/single/history', 'r', false, $context); print_r(stream_get_contents($fp)); ``` -------------------------------- ### List All Platforms using cURL Source: https://livecoinwatch.github.io/lcw-api-docs Use this cURL command to make a POST request to the `/platforms/all` endpoint. Ensure you replace `` with your actual API key. ```bash curl -X POST 'https://api.livecoinwatch.com/platforms/all' \ -H 'content-type: application/json' \ -H 'x-api-key: ' ``` -------------------------------- ### List All Platforms using C# RestSharp Source: https://livecoinwatch.github.io/lcw-api-docs This C# example utilizes the RestSharp library to perform a POST request to retrieve all coin platforms. It configures the request with appropriate headers. ```csharp var client = new RestClient("https://api.livecoinwatch.com/platforms/all"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("content-type", "application/json"); request.AddHeader("x-api-key", ""); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` -------------------------------- ### Get Overview Data with Python Requests Source: https://livecoinwatch.github.io/lcw-api-docs Use the Python requests library to get aggregated market data. This snippet demonstrates setting headers and sending JSON data. ```python import requests import json url = "https://api.livecoinwatch.com/overview" payload = json.dumps({ "currency": "USD" }) headers = { 'content-type': 'application/json', 'x-api-key': '' } response = requests.request("POST", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### Get Historical Market Data with Python Source: https://livecoinwatch.github.io/lcw-api-docs This Python script shows how to make a POST request to the API to get historical market data. Replace '' with your actual API key. ```python import requests import json url = "https://api.livecoinwatch.com/overview/history" payload = json.dumps({ "currency": "USD", "start": 1606232700000, "end": 1606233000000 }) headers = { 'content-type': 'application/json', 'x-api-key': '' } response = requests.request("POST", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### API Error Response Example Source: https://livecoinwatch.github.io/lcw-api-docs This JSON snippet shows an example of an API error response, specifically a 405 Method Not Allowed error, indicating an invalid HTTP method was used. ```json { "error": { "code": 405, "status": "Method Not Available.", "description": "You tried to access a resource with an invalid method." } } ``` -------------------------------- ### Get Historical Market Data with Go Source: https://livecoinwatch.github.io/lcw-api-docs This Go program demonstrates how to make an HTTP POST request to retrieve historical market data. Replace '' with your actual API key. ```go package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://api.livecoinwatch.com/overview/history" method := "POST" payload := strings.NewReader(`{ "currency": "USD", "start": 1606232700000, "end": 1606233000000 } `) client := &http.Client { } req, err := http.NewRequest(method, url, payload) if err != nil { fmt.Println(err) return } req.Header.Add("content-type", "application/json") req.Header.Add("x-api-key", "") res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Historical Market Data Response Example Source: https://livecoinwatch.github.io/lcw-api-docs This is an example of the JSON response structure you can expect when querying historical market data. It includes market cap, volume, liquidity, and Bitcoin dominance for the specified dates. ```json [ { "date": 1606232700000, "cap": 581093086830, "volume": 56386526334, "liquidity": 1288814828, "btcDominance": 0.614520121091147 }, { "date": 1606233000000, "cap": 582164608234, "volume": 56939433331, "liquidity": 1274915303, "btcDominance": 0.612858305207367 } ] ``` -------------------------------- ### Fetch Coin Map Data with Go Source: https://livecoinwatch.github.io/lcw-api-docs Send a POST request to the `/coins/map` endpoint using Go's standard `net/http` package. This example shows how to construct the request, set headers, and read the response body. ```go package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://api.livecoinwatch.com/coins/map" method := "POST" payload := strings.NewReader(`{ "codes": ["ETH","BTC","GRIN"], "currency": "USD", "sort": "rank", "order": "ascending", "offset": 0, "limit": 0, "meta": false }`) client := &http.Client { } req, err := http.NewRequest(method, url, payload) if err != nil { fmt.Println(err) return } req.Header.Add("content-type", "application/json") req.Header.Add("x-api-key", "") res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Fetch Coin List with Go Source: https://livecoinwatch.github.io/lcw-api-docs This Go program shows how to send a POST request to the /coins/list endpoint. It configures the request with the necessary headers and JSON payload. ```go package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://api.livecoinwatch.com/coins/list" method := "POST" payload := strings.NewReader(`{ "currency": "USD", "sort": "rank", "order": "ascending", "offset": 0, "limit": 2, "meta": false }`) client := &http.Client { } req, err := http.NewRequest(method, url, payload) if err != nil { fmt.Println(err) return } req.Header.Add("content-type", "application/json") req.Header.Add("x-api-key", "") res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) } ``` -------------------------------- ### List All Fiat Currencies (Go) Source: https://livecoinwatch.github.io/lcw-api-docs This Go program makes a POST request to fetch all fiat currencies. It includes necessary headers and handles the response. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://api.livecoinwatch.com/fiats/all" method := "POST" client := &http.Client { } req, err := http.NewRequest(method, url, nil) if err != nil { fmt.Println(err) return } req.Header.Add("content-type", "application/json") req.Header.Add("x-api-key", "") res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) } ``` -------------------------------- ### List All Platforms using JavaScript Fetch API Source: https://livecoinwatch.github.io/lcw-api-docs This JavaScript snippet demonstrates how to use the `fetch` API to get all coin platforms. It includes setting the necessary headers, including your API key. ```javascript await fetch(new Request("https://api.livecoinwatch.com/platforms/all"), { method: "POST", headers: new Headers({ "content-type": "application/json", "x-api-key": "", }), }); ``` -------------------------------- ### Get Coin List Source: https://livecoinwatch.github.io/lcw-api-docs Retrieves a list of coins with optional filtering, sorting, and metadata inclusion. ```APIDOC ## GET /coins ### Description Retrieves a list of coins with optional filtering, sorting, and metadata inclusion. ### Method GET ### Endpoint /coins ### Parameters #### Query Parameters - **codes** (array) - Optional - array any valid coin code strings - **currency** (string) - Optional - any valid coin or fiat code - **sort** (string) - Optional - sorting parameter, `rank`, `price`, `volume`, `code`, `name`, `age` - **order** (string) - Optional - sorting order, `ascending` or `descending` - **offset** (number) - Optional - offset of the list, default `0` - **limit** (number) - Optional - limit of the list, default `0`, maximum `100` - **meta** (boolean) - Optional - to include full coin information or not ### Response #### Success Response (200) - **name** (string) - coin's name - **symbol** (string) - coin's symbol - **rank** (rank) - coin's rank - **age** (number) - coin's age in days - **color** (string) - hexadecimal color code (`#282a2a`) - **png32** (string) - 32-pixel png image of coin icon - **png64** (string) - 64-pixel png image of coin icon - **webp32** (string) - 32-pixel webp image of coin icon - **webp64** (string) - 64-pixel webpg image of coin icon - **exchanges** (number) - number of exchange coin is present at - **markets** (number) - number of markets coin is present at - **pairs** (number) - number of unique markets coin is present at - **allTimeHighUSD** (number) - all-time high in USD - **circulatingSupply** (number) - number of coins minted, but not locked - **totalSupply** (number) - number of coins minted, including locked - **maxSupply** (number) - maximum number of coins that can be minted - **code** (string) - coin's code - **rate** (number) - coin rate in the specified currency - **volume** (number) - 24-hour volume of coin - **cap** (number) - market cap of coin - **categories** (array) - array of category strings - **delta.hour** (number) - rate of change in the last hour - **delta.day** (number) - rate of change in the last 24 hours - **delta.week** (number) - rate of change in the last 7 days - **delta.month** (number) - rate of change in the last 30 days - **delta.quarter** (number) - rate of change in the last 90 days - **delta.year** (number) - rate of change in the last 365 days ```