https://github.com/yeikiu/ts-kraken
πΎπ A strongly typed library to operate with the Kraken Crypto Exchange | https://www.npmjs.com/package/ts-kraken
https://github.com/yeikiu/ts-kraken
api cli crypto cryptocurrencies js kraken library repl rxjs trading-api tradingbot ts typescript websocket
Last synced: 8 months ago
JSON representation
πΎπ A strongly typed library to operate with the Kraken Crypto Exchange | https://www.npmjs.com/package/ts-kraken
- Host: GitHub
- URL: https://github.com/yeikiu/ts-kraken
- Owner: yeikiu
- License: cc0-1.0
- Created: 2021-03-13T06:29:34.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2025-07-23T01:04:18.000Z (10 months ago)
- Last Synced: 2025-07-23T01:08:14.388Z (10 months ago)
- Topics: api, cli, crypto, cryptocurrencies, js, kraken, library, repl, rxjs, trading-api, tradingbot, ts, typescript, websocket
- Language: TypeScript
- Homepage: https://yeikiu.github.io/ts-kraken/
- Size: 116 MB
- Stars: 16
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
A strongly typed library to operate with the Kraken Crypto Exchange
Quick-Start β’
About β’
Usage β’
Documentation β’
Acknowledgments
## π Quick-Start
(click to extend π)
- 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](https://yeikiu.github.io/ts-kraken).
```ts
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
(click to extend π)
> **ts-kraken** is a **strongly-typed** _Typescript Library_ that will help you
> operating via code or shell with
> [the Kraken Crypto Exchange](https://kraken.com)
- Easily operate with Kraken
[REST](https://docs.kraken.com/api/docs/category/rest-api/market-data) and
[WebSocketV2](https://docs.kraken.com/websockets/) APIs
- Use
[`ts-kraken` helper methods](https://yeikiu.github.io/ts-kraken/functions/getClosedOrders.html)
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](https://jqlang.github.io/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
(click to extend π)
#### Use the library in your TypeScript/JS project:
(click to extend π)
- `cd dependant/project/path && npm i ts-kraken`

> Get _IDE code-suggestions_ for any REST or WS request you need

#### Use the REPL-cli
(click to extend π)
> 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 repl` or `npx kraken-repl`
> Open a PR with any addition/change proposal you have!

##### REPL commands
(click to extend π)
> 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 ! ? ? <-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 ! ? ? <-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 ! ? ? <-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 ! ? ? <-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
- [ts-kraken Documentation](https://yeikiu.github.io/ts-kraken)
- [Kraken REST API docs](https://docs.kraken.com/api/docs/rest-api/add-order)
- [Kraken WebSocketsV2 API docs](https://docs.kraken.com/api/docs/websocket-v2/add_order)
- [jq Manual](https://stedolan.github.io/jq/manual)
- [jq Playground](https://jqkungfu.com/)
## π Acknowledgments
- [@trasherdk](https://github.com/trasherdk) | Contributor