Socket
Book a DemoInstallSign in
Socket

@anypay/prices-client

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@anypay/prices-client

Prices client for Anypay developers

latest
npmnpm
Version
0.1.2
Version published
Maintainers
2
Created
Source

@anypay/prices-client

Overview

@anypay/prices-client is a TypeScript library for connecting to and interacting with the Anypay Prices API. This client library provides easy access to real-time financial market price updates and conversion rates. It's built for both browser and Node.js environments, making it versatile for various applications, including web apps, server-side applications, and more.

Features

  • Real-time price updates via WebSocket.
  • Fetch current prices and conversion rates through HTTP API.
  • Automatic reconnection to WebSocket in case of disconnection.
  • Typed interfaces for easy integration and development within TypeScript projects.

Installation

Install @anypay/prices-client using npm:

npm install @anypay/prices-client

Or using yarn:

yarn add @anypay/prices-client

Usage

Creating a Client

First, import and create a client instance. You can optionally pass in configuration options.

import { createClient } from '@anypay/prices-client';

const client = createClient({
  http_api_url: 'https://prices.anypayx.com', // Optional custom API URL
  websocket_api_url: 'wss://prices.anypayx.com', // Optional custom WebSocket URL
  token: 'your_api_token_here', // Optional API token for authenticated requests
});

Subscribing to Price Updates

To listen for real-time updates on prices:

client.subscribeToPricesUpdates();

client.on('price/updated', (price) => {
  console.log('Price updated', price);
});

client.on('websocket.error', (err) => {
  console.error('WebSocket error', err);
});

client.on('websocket.open', () => {
  console.log('WebSocket open');
});

client.on('websocket.message', (data) => {
  console.log(data);
});

Unsubscribing from Price Updates

To stop receiving price updates:

client.unsubscribeFromPricesUpdates();

Fetching Prices and Conversions

Fetch current prices:

async function fetchPrices() {
  const prices = await client.listPrices();
  console.log(prices);
}
fetchPrices();

Convert one currency to another:

async function convertCurrency() {
  const conversion = await client.convertPrice({
    base: 'USD',
    value: 1000,
    quote: 'BTC'
  });
  console.log(conversion);
}
convertCurrency();

Development

This library is open for contributions! Clone the repository, install dependencies, and make sure to follow the coding standards and commit message guidelines.

Testing

Run the test suite to ensure your changes do not break existing functionality:

npm run test

License

This project is licensed under the ISC License. See the LICENSE file for details.

This README provides a comprehensive guide to using the @anypay/prices-client library, from installation to making API calls for price updates and conversions. Adjust the content as needed to match the specifics of your project and its development workflow.

FAQs

Package last updated on 15 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts