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

cryptomarket

v3.2.1

Published

The CryptoMarket for Node.js

Downloads

83

Readme

CryptoMarket-javascript

main page

sign up in CryptoMarket.

Installation

To install Cryptomarket use npm

npm install [email protected]

Documentation

This sdk makes use of the api version 3 of cryptomarket.

Quick Start

rest client

const { Client } = require("cryptomarket");

// instance a client
const apiKey = "AB32B3201";
const apiSecret = "21b12401";
const client = new Client(apiKey, apiSecret);

// get currencies
const currencies = await client.getCurrencies();

// get order books
const orderBook = await client.getOrderBook("EOSETH");

// get your account balances
const accountBalances = await client.getWalletBalances();

// get your trading balances
const tradingBalances = await client.getSpotTradingBalances();

// move balance from wallet to spot trading
const result = await client.transferBetweenWalletAndExchange({
  currency: "EOS",
  amount: "3.2",
  source: Account.Wallet,
  destination: Account.Spot,
});

// get your active orders
const activeOrders = await client.getAllActiveSpotOrders("EOSETH");

// create a new order
const newOrder = await client.createOrder({
  symbol: "EOSETH",
  side: "buy",
  quantity: "10",
  price: "10",
});

websocket client

There are three websocket clients, the market data client, the spot trading client and the wallet client. The market data client requires no authentication, while the spot trading client and the wallet client do require it.

All websocket methods return promises. Subscriptions also take in a function of two parameters, the notification data, and the notification type. The notification type is of type NOTIFICATION_TYPE, and is either SNAPSHOT, NOTIFICATION or DATA.

The documentation of a specific subscriptions explains with of this types of notification uses.

MarketDataClient

Example of use of the market data client

// instantiate a market data client
const wsclient = new WSMarketDataClient();

// make a partial orderbook subscription

//    make subscription
await marketDataClient.subscribeToPartialOrderBook(
  callback:(notification, type) => {
    if (type === NOTIFICATION_TYPE.DATA) {
      System.out.println("this subscription only recieves data notifications");
    }
    for (const symbol in notification) {
      console.log(symbol);
      const orderbook = notification[symbol];
      console.log(orderbook);
    }
  },
  params: {
    speed: ORDER_BOOK_SPEED._100_MS,
    depth: DEPTH._5,
    symbols: ["EOSETH", "ETHBTC"],
  }
);

SpotTradingClient

Example of use of the spot trading client

const apiKey = "AB32B3201";
const apiSecret= "21b12401";

// instantiate a spot trading websocket client with a window of 10 seconds
const wsclient = new WSTradingClient(apiKey, apiSecret, 10_000);

// connect the client (and authenticate it automatically)
await wsclient.connect();

// get all the spot trading balances
const balanceList = await tradingClient.getSpotTradingBalances()
console.log(balanceList);


let clientOrderID = Math.floor(Date.now() / 1000).toString();
// make a spot order
const report = await tradingClient.createSpotOrder({
  clientOrderId: clientOrderID,
  symbol: "EOSETH",
  side: "sell",
  quantity: "0.01",
  price: "1000",
}
console.log(report);

WalletClient

Example of use of the wallet client

// instantiate a wallet websocket client with a default window of 10 seconds
const wsclient = new WSWalletClient(keys.apiKey, keys.apiSecret);

// get a list of transactions
const transactionList = await walletClient.getTransactions({
  currencies: ["EOS"],
  limit: 3,
});
console.log(transactionList);

// subscribe to a feed of transactions
await walletClient.subscribeToTransactions((notification, type) => {
  if (type === NOTIFICATION_TYPE.UPDATE) {
    console.log("this subscription only recieves update notifications");
  }
  console.log(notification);
});

error handling


{ CryptomarketSDKException, Client, WSMarketDataClient } = require('cryptomarket')
// exceptions derive from the CryptomarketSDKException class.

const client = new Client()
// catch a failed transaction
try {
    const order = await client.createOrder({
        'symbol':'EOSETHH',  // non existant symbol
        'side':'sell',
        'quantity':'10',
        'price':'10'})
} catch (error) {
    console.log(error)
}

const wsclient = new WSMarketDataClient()
await wsclient.connect();

// catch missing arguments
try {
    await wsclient.subscribeToMiniTickers()
} catch (error) {
    console.log(error)
}

Constants

All constants used for calls are in the constants module.

Checkout our other SDKs

python sdk

java sdk

go sdk

ruby sdk