Skip to content

πŸ‘ΎπŸ“ˆ A versatile unofficial ts-lib & node-repl-cli to operate against the Kraken Crypto Exchange

License

Notifications You must be signed in to change notification settings

jambudipa/ts-kraken

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


ts-ts_kraken_logo



A versatile unofficial ts-lib & node-repl-cli to operate against the Kraken Crypto Exchange


About β€’ TLDR β€’ Installation β€’ Resources β€’ Upcoming




About

ts-kraken is a highly-typed Typescript Library to operate against the Kraken Crypto Exchange REST and WebSocket APIs

It also features an interactive node REPL-cli to operate via command-shell πŸ€“

ts_kraken_demo




TLDR; Get started

Launch the REPL directly on your terminal with npx:

Quickest way to test it out! πŸš€

npx ts-kraken

REPL commands

  • .help

  • .setkeys

  • .showkeys

  • .get PublicEndpoint params? jqFilter? -table?
.get Ticker pair=XBTUSD .XXBTZUSD|.c[0]|{BTC_PRICE:.}
.get AssetPairs . as $base|keys|map($base[.])|map({pair:.wsname,decimals:.pair_decimals,min:.ordermin}) -table

  • .post PrivateEndpoint params? jqFilter? -table?
.post OpenOrders .open as $open|.open|keys|map($open[.].descr) -table

  • .find pair orderMatchFilter? maxOffset=1000 jqFilter?
.find ADAETH descr[type]=buy 500 .descr.order
  • .pubsub PublicChannel params? jqFilter? -table?
.pubsub ticker pair[]=XBT/USD .[1].c[0]
.pubsub ticker pair[]=XBT/USD&pair[]=ETH/USD . as $base|{pair:.[3],price:$base[1].c[0]}

  • .privsub PrivateChannel params? jqFilter? -table?
.privsub openOrders .[0]|map(. as $order|keys[0]|$order[.])

  • .unsub ChannelName
.unsub ohlc

  • .unsuball



Installation

Setup in a standalone directory and have fun with the REPL:

Recommended if planning to use regularly

git clone https://github.com/yeikiu/ts-kraken && cd ts-kraken && npm i

You can create a .env file like the following under project's root directory to reuse the keys:

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

KRAKEN_API_KEY=yourApiKey
KRAKEN_API_SECRET=yourApiSecret
npm run kraken-repl



Setup as a library in your TypeScript/JS project:

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

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

ts_kraken_ide

Demo playground snippet

import { publicRESTRequest, privateRESTRequest, getOpenOrdersStream } from 'ts-kraken'

const apiKeys = {
    /* 
        Alternatively you can define your keys under a .env file
        or simply set them into process.env as KRAKEN_API_KEY and KRAKEN_API_SECRET
    */
    apiKey: 'yourApiKey',
    apiSecret: 'yourApiSecret'
}

const testTsKraken = async () => {

    const allTradingPairs = await publicRESTRequest({ url: 'AssetPairs' })
    console.log(`Total trading pairs: ${Object.keys(allTradingPairs).length}`)

    const ethTradingPairInfo = await publicRESTRequest({ url: 'AssetPairs', params: { pair: 'ETHEUR' }})
    console.log({ ethTradingPairInfo })

    // Fetch balance from a different account injecting keys in runtime
    const currentBalances = await privateRESTRequest({ url: 'Balance' }, apiKeys)
    console.log({ currentBalances })

    // Notice we are not passing an `apiKeys` param in the next private method, process.env ones will be used by default
    const { openOrders$ } = await getOpenOrdersStream()
    openOrders$.subscribe(openOrdersSnapshot => {
        // Output all open orders any time an order status updates
        console.log({ openOrdersSnapshot })
    })
}

testTsKraken()

Invoke the repl within node_modules

While working on your project, if it depends on ts-kraken you can invoke the repl in the shell directly with:

npx kraken-repl



Resources




Upcoming features

  • Option to record all requests and incoming streams to json files
  • Wrapper-REPL-Command prompting user for request params (with pre-flight validations) for each endpoint/subscription
  • Optional flag to save any repl-command output to a file



About

πŸ‘ΎπŸ“ˆ A versatile unofficial ts-lib & node-repl-cli to operate against the Kraken Crypto Exchange

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 88.0%
  • JavaScript 12.0%