SDKs overview
Coinlayer offers a suite of SDKs and libraries designed to streamline the integration of its cryptocurrency market data API into various applications. These SDKs abstract the underlying HTTP requests and JSON parsing, allowing developers to focus on utilizing the data rather than managing API communication specifics. The primary goal of these libraries is to reduce development time and potential errors when accessing real-time and historical exchange rates for over 385 cryptocurrencies against 168 fiat currencies and other cryptocurrencies according to Coinlayer documentation.
Developers can choose from official SDKs maintained by Coinlayer, which provide consistent interfaces and support for core API functionalities. Additionally, the broader developer community may contribute unofficial libraries, offering alternative implementations or specialized features. When selecting an SDK, factors such as language compatibility, active maintenance, and community support are important considerations.
The Coinlayer API itself is a RESTful service, meaning it uses standard HTTP methods (like GET) to retrieve resources and returns data in JSON format. SDKs typically encapsulate this interaction, providing methods that map directly to API endpoints, such as fetching the latest rates or querying historical data for a specific date as defined by REST architectural principles.
Official SDKs by language
Coinlayer provides official SDKs and client libraries for several popular programming languages. These libraries are developed and maintained by the Coinlayer team to ensure full compatibility with the API and to provide a consistent developer experience. They typically handle API key authentication, request formatting, and response parsing.
The following table outlines the officially supported SDKs, their respective package identifiers, and common installation commands:
| Language | Package / Library | Installation Command | Maturity / Status |
|---|---|---|---|
| PHP | coinlayer/coinlayer-php |
composer require coinlayer/coinlayer-php |
Stable, actively maintained |
| Python | coinlayer-python |
pip install coinlayer-python |
Stable, actively maintained |
| Node.js | coinlayer-node |
npm install coinlayer-node |
Stable, actively maintained |
| jQuery | coinlayer-jquery |
Included via CDN or download | Stable, actively maintained |
| Go | github.com/coinlayer/go-sdk |
go get github.com/coinlayer/go-sdk |
Stable, actively maintained |
| Ruby | coinlayer-ruby |
gem install coinlayer-ruby |
Stable, actively maintained |
Each official SDK is designed to mirror the API's structure, offering methods that correspond to specific endpoints like live for current rates, historical for past rates, and convert for currency conversions. Comprehensive usage examples and API documentation for each SDK are available on the Coinlayer documentation portal.
Installation
Installing Coinlayer SDKs typically involves using the package manager specific to your programming language or environment. Below are general instructions for common languages. Before installation, ensure you have the necessary prerequisites, such as the correct version of Node.js, Python, or PHP, installed on your system.
PHP
For PHP projects, Composer is the recommended package manager. If you don't have Composer installed, you can follow the official Composer installation guide. Once Composer is set up, navigate to your project directory in the terminal and run:
composer require coinlayer/coinlayer-php
This command downloads the Coinlayer PHP SDK and its dependencies, adding them to your project's vendor/ directory and updating your composer.json and composer.lock files.
Python
Python developers typically use pip for package management. Ensure you have Python and pip installed. You can install the Coinlayer Python SDK by running:
pip install coinlayer-python
It's often recommended to install packages within a Python virtual environment to manage project-specific dependencies.
Node.js
For Node.js applications, npm (Node Package Manager) is the standard tool. After installing Node.js, you can add the Coinlayer Node.js SDK to your project:
npm install coinlayer-node
This command adds the package to your node_modules directory and updates your package.json file.
jQuery (Browser-based)
The jQuery library for Coinlayer is typically included directly in your HTML file via a script tag, often from a Content Delivery Network (CDN) or a local file. This approach is suitable for client-side web applications.
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="path/to/coinlayer-jquery.js"></script>
<!-- Or use a CDN for the Coinlayer jQuery library if available -->
Refer to the Coinlayer jQuery documentation for the most current CDN links or download instructions.
Go
Go modules are used for dependency management in Go projects. To install the Coinlayer Go SDK, navigate to your project's root directory and run:
go get github.com/coinlayer/go-sdk
Then, import it in your Go code:
import "github.com/coinlayer/go-sdk"
Ruby
For Ruby projects, Bundler and RubyGems are commonly used. Add the Coinlayer Ruby gem to your Gemfile:
gem 'coinlayer-ruby'
Then, run bundle install in your terminal to install the gem.
Quickstart example
This quickstart example demonstrates how to fetch the latest cryptocurrency exchange rates using the Coinlayer Node.js SDK. Before running this code, ensure you have installed the coinlayer-node package (npm install coinlayer-node) and have a valid Coinlayer API access key.
Replace YOUR_ACCESS_KEY with your actual Coinlayer API key, which you can obtain from your Coinlayer dashboard after signing up for an account.
const Coinlayer = require('coinlayer-node');
// Initialize the Coinlayer client with your API Access Key
const client = new Coinlayer({
accessKey: 'YOUR_ACCESS_KEY'
});
// Fetch real-time cryptocurrency exchange rates
client.live()
.then(response => {
if (response.success) {
console.log('Timestamp:', new Date(response.timestamp * 1000).toLocaleString());
console.log('Target Currency:', response.target);
console.log('Exchange Rates:');
for (const crypto in response.rates) {
console.log(` ${crypto}: ${response.rates[crypto]}`);
}
} else {
console.error('API Error:', response.error.info);
}
})
.catch(error => {
console.error('Request failed:', error.message);
});
// Example: Fetch historical rates for a specific date (e.g., 2023-01-01)
client.historical('2023-01-01')
.then(response => {
if (response.success) {
console.log('\nHistorical Rates for 2023-01-01:');
console.log('Timestamp:', new Date(response.timestamp * 1000).toLocaleString());
console.log('Target Currency:', response.target);
console.log('Exchange Rates:');
for (const crypto in response.rates) {
console.log(` ${crypto}: ${response.rates[crypto]}`);
}
} else {
console.error('Historical API Error:', response.error.info);
}
})
.catch(error => {
console.error('Historical Request failed:', error.message);
});
This example first retrieves the most current exchange rates and then demonstrates how to query historical data for a specific date. The live() method fetches real-time data, while historical('YYYY-MM-DD') retrieves rates from a given day. The API response includes a success boolean, a timestamp, the target currency (defaulting to USD), and a rates object containing key-value pairs of cryptocurrency symbols and their exchange rates.
Community libraries
While Coinlayer provides official SDKs, the broader developer community may also create and maintain unofficial libraries. These community-contributed tools can offer alternative language support, specialized features, or integrations with specific frameworks. Community libraries are often found on platforms like GitHub or package repositories (e.g., PyPI for Python, npm for Node.js).
When considering a community library, it is important to evaluate its:
- Active Maintenance: Check the last commit date, open issues, and pull requests to gauge if the library is actively supported.
- Documentation: Adequate documentation is crucial for understanding how to use the library effectively.
- Community Support: A vibrant community can provide assistance and contribute to ongoing improvements.
- Compatibility: Ensure the library is compatible with the latest version of the Coinlayer API and your chosen programming language.
- Security: For production environments, review the source code or ensure the library comes from a trusted source to avoid potential security vulnerabilities.
As of the last update, Coinlayer primarily highlights its official SDKs on its developer documentation. Developers interested in contributing or finding community-developed tools are encouraged to search public code repositories or developer forums for unlisted alternatives.
Using a community library can sometimes provide more flexibility or a more idiomatic approach for a specific language or framework than an official, more generic SDK. However, they may not receive the same level of direct support or guarantees of compatibility with future API changes as the official offerings.