SDKs overview

1Forge offers a RESTful API for accessing real-time and historical foreign exchange rate data. To streamline integration, 1Forge provides official Software Development Kits (SDKs) for popular programming languages. These SDKs are designed to abstract the complexities of HTTP requests, authentication, and response parsing, allowing developers to focus on application logic rather than low-level API interactions. The availability of SDKs can reduce development time and potential integration errors, as they handle common tasks like endpoint construction and data deserialization.

The 1Forge API primarily delivers JSON responses, a standard format for web APIs due to its human-readability and ease of parsing across various programming environments. For example, a request for current currency rates might return a JSON object containing currency pairs and their corresponding bid/ask prices, along with timestamps. Understanding the structure of JSON data is foundational when working with the 1Forge API, whether directly or through an SDK. Developers can refer to the Mozilla Developer Network JSON reference for detailed information on JSON syntax and usage.

Official SDKs by language

1Forge maintains official SDKs for several programming languages, designed to facilitate interaction with its real-time and historical forex data API. These libraries encapsulate the HTTP request logic, API key management, and response parsing, offering a higher-level interface than direct API calls. The official SDKs ensure compatibility with the latest API versions and features, providing a stable integration path for developers. Each SDK generally mirrors the API's available endpoints, such as retrieving current rates, historical data, or converting currencies, as detailed in the 1Forge API documentation.

The table below outlines the official SDKs, their respective package managers, and typical installation commands for quick setup.

Language Package Manager / System Installation Command Maturity
JavaScript npm npm install 1forge-api Stable
PHP Composer composer require 1forge/1forge-api Stable
Python pip pip install 1forge-api Stable

These SDKs are actively maintained by 1Forge, ensuring they remain compatible with updates to the API and provide a consistent developer experience across different language ecosystems. Developers are encouraged to consult the 1Forge API reference for the most up-to-date SDK usage guidelines and examples specific to each language.

Installation

Installing the 1Forge SDKs typically involves using the standard package manager for each respective language. This process ensures that all necessary dependencies are resolved and the library is properly integrated into your development environment. Below are detailed installation instructions for JavaScript, PHP, and Python.

JavaScript (Node.js)

For JavaScript projects, especially those using Node.js, the 1Forge API client can be installed via npm (Node Package Manager). Navigate to your project directory in the terminal and execute the installation command:

npm install 1forge-api

This command adds the 1forge-api package to your node_modules directory and updates your package.json file, making it available for import in your JavaScript files.

PHP

PHP projects commonly use Composer for dependency management. To install the 1Forge PHP SDK, ensure Composer is set up in your environment, then run the following command in your project's root directory:

composer require 1forge/1forge-api

Composer will download the package and its dependencies, creating a vendor directory and an autoloader file. You will need to include Composer's autoloader in your PHP scripts to use the SDK classes.

Python

Python developers can install the 1Forge SDK using pip, the Python package installer. Open your terminal or command prompt and execute:

pip install 1forge-api

This command fetches the package from the Python Package Index (PyPI) and installs it into your Python environment, making the oneforge module available for import in your Python scripts. It is often recommended to install Python packages within a Python virtual environment to manage project-specific dependencies.

Quickstart example

To demonstrate the basic usage of the 1Forge SDKs, here are quickstart examples for fetching current exchange rates using JavaScript, PHP, and Python. These examples assume you have already installed the respective SDK and have a valid API key from your 1Forge account dashboard.

JavaScript Example

This JavaScript example uses the 1forge-api package to get the current rates for several currency pairs.

const OneForge = require('1forge-api');

const API_KEY = 'YOUR_API_KEY'; // Replace with your actual API key
const oneforge = new OneForge(API_KEY);

oneforge.getQuotes(['USDJPY', 'EURUSD', 'GBPUSD'])
  .then(quotes => {
    console.log('Current Quotes:');
    quotes.forEach(quote => {
      console.log(`  ${quote.symbol}: Bid ${quote.bid}, Ask ${quote.ask}`);
    });
  })
  .catch(error => {
    console.error('Error fetching quotes:', error.message);
  });

PHP Example

The PHP example illustrates how to retrieve currency quotes using the Composer-installed 1forge/1forge-api library.

<?php

require_once __DIR__ . '/vendor/autoload.php';

use OneForge\OneForgeAPI;

$apiKey = 'YOUR_API_KEY'; // Replace with your actual API key
$oneforge = new OneForgeAPI($apiKey);

try {
    $quotes = $oneforge->getQuotes(['USDJPY', 'EURUSD', 'GBPUSD']);
    echo "Current Quotes:\n";
    foreach ($quotes as $quote) {
        echo "  {$quote['symbol']}: Bid {$quote['bid']}, Ask {$quote['ask']}\n";
    }
} catch (Exception $e) {
    echo 'Error fetching quotes: ' . $e->getMessage() . "\n";
}

?>

Python Example

This Python quickstart demonstrates fetching live currency rates using the oneforge-api module.

from oneforge import OneForgeAPI
import os

# It's recommended to store API keys as environment variables
api_key = os.getenv('ONEFORGE_API_KEY', 'YOUR_API_KEY') # Replace with your actual API key or environment variable
oneforge = OneForgeAPI(api_key)

try:
    quotes = oneforge.get_quotes(['USDJPY', 'EURUSD', 'GBPUSD'])
    print("Current Quotes:")
    for quote in quotes:
        print(f"  {quote['symbol']}: Bid {quote['bid']}, Ask {quote['ask']}")
except Exception as e:
    print(f"Error fetching quotes: {e}")

These examples provide a starting point for integrating 1Forge data into your applications. Remember to replace 'YOUR_API_KEY' with your actual 1Forge API key to authenticate your requests. Additional API methods for historical data, conversions, and more are available within each SDK, aligning with the comprehensive 1Forge API documentation.

Community libraries

While 1Forge provides official SDKs, the broader developer community may also contribute third-party libraries or wrappers for languages not officially supported or for specific use cases. These community-driven projects can offer alternative integration paths and might sometimes include features or abstractions tailored to particular frameworks or development styles. However, it is crucial to exercise caution when using community-contributed libraries. Unlike official SDKs, they may not be actively maintained by 1Forge, potentially leading to outdated functionality, compatibility issues with newer API versions, or security vulnerabilities.

Developers considering community libraries should apply due diligence, which includes:

  • Checking project activity: Look for recent commits, issue resolutions, and releases to gauge ongoing maintenance.
  • Reviewing documentation and examples: Ensure the library is well-documented and provides clear usage instructions.
  • Assessing community support: Active GitHub repositories with open discussions or forums can indicate a healthy project.
  • Verifying source code: Inspect the code for potential security flaws, inefficient API usage, or adherence to best practices.

As of late 2024, the primary recommended integration method remains through the official 1Forge SDKs for JavaScript, PHP, and Python, which are directly supported and maintained by 1Forge. For languages not covered by official SDKs, direct HTTP requests to the 1Forge REST API are a reliable alternative, allowing developers to implement custom client logic while having full control over the interaction. This approach aligns with standard API integration practices, as detailed in general REST API design principles. Developers can also consult resources like the IETF RFC 7231 for HTTP/1.1 Semantics and Content to build robust custom API clients.