npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@anypay/prices-client

v0.1.2

Published

Prices client for Anypay developers

Downloads

18

Readme

@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.