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

ts-kraken

v4.0.4

Published

A strongly typed library to operate with the Kraken Crypto Exchange

Downloads

238

Readme

🚀 Quick-Start

  • Add the dependency to your js/ts project: npm i ts-kraken

  • Optionally add KRAKEN_API_KEY and KRAKEN_API_SECRET to your .env (only if you intend to use private methods, i.e. add orders or fetch balances)

  • Test the repl-cli with npx ts-kraken or find code-snippets examples for the methods you want to import in the documentation.

import {
  getClosedOrders,
  getWsAuthToken,
  privateWsSubscription,
  publicWsSubscription
} from 'ts-kraken'

getWsAuthToken()
  .then(async token => {
    console.log({ token })

    /* Fetch latest 50 closed orders and logs them */
    getClosedOrders().then(lastClosedOrdersArr => {
      const closedOrders = lastClosedOrdersArr.map(
        ({ orderid, descr: { order } }) => ({ orderid, order })
      )

      console.table(closedOrders)
    })

    /* Print any updates in the private `balances` channel */
    const balances$ = await privateWsSubscription(
      {
        channel: 'balances',
        params: { snapshot: true }
      },
      token
    ) // Pass token here to save time as the library won't need to fetch one internally!

    balances$.subscribe(({ data }) => {
      console.table(data)
    })

    /* Track 5m candles updates */
    const fiveMinsBtcUsdCandles$ = publicWsSubscription({
      channel: 'ohlc',
      params: { symbol: ['BTC/USD'], interval: 5, snapshot: false }
    })

    fiveMinsBtcUsdCandles$.subscribe(
      ({ data: [{ open, high, low, close }] }) => {
        console.log({ open, high, low, close })
      }
    )
  })
  .catch(error => {
    console.log({ error })
  })

ℹ️ About this project

ts-kraken is a strongly-typed Typescript Library that will help you operating via code or shell with the Kraken Crypto Exchange

  • Easily operate with Kraken REST and WebSocketV2 APIs

  • Use ts-kraken helper methods to build your own trading bots

  • Subscribe to custom streams of data combining the RxJS Observables returned by the WebsocketV2 methods

  • Get advantage of modern IDEs Typescript integrations (code autocompletion, suggested imports, etc.)

It also features an interactive node REPL-cli to operate via command-shell or leave a socket open printing all updates to the terminal with a nice jq format 🤓

  • Kraken UI down durig high traffic or maintenance? You can still use the APIs!

  • Use any of the available REST methods directly from your terminal

  • Print nicely formatted data updates coming directly from WebsocketV2 subscriptions

🛠️ Usage

Use the library in your TypeScript/JS project:

  • cd dependant/project/path && npm i ts-kraken

Get IDE code-suggestions for any REST or WS request you need

Use the REPL-cli

You can create a .env file that the repl-cli will try to read from cwd (current working directory):

  • touch .env

Use the following format:

# .env's file content holding your API key/secret

KRAKEN_API_KEY=yourApiKey
KRAKEN_API_SECRET=yourApiSecret

Launch the REPL directly on your terminal with npx:

Quickest way to test it! 🚀 (will automatically download the library as a global npm package if you don't run npm i ts-kraken first)

  • npx ts-kraken

Set it up in a standalone directory:

Recommended if planning to use regularly and/or modify core functionality

  • git clone https://github.com/yeikiu/ts-kraken

  • cd ts-kraken

  • npm i

  • npm run kraken-repl

Open a PR with any addition/change proposal you have!

ts_kraken_demo

REPL commands

The following list includes only a subset sample of all possible commands you could generate for the .get and .post methods:

.exit       👉 Exit the REPL

-----------------------------------------------------------------------------------------------------------------------------------------------------

.help       👉 Print this help message

-----------------------------------------------------------------------------------------------------------------------------------------------------

.get        👉 Fetch PUBLIC REST data.

            Usage   >> .get <PublicEndpoint>! <paramA=valueA&param_list[]=value1&param_list[]=value2>? <jqFilter>? <-table>?

            i.e.    >> .get Time .rfc1123
                    >> .get AssetPairs . as $base|keys|map($base[.])|map({wsname,tick_size,pair_decimals,ordermin}) -table
                    >> .get AssetPairs pair=BTC/EUR . as $base|keys[0]|$base[.]|{wsname,tick_size,pair_decimals,ordermin}

-----------------------------------------------------------------------------------------------------------------------------------------------------

.post       👉 Fetch PRIVATE REST data.

            Usage   >> .post <PrivateEndpoint>! <paramA=valueA&param_list[]=value1&param_list[]=value2>? <jqFilter>? <-table>?

            i.e.    >> .post OpenOrders .open as $open|.open|keys|map($open[.].descr.order)
                    >> .post OpenOrders .open as $open|.open|keys|map($open[.].descr) -table
                    >> .post AddOrder ordertype=market&type=sell&volume=0.002&pair=ETHEUR
                    >> .post CancelAll

-----------------------------------------------------------------------------------------------------------------------------------------------------

.privsub    👉 Subscribe to PRIVATE WS stream.

            Usage   >> .privsub <subscriptionName>! <paramA=valueA&param_list[]=value1&param_list[]=value2>? <jqFilter>? <-table>?

            i.e.    >> .privsub balances snap_orders=true .data|map({ asset, balance }) -table
                    >> .privsub executions snap_orders=true .data|map({order_id,side,order_qty,symbol,order_type,limit_price}) -table

.pubsub     👉 Subscribe to PUBLIC WS stream.

            Usage   >> .pubsub <subscriptionName>! <paramA=valueA&param_list[]=value1&param_list[]=value2>? <jqFilter>? <-table>?

            i.e.    >> .pubsub ticker symbol[]=BTC/EUR .data[0].last
                    >> .pubsub ticker symbol[]=BTC/EUR&symbol[]=ADA/BTC&symbol[]=USDT/USD .data[0]|{symbol,last} -table

-----------------------------------------------------------------------------------------------------------------------------------------------------

.setkeys    👉 Load API key/secret (non-persistent, use a .env file to reuse persistent keys)

.showkeys   👉 Display current API key/secret in use

-----------------------------------------------------------------------------------------------------------------------------------------------------

.unsub      👉 Closes WebSocket stream for GIVEN subscriptionName.

            i.e.    >> .unsub ticker
                    >> .unsub executions

.unsuball   👉 Closes WebSocket stream for ALL subscriptions.

            i.e.    >> .unsuball

🔖 Documentation

🙏 Acknowledgments